-
Notifications
You must be signed in to change notification settings - Fork 0
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
[TNT-217] feat: 트레이니 - 식단 등록 기능 구현 #57
Changes from 8 commits
87e2d2d
2b43c5f
dae5c27
e94a40d
15f6246
f5f603e
2b232a3
91b0d70
52fdc1b
33b4d39
17b0459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.tnt.application.trainee; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.tnt.domain.trainee.Diet; | ||
import com.tnt.infrastructure.mysql.repository.trainee.DietRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DietService { | ||
|
||
private final DietRepository dietRepository; | ||
|
||
@Transactional | ||
public Diet save(Diet diet) { | ||
return dietRepository.save(diet); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.tnt.domain.trainee; | ||
|
||
import static com.tnt.common.error.model.ErrorMessage.DIET_INVALID_IMAGE_URL; | ||
import static com.tnt.common.error.model.ErrorMessage.DIET_INVALID_MEMO; | ||
import static io.micrometer.common.util.StringUtils.isBlank; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
|
||
import com.tnt.infrastructure.mysql.BaseTimeEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "diet") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Diet extends BaseTimeEntity { | ||
|
||
public static final int DIET_IMAGE_URL_LENGTH = 255; | ||
public static final int MEMO_LENGTH = 100; | ||
public static final int DIET_TYPE_LENGTH = 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다~ 반영하겠습니다 ! |
||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false, unique = true) | ||
private Long id; | ||
|
||
@Column(name = "trainee_id", nullable = false) | ||
private Long traineeId; | ||
|
||
@Column(name = "date", nullable = false) | ||
private LocalDate date; | ||
|
||
@Column(name = "time", nullable = false) | ||
private LocalTime time; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 따로 받도록 구현하신 이유가 있을까요!? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 수정해서 반영하겠습니다 ! |
||
|
||
@Column(name = "diet_image_url", nullable = false, length = DIET_IMAGE_URL_LENGTH) | ||
private String dietImageUrl; | ||
|
||
@Column(name = "memo", nullable = false, length = MEMO_LENGTH) | ||
private String memo; | ||
|
||
@Column(name = "deleted_at", nullable = true) | ||
private LocalDateTime deletedAt; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "diet_type", nullable = false, length = DIET_TYPE_LENGTH) | ||
private DietType dietType; | ||
|
||
@Builder | ||
public Diet(Long id, Long traineeId, LocalDate date, LocalTime time, String dietImageUrl, String memo, | ||
DietType dietType) { | ||
this.id = id; | ||
this.traineeId = requireNonNull(traineeId); | ||
this.date = requireNonNull(date); | ||
this.time = requireNonNull(time); | ||
this.dietImageUrl = validateDietImageUrl(dietImageUrl); | ||
this.memo = validateMemo(memo); | ||
this.dietType = requireNonNull(dietType); | ||
} | ||
|
||
private String validateDietImageUrl(String dietImageUrl) { | ||
if (dietImageUrl.length() > DIET_IMAGE_URL_LENGTH) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사진 없으면 디폴트를 |
||
throw new IllegalArgumentException(DIET_INVALID_IMAGE_URL.getMessage()); | ||
} | ||
|
||
return dietImageUrl; | ||
} | ||
|
||
private String validateMemo(String memo) { | ||
if (isBlank(memo) || memo.length() > MEMO_LENGTH) { | ||
throw new IllegalArgumentException(DIET_INVALID_MEMO.getMessage()); | ||
} | ||
|
||
return memo; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tnt.domain.trainee; | ||
|
||
import static com.tnt.common.error.model.ErrorMessage.UNSUPPORTED_DIET_TYPE; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.tnt.common.error.exception.TnTException; | ||
|
||
public enum DietType { | ||
BREAKFAST, | ||
LUNCH, | ||
DINNER, | ||
SNACK; | ||
|
||
@JsonCreator | ||
public static DietType of(String value) { | ||
for (DietType type : DietType.values()) { | ||
if (type.name().equalsIgnoreCase(value)) { // 대소문자 구분 없이 처리 | ||
return type; | ||
} | ||
} | ||
throw new TnTException(UNSUPPORTED_DIET_TYPE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.tnt.dto.trainer.request; | ||
package com.tnt.dto.trainee.request; | ||
|
||
import java.time.LocalDate; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.tnt.dto.trainee.request; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
import com.tnt.domain.trainee.DietType; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.PastOrPresent; | ||
|
||
@Schema(description = "식단 등록 API 요청") | ||
public record CreateDietRequest( | ||
@Schema(description = "식사 날짜", example = "2025-01-01", nullable = true) | ||
@PastOrPresent(message = "식사 날짜는 현재거나 과거 날짜여야 합니다.") | ||
LocalDate date, | ||
|
||
@Schema(description = "식사 시간", example = "19:30", nullable = true) | ||
@PastOrPresent(message = "식사 시간은 현재거나 과거 시간이어야 합니다.") | ||
LocalTime time, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 Entity 쪽 참고 부탁드려요! |
||
|
||
@Schema(description = "식단 타입", example = "BREAKFAST", nullable = false) | ||
@NotNull(message = "식단 타입은 필수입니다.") | ||
DietType dietType, | ||
|
||
@Schema(description = "메모", example = "아 배부르다.", nullable = false) | ||
@NotBlank(message = "메모는 필수입니다.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100자 이하로 받기 때문에 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 반영하겠습니다 ! |
||
String memo | ||
) { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메모 부분은 추후에 넣어주어야 하니까 나중을 위해 위에다가 주석 하나 달아주세요!
ex)
// Memo 추가 구현
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 반영하겠습니다 !