Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] 솜뭉치 개수가 0 이하일 경우 예외 처리 추가 #340

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
public class ErrorHandler {

@ExceptionHandler(SoftieException.class)
public ResponseEntity<ErrorResponse> authException(SoftieException exception) {
public ResponseEntity<ErrorResponse> 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<ErrorResponse> makerException(RuntimeException exception) {
public ResponseEntity<ErrorResponse> exception(RuntimeException exception) {
log.error(exception.getMessage());
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Loading