JSCODE Logo
프로그래밍 과외블로그후기멘토진
회사명 : JSCODE대표 : 박재성사업자 등록번호 : 244-22-01557통신판매업 : 제 2023-인천미추홀-0381 호
학원 명칭 : 제이에스코드(JSCODE)원격학원학원설립ㆍ운영 등록번호 : 제6063호

서울특별시 구로구 경인로 20가길 11(오류동, 아델리아)

Copyright ⓒ 2025 JSCODE - 최상위 현업 개발자들의 프로그래밍 교육 All rights reserved.

이용약관개인정보처리방침
← 블로그 목록으로 돌아가기

[실습] 회원 가입하면 포인트가 적립되도록 만들기

JSCODE 박재성
JSCODE 박재성
2025-12-06
author
JSCODE 박재성
category
MSA
createdAt
Dec 6, 2025
series
비전공자도 이해할 수 있는 MSA 입문/실전
slug
practice-earn-points-on-signup
type
post
updatedAt
Dec 6, 2025 05:43 AM

✅ 구조

아래 그림과 같이 회원 가입을 하면 포인트가 적립되도록 코드를 작성해보자.
notion image
 
 

✅ 코드 작성하기

user-service에서 아래 코드 작성하기
  1. PointClient 코드 작성하기
    1. 포인트 서비스에 API 요청을 보내는 코드를 작성하자.
      application.yml
      server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/user-db username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true client: point-service: url: http://localhost:8082
       
      dto/AddPointsRequestDto
      public class AddPointsRequestDto { private Long userId; private int amount; public AddPointsRequestDto(Long userId, int amount) { this.userId = userId; this.amount = amount; } public Long getUserId() { return userId; } public int getAmount() { return amount; } }
       
      client/PointClient
      @Component public class PointClient { private final RestClient restClient; public PointClient( @Value("${client.point-service.url}") String pointServiceUrl ) { this.restClient = RestClient.builder() .baseUrl(pointServiceUrl) .build(); } public void addPoints(Long userId, int amount) { AddPointsRequestDto addPointsRequestDto = new AddPointsRequestDto(userId, amount); this.restClient.post() .uri("/points/add") .contentType(MediaType.APPLICATION_JSON) .body(addPointsRequestDto) .retrieve() .toBodilessEntity(); } }
       
  1. Service 코드 작성하기
    1. 회원 가입 로직에 포인트 적립 로직을 추가해야 한다.
      service/UserService
      @Service public class UserService { private final UserRepository boardRepository; private final PointClient pointClient; public UserService(UserRepository userRepository, PointClient pointClient) { this.userRepository = userRepository; this.pointClient = pointClient; } public void signUp(SignUpRequestDto signUpRequestDto) { User user = new User( signUpRequestDto.getEmail(), signUpRequestDto.getName(), signUpRequestDto.getPassword() ); User savedUser = this.userRepository.save(user); // 회원가입하면 포인트 1000점 적립 pointClient.addPoints(savedUser.getUserId(), 1000); } ... }
       
  1. 서버 다시 실행시키기
    1.  
  1. 서버 실행시켜서 API 테스트해보기
    1. notion image
      notion image
      notion image
 
author
JSCODE 박재성
category
MSA
createdAt
Dec 6, 2025
series
비전공자도 이해할 수 있는 MSA 입문/실전
slug
type
series-footer
updatedAt
Dec 6, 2025 05:45 AM
📎
이 글은 비전공자도 이해할 수 있는 MSA 입문/실전 강의의 수업 자료 중 일부입니다.