Skip to content

Commit

Permalink
[fix] #94 Common 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
kmjenny committed Jun 7, 2024
1 parent 600de26 commit 8f1df0b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
Expand All @@ -35,11 +37,12 @@ public ResponseEntity<ProfileInfoDto> getProfileExtraInfo(
}

@PutMapping("/rooms/{roomId}")
public ResponseEntity<Profile> updateProfileInfo(
public ResponseEntity<Void> 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();
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/telepigeon/server/domain/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/telepigeon/server/dto/type/AgeRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/telepigeon/server/dto/type/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/telepigeon/server/dto/type/Relation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 8f1df0b

Please sign in to comment.