diff --git a/src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java b/src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java index cc0bc8d..8f4bc59 100644 --- a/src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java +++ b/src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java @@ -4,11 +4,12 @@ import com.gamsa.activity.domain.Activity; import com.gamsa.activity.domain.District; import com.gamsa.activity.domain.Institute; -import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import java.time.LocalDateTime; + @Getter @Builder @RequiredArgsConstructor @@ -38,27 +39,27 @@ public class ActivitySaveRequest { public Activity toModel(Institute institute, District sidoGungu) { return Activity.builder() - .actId(actId) - .actTitle(actTitle) - .actLocation(actLocation) - .description(description) - .noticeStartDate(noticeStartDate) - .noticeEndDate(noticeEndDate) - .actStartDate(actStartDate) - .actEndDate(actEndDate) - .actStartTime(actStartTime) - .actEndTime(actEndTime) - .recruitTotalNum(recruitTotalNum) - .adultPossible(adultPossible) - .teenPossible(teenPossible) - .groupPossible(groupPossible) - .actWeek(actWeek) - .actManager(actManager) - .actPhone(actPhone) - .url(url) - .category(category) - .institute(institute) - .sidoGungu(sidoGungu) - .build(); + .actId(actId) + .actTitle(actTitle) + .actLocation(actLocation) + .description(description) + .noticeStartDate(noticeStartDate) + .noticeEndDate(noticeEndDate) + .actStartDate(actStartDate) + .actEndDate(actEndDate) + .actStartTime(actStartTime) + .actEndTime(actEndTime) + .recruitTotalNum(recruitTotalNum) + .adultPossible(adultPossible) + .teenPossible(teenPossible) + .groupPossible(groupPossible) + .actWeek(actWeek) + .actManager(actManager) + .actPhone(actPhone) + .url(url) + .category(category) + .institute(institute) + .sidoGungu(sidoGungu) + .build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/gamsa/avatar/constant/AgeRange.java b/src/main/java/com/gamsa/avatar/constant/AgeRange.java index 9da6952..fd857c3 100644 --- a/src/main/java/com/gamsa/avatar/constant/AgeRange.java +++ b/src/main/java/com/gamsa/avatar/constant/AgeRange.java @@ -1,5 +1,7 @@ package com.gamsa.avatar.constant; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,4 +13,19 @@ public enum AgeRange { ADULT("성인"); private final String name; + + @JsonCreator + public static AgeRange fromValue(String value) { + for (AgeRange ageRange : AgeRange.values()) { + if (ageRange.name.equals(value)) { + return ageRange; + } + } + throw new IllegalArgumentException("Unknown value: " + value); + } + + @JsonValue + public String toValue() { + return this.name; + } } diff --git a/src/main/java/com/gamsa/avatar/constant/Experienced.java b/src/main/java/com/gamsa/avatar/constant/Experienced.java index c54cddc..392c006 100644 --- a/src/main/java/com/gamsa/avatar/constant/Experienced.java +++ b/src/main/java/com/gamsa/avatar/constant/Experienced.java @@ -1,5 +1,7 @@ package com.gamsa.avatar.constant; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,4 +13,19 @@ public enum Experienced { EXPERT("상급자"); private final String name; + + @JsonCreator + public static Experienced fromValue(String value) { + for (Experienced level : Experienced.values()) { + if (level.name.equals(value)) { + return level; + } + } + throw new IllegalArgumentException("Unknown value: " + value); + } + + @JsonValue + public String toValue() { + return this.name; + } } diff --git a/src/main/java/com/gamsa/avatar/controller/AvatarController.java b/src/main/java/com/gamsa/avatar/controller/AvatarController.java index 9008cbd..ee6c805 100644 --- a/src/main/java/com/gamsa/avatar/controller/AvatarController.java +++ b/src/main/java/com/gamsa/avatar/controller/AvatarController.java @@ -23,18 +23,18 @@ public ResponseEntity saveAvatar(@RequestBody AvatarSaveRequest saveRequ } @GetMapping("{avatar-id}") - public AvatarFindResponse getAvatar(@PathVariable Long avatarId) { + public AvatarFindResponse getAvatar(@PathVariable("avatar-id") Long avatarId) { return avatarService.findById(avatarId); } @PutMapping("{avatar-id}") - public ResponseEntity updateAvatar(@PathVariable Long avatarId, @RequestBody AvatarSaveRequest saveRequest) { + public ResponseEntity updateAvatar(@PathVariable("avatar-id") Long avatarId, @RequestBody AvatarSaveRequest saveRequest) { avatarService.update(avatarId, saveRequest); return new ResponseEntity<>(HttpStatus.OK); } @DeleteMapping("{avatar-Id}") - public ResponseEntity deleteAvatar(@PathVariable Long avatarId) { + public ResponseEntity deleteAvatar(@PathVariable("avatar-id") Long avatarId) { avatarService.delete(avatarId); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/java/com/gamsa/avatar/dto/AvatarSaveRequest.java b/src/main/java/com/gamsa/avatar/dto/AvatarSaveRequest.java index 3efd859..28af1b5 100644 --- a/src/main/java/com/gamsa/avatar/dto/AvatarSaveRequest.java +++ b/src/main/java/com/gamsa/avatar/dto/AvatarSaveRequest.java @@ -7,16 +7,16 @@ import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; -import java.time.LocalDateTime; - @Getter @Builder @RequiredArgsConstructor +@NoArgsConstructor(force = true) public class AvatarSaveRequest { @NotNull(message = "닉네임은 비어있으면 안됩니다.") - @Max(value=10, message = "닉네임은 최대 10자입니다.") + @Max(value = 10, message = "닉네임은 최대 10자입니다.") private final String nickname; @NotNull(message = "연령대를 선택해야 합니다.") private final AgeRange ageRange; diff --git a/src/main/java/com/gamsa/avatar/service/AvatarService.java b/src/main/java/com/gamsa/avatar/service/AvatarService.java index b55c41a..3eb0193 100644 --- a/src/main/java/com/gamsa/avatar/service/AvatarService.java +++ b/src/main/java/com/gamsa/avatar/service/AvatarService.java @@ -21,7 +21,6 @@ public AvatarFindResponse findById(Long id) { public void save(AvatarSaveRequest saveRequest) { Avatar avatar = saveRequest.toModel(); - avatarRepository.findById(avatar.getAvatarId()).orElseThrow(NoSuchElementException::new); avatarRepository.save(avatar); } diff --git a/src/main/java/com/gamsa/history/controller/HistoryController.java b/src/main/java/com/gamsa/history/controller/HistoryController.java index 1dac62f..3e57205 100644 --- a/src/main/java/com/gamsa/history/controller/HistoryController.java +++ b/src/main/java/com/gamsa/history/controller/HistoryController.java @@ -4,8 +4,10 @@ import com.gamsa.history.dto.HistorySaveRequest; import com.gamsa.history.service.HistoryService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -16,6 +18,8 @@ public class HistoryController { private HistoryService historyService; + private static final int MAX_SIZE = Integer.MAX_VALUE; + @PostMapping public ResponseEntity addHistory(@RequestBody HistorySaveRequest saveRequest) { historyService.save(saveRequest); @@ -23,7 +27,16 @@ public ResponseEntity addHistory(@RequestBody HistorySaveRequest saveReq } @GetMapping("{avatar-id}") - public Slice findSliceByUserId(@PathVariable("avatar-id") long avatarId, Pageable pageable) { + public Slice findSliceByUserId(@PathVariable("avatar-id") long avatarId, + @RequestParam(value = "page", required = false) Integer page, + @RequestParam(value = "size", required = false) Integer size) { + Pageable pageable; + + if (page == null || size == null) { + pageable = PageRequest.of(0, MAX_SIZE, Sort.unsorted()); + } else { + pageable = PageRequest.of(page, size, Sort.unsorted()); + } return historyService.findSliceByAvatarId(avatarId, pageable); }