From b5d8adbda2e70940bee690d51cb2e6da1c952cf5 Mon Sep 17 00:00:00 2001 From: thguss Date: Thu, 29 Aug 2024 20:24:59 +0900 Subject: [PATCH 1/2] [ADD] added cotton count gt zero check logic --- .../java/com/soptie/server/domain/member/MemberCotton.java | 7 +++++++ .../com/soptie/server/domain/member/MemberService.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/soptie/server/domain/member/MemberCotton.java b/src/main/java/com/soptie/server/domain/member/MemberCotton.java index 1c8a415e..b136e79c 100644 --- a/src/main/java/com/soptie/server/domain/member/MemberCotton.java +++ b/src/main/java/com/soptie/server/domain/member/MemberCotton.java @@ -23,4 +23,11 @@ public void subtractCotton(CottonType type) { case HAPPINESS -> rainbowCottonCount--; } } + + public int getCottonCount(CottonType type) { + return switch (type) { + case DAILY -> basicCottonCount; + case HAPPINESS -> rainbowCottonCount; + }; + } } diff --git a/src/main/java/com/soptie/server/domain/member/MemberService.java b/src/main/java/com/soptie/server/domain/member/MemberService.java index c40db71b..f10e44c8 100644 --- a/src/main/java/com/soptie/server/domain/member/MemberService.java +++ b/src/main/java/com/soptie/server/domain/member/MemberService.java @@ -8,6 +8,8 @@ import com.soptie.server.api.controller.dto.request.member.CreateProfileRequest; import com.soptie.server.api.controller.dto.response.member.GetHomeInfoResponse; import com.soptie.server.api.controller.dto.response.member.GiveMemberCottonResponse; +import com.soptie.server.common.exception.ExceptionCode; +import com.soptie.server.common.exception.SoftieException; import com.soptie.server.domain.conversation.Conversation; import com.soptie.server.domain.doll.DollType; import com.soptie.server.domain.memberdoll.MemberDoll; @@ -42,6 +44,11 @@ public void createMemberProfile(long memberId, CreateProfileRequest request) { @Transactional public GiveMemberCottonResponse giveCotton(long memberId, CottonType cottonType) { val member = memberAdapter.findById(memberId); + + if (member.getCottonInfo().getCottonCount(cottonType) <= 0) { + throw new SoftieException(ExceptionCode.BAD_REQUEST, "솜뭉치가 없습니다."); + } + member.getCottonInfo().subtractCotton(cottonType); memberAdapter.update(member); From 3c654fdcac78ae2d0ec2b79e6f421fb72f7b315a Mon Sep 17 00:00:00 2001 From: thguss Date: Thu, 29 Aug 2024 20:25:10 +0900 Subject: [PATCH 2/2] [FIX] updated exception handler --- .../java/com/soptie/server/api/web/advice/ErrorHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/soptie/server/api/web/advice/ErrorHandler.java b/src/main/java/com/soptie/server/api/web/advice/ErrorHandler.java index d98d6d15..35ea4f7d 100644 --- a/src/main/java/com/soptie/server/api/web/advice/ErrorHandler.java +++ b/src/main/java/com/soptie/server/api/web/advice/ErrorHandler.java @@ -15,15 +15,15 @@ public class ErrorHandler { @ExceptionHandler(SoftieException.class) - public ResponseEntity authException(SoftieException exception) { + public ResponseEntity softieException(SoftieException exception) { log.error(exception.getMessage()); return ResponseEntity .status(exception.getStatusCode()) - .body(ErrorResponse.of(exception.getDefaultMessage() + "\n" + exception.getDetailMessage())); + .body(ErrorResponse.of("[" + exception.getDefaultMessage() + "] " + exception.getDetailMessage())); } @ExceptionHandler(RuntimeException.class) - public ResponseEntity makerException(RuntimeException exception) { + public ResponseEntity exception(RuntimeException exception) { log.error(exception.getMessage()); return ResponseEntity .status(HttpStatus.INTERNAL_SERVER_ERROR.value())