Skip to content

Commit

Permalink
[FIX] �솝탬프 contents가 empty이면 오류가 발생하는 에러 해결 (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Nov 19, 2024
2 parents f4130fb + 72e559e commit 59ad7ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/main/java/org/sopt/app/application/stamp/StampService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.sopt.app.application.user.UserWithdrawEvent;
import org.sopt.app.common.event.EventPublisher;
Expand All @@ -21,6 +22,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class StampService {

private final StampRepository stampRepository;
Expand All @@ -42,6 +44,24 @@ public StampInfo.Stamp findStamp(Long missionId, Long userId) {
.build();
}

private void validateStampInfo(Stamp entity) {
if (!StringUtils.hasText(entity.getContents())) {
if(entity.getContents().isEmpty()) {
log.warn("Stamp ID-{}: stamp contents is empty", entity.getId());
}
throw new BadRequestException(ErrorCode.INVALID_STAMP_CONTENTS);
}
if (entity.getImages().isEmpty()) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_IMAGES);
}
if (entity.getActivityDate() == null) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_ACTIVITY_DATE);
}
if (entity.getMissionId() == null) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_MISSION_ID);
}
}

@Transactional
public StampInfo.Stamp uploadStampDeprecated(
@Valid RegisterStampRequest stampRequest,
Expand Down Expand Up @@ -163,24 +183,6 @@ public void handleUserWithdrawEvent(final UserWithdrawEvent event) {
this.deleteAllStamps(event.getUserId());
}

private void validateStampInfo(Stamp entity) {
if (entity.getId() == null) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_ID);
}
if (!StringUtils.hasText(entity.getContents())) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_CONTENTS);
}
if (entity.getImages().isEmpty()) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_IMAGES);
}
if (entity.getActivityDate() == null) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_ACTIVITY_DATE);
}
if (entity.getMissionId() == null) {
throw new BadRequestException(ErrorCode.INVALID_STAMP_MISSION_ID);
}
}

private Stamp convertStampImgDeprecated(
@Valid RegisterStampRequest stampRequest,
List<String> imgList,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.app.presentation.stamp;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -36,6 +37,7 @@ public static class RegisterStampRequest {
private String image;
@Schema(description = "스탬프 내용", example = "스탬프 찍었다!")
@NotNull(message = "contents may not be null")
@NotEmpty(message = "contents may not be empty")
private String contents;
@Schema(description = "활동 날짜", example = "2024.04.08")
@NotNull(message = "activity date may not be null")
Expand Down

0 comments on commit 59ad7ae

Please sign in to comment.