diff --git a/src/main/java/com/telepigeon/server/controller/ProfileController.java b/src/main/java/com/telepigeon/server/controller/ProfileController.java index 81e10ec..2e0bcf1 100644 --- a/src/main/java/com/telepigeon/server/controller/ProfileController.java +++ b/src/main/java/com/telepigeon/server/controller/ProfileController.java @@ -11,6 +11,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.net.URI; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v1") @@ -35,11 +37,12 @@ public ResponseEntity getProfileExtraInfo( } @PutMapping("/rooms/{roomId}") - public ResponseEntity updateProfileInfo( + public ResponseEntity updateProfileInfo( @PathVariable final Long roomId, @UserId final Long userId, @Valid @RequestBody final ProfileDto profileDto ) { - return ResponseEntity.ok(profileService.updateProfileInfo(roomId, userId, profileDto)); + profileService.updateProfileInfo(roomId, userId, profileDto); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/com/telepigeon/server/domain/Profile.java b/src/main/java/com/telepigeon/server/domain/Profile.java index d1207ac..e0af36f 100644 --- a/src/main/java/com/telepigeon/server/domain/Profile.java +++ b/src/main/java/com/telepigeon/server/domain/Profile.java @@ -101,14 +101,14 @@ public void updateEmotion(Double emotion) { public void updateProfileInfo( String keywords, - String gender, - String ageRange, - String relation + Gender gender, + AgeRange ageRange, + Relation relation ) { this.keywords = keywords; - this.gender = Gender.valueOf(gender); - this.ageRange = AgeRange.valueOf(ageRange); - this.relation = Relation.valueOf(relation); + this.gender = gender; + this.ageRange = ageRange; + this.relation = relation; this.updatedAt = LocalDateTime.now(); } } diff --git a/src/main/java/com/telepigeon/server/dto/type/AgeRange.java b/src/main/java/com/telepigeon/server/dto/type/AgeRange.java index de19c97..481b649 100644 --- a/src/main/java/com/telepigeon/server/dto/type/AgeRange.java +++ b/src/main/java/com/telepigeon/server/dto/type/AgeRange.java @@ -14,4 +14,13 @@ public enum AgeRange { SIXTY("60대"), SEVENTY("70대 이상"); private final String content; + + public static AgeRange fromContent(String content) { + for (AgeRange ageRange : AgeRange.values()) { + if (ageRange.getContent().equals(content)) { + return ageRange; + } + } + throw new IllegalArgumentException("Unknown content : " + content); + } } diff --git a/src/main/java/com/telepigeon/server/dto/type/Gender.java b/src/main/java/com/telepigeon/server/dto/type/Gender.java index 6bcc1d9..8d879ba 100644 --- a/src/main/java/com/telepigeon/server/dto/type/Gender.java +++ b/src/main/java/com/telepigeon/server/dto/type/Gender.java @@ -2,11 +2,22 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Getter @AllArgsConstructor public enum Gender { MALE("남성"), FEMALE("여성"); private final String content; + + public static Gender fromContent(String content) { + for (Gender gender : Gender.values()) { + if (gender.getContent().equals(content)) { + return gender; + } + } + throw new IllegalArgumentException("Unknown content : " + content); + } } diff --git a/src/main/java/com/telepigeon/server/dto/type/Relation.java b/src/main/java/com/telepigeon/server/dto/type/Relation.java index 18b13da..ba93264 100644 --- a/src/main/java/com/telepigeon/server/dto/type/Relation.java +++ b/src/main/java/com/telepigeon/server/dto/type/Relation.java @@ -6,9 +6,18 @@ @Getter @AllArgsConstructor public enum Relation { - FRIEND("지인"), + FRIEND("친구"), CHILD("자식"), MOTHER("엄마"), FATHER("아빠"); private final String content; + + public static Relation fromContent(String content) { + for (Relation relation : Relation.values()) { + if (relation.getContent().equals(content)) { + return relation; + } + } + throw new IllegalArgumentException("Unknown content : " + content); + } } diff --git a/src/main/java/com/telepigeon/server/service/profile/ProfileService.java b/src/main/java/com/telepigeon/server/service/profile/ProfileService.java index 481ae02..07c4bec 100644 --- a/src/main/java/com/telepigeon/server/service/profile/ProfileService.java +++ b/src/main/java/com/telepigeon/server/service/profile/ProfileService.java @@ -6,6 +6,9 @@ import com.telepigeon.server.dto.profile.request.ProfileDto; import com.telepigeon.server.dto.profile.response.ProfileInfoDto; import com.telepigeon.server.dto.profile.response.ProfileKeywordsDto; +import com.telepigeon.server.dto.type.AgeRange; +import com.telepigeon.server.dto.type.Gender; +import com.telepigeon.server.dto.type.Relation; import com.telepigeon.server.service.room.RoomRetriever; import com.telepigeon.server.service.user.UserRetriever; import lombok.RequiredArgsConstructor; @@ -53,7 +56,7 @@ public ProfileInfoDto getProfileExtraInfo(final Long roomId, final Long userId) } @Transactional - public Profile updateProfileInfo( + public void updateProfileInfo( final Long roomId, final Long userId, final ProfileDto profileDto @@ -70,11 +73,9 @@ public Profile updateProfileInfo( profileUpdater.updateProfileInfo( profile, keywords, - profileDto.gender(), - profileDto.ageRange(), - profileDto.relation() + Gender.fromContent(profileDto.gender()), + AgeRange.fromContent(profileDto.ageRange()), + Relation.fromContent(profileDto.relation()) ); - - return profileSaver.save(profile); } } diff --git a/src/main/java/com/telepigeon/server/service/profile/ProfileUpdater.java b/src/main/java/com/telepigeon/server/service/profile/ProfileUpdater.java index f0ae640..c8babbf 100644 --- a/src/main/java/com/telepigeon/server/service/profile/ProfileUpdater.java +++ b/src/main/java/com/telepigeon/server/service/profile/ProfileUpdater.java @@ -1,6 +1,9 @@ package com.telepigeon.server.service.profile; import com.telepigeon.server.domain.Profile; +import com.telepigeon.server.dto.type.AgeRange; +import com.telepigeon.server.dto.type.Gender; +import com.telepigeon.server.dto.type.Relation; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -11,9 +14,9 @@ public class ProfileUpdater { public void updateProfileInfo( final Profile profile, final String keywords, - final String gender, - final String ageRange, - final String relation + final Gender gender, + final AgeRange ageRange, + final Relation relation ) { profile.updateProfileInfo(keywords, gender, ageRange, relation); } diff --git a/src/test/java/com/telepigeon/server/profileTest/ProfileServiceTest.java b/src/test/java/com/telepigeon/server/profileTest/ProfileServiceTest.java index 6231e81..03fe07e 100644 --- a/src/test/java/com/telepigeon/server/profileTest/ProfileServiceTest.java +++ b/src/test/java/com/telepigeon/server/profileTest/ProfileServiceTest.java @@ -133,7 +133,7 @@ public void updateProfileExtraInfoTest() { Profile updatedProfile = profileService.updateProfileInfo(roomId, userId, profileDto); // Then (method의 호출 검증을 통해 확인) - verify(profileUpdater).updateProfileInfo(profile, keyword, gender.getContent(), ageRange.getContent(), relation.getContent()); + verify(profileUpdater).updateProfileInfo(profile, keyword, gender, ageRange, relation); verify(profileSaver).save(profile); } }