Skip to content

Commit

Permalink
fix: 아바타 저장 시 오류 해결 (#44)
Browse files Browse the repository at this point in the history
* feat: 유저 기록 기능 구현

* test: 유저 기록 기능 테스트

* fix: activity 관련 의존성 수정

* fix: 요구사항 변경에 따른 선택적 무한 스크롤

* fix: 아바타 역직렬화 과정에서의 오류 수정
  • Loading branch information
Awhn authored Oct 29, 2024
1 parent cbf6965 commit 6f5e976
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 32 deletions.
49 changes: 25 additions & 24 deletions src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/gamsa/avatar/constant/AgeRange.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/gamsa/avatar/constant/Experienced.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public ResponseEntity<String> 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<String> updateAvatar(@PathVariable Long avatarId, @RequestBody AvatarSaveRequest saveRequest) {
public ResponseEntity<String> updateAvatar(@PathVariable("avatar-id") Long avatarId, @RequestBody AvatarSaveRequest saveRequest) {
avatarService.update(avatarId, saveRequest);
return new ResponseEntity<>(HttpStatus.OK);
}

@DeleteMapping("{avatar-Id}")
public ResponseEntity<String> deleteAvatar(@PathVariable Long avatarId) {
public ResponseEntity<String> deleteAvatar(@PathVariable("avatar-id") Long avatarId) {
avatarService.delete(avatarId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/gamsa/avatar/dto/AvatarSaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/gamsa/avatar/service/AvatarService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -16,14 +18,25 @@
public class HistoryController {
private HistoryService historyService;

private static final int MAX_SIZE = Integer.MAX_VALUE;

@PostMapping
public ResponseEntity<String> addHistory(@RequestBody HistorySaveRequest saveRequest) {
historyService.save(saveRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping("{avatar-id}")
public Slice<HistoryFindSliceResponse> findSliceByUserId(@PathVariable("avatar-id") long avatarId, Pageable pageable) {
public Slice<HistoryFindSliceResponse> 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);
}

Expand Down

0 comments on commit 6f5e976

Please sign in to comment.