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-point-deduction-post-creation-score
type
post
updatedAt
Dec 6, 2025 05:43 AM

✅ 구조

이 서비스는 게시글을 작성하려면 포인트가 필요한 서비스이다. 그래서 포인트 차감을 한 뒤에 게시글이 작성돼야 하고, 게시글 작성이 완료되면 사용자의 활동 점수가 적립되는 서비스이다. 아래 그림과 같이 작동하도록 코드를 작성해보자.
notion image
 
 

✅ 코드 작성하기

board-service에서 아래 코드 작성하기
  1. 포인트 차감 API 호출 코드 작성하기
    1. application.yml
      server: port: 8081 spring: datasource: url: jdbc:mysql://localhost:3307/board-db username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true client: user-service: url: http://localhost:8080 point-service: url: http://localhost:8082
       
      dto/DeductPointsRequestDto
      public class DeductPointsRequestDto { private Long userId; private int amount; public DeductPointsRequestDto(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 deductPoints(Long userId, int amount) { DeductPointsRequestDto deductPointsRequestDto = new DeductPointsRequestDto(userId, amount); this.restClient.post() .uri("/points/deduct") .contentType(MediaType.APPLICATION_JSON) .body(deductPointsRequestDto) .retrieve() .toBodilessEntity(); } }
       
  1. 활동 점수 적립 API 호출 코드 작성하기
    1. dto/AddActivityScoreRequestDto
      public class AddActivityScoreRequestDto { private Long userId; private int score; public AddActivityScoreRequestDto(Long userId, int score) { this.userId = userId; this.score = score; } public Long getUserId() { return userId; } public int getScore() { return score; } }
       
      client/UserCleint
      @Component public class UserClient { ... public void addActivityScore(Long userId, int score) { AddActivityScoreRequestDto addActivityScoreRequestDto = new AddActivityScoreRequestDto(userId, score); this.restClient.post() .uri("/users/activity-score/add") .contentType(MediaType.APPLICATION_JSON) .body(addActivityScoreRequestDto) .retrieve() .toBodilessEntity(); } }
       
  1. Service 코드 작성하기
    1. 게시글 작성 로직에 포인트 적립 로직을 추가해야 한다.
      service/BoardService
      @Service public class BoardService { private final BoardRepository boardRepository; private final UserClient userClient; private final PointClient pointClient; public BoardService(BoardRepository boardRepository, UserClient userClient, PointClient pointClient) { this.boardRepository = boardRepository; this.userClient = userClient; this.pointClient = pointClient; } @Transactional public void create(CreateBoardRequestDto createBoardRequestDto) { // 게시글 작성 전 100 포인트 차감 pointClient.deductPoints(createBoardRequestDto.getUserId(), 100); // 게시글 작성 Board board = new Board( createBoardRequestDto.getTitle(), createBoardRequestDto.getContent(), createBoardRequestDto.getUserId() ); this.boardRepository.save(board); // 게시글 작성 시 작성자에게 활동 점수 10점 부여 userClient.addActivityScore(createBoardRequestDto.getUserId(), 10); } ... }
       
  1. 서버 다시 실행시키기
    1.  
  1. 기존 DB 데이터 체크
    1. notion image
      notion image
      notion image
       
  1. 서버 실행시켜서 API 테스트해보기
    1. notion image
      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 입문/실전 강의의 수업 자료 중 일부입니다.