Skip to content

Commit b1117c7

Browse files
authored
[FEATURE] 유저 프로필(기본정보) 수정 (#340)
* feat(basicInfo): 사용자 기본 정보 요청 DTO 추가 - VolunteerBasicInfoRequestDto 추가 - 공통 기본 정보(CommonBasicInfoRequestDto), 닉네임, 성별 필드 포함 - CenterBasicInfoRequestDto 추가 - 공통 기본 정보(CommonBasicInfoRequestDto), 홈페이지 링크 필드 포함 - CommonBasicInfoRequestDto 추가 - 이름, 연락처, 이미지 링크, 소개 글 필드 포함 * feat(domain): 공통 속성 및 엔티티별 업데이트 메서드 추가 - UserCommonAttribute: CommonBasicInfoRequestDto 기반 업데이트 메서드 추가 - NEWVolunteer: nickname, gender, volunteerStats 업데이트 메서드 추가 - NEWCenter: homepageUrl 업데이트 메서드 추가 * test(user): 기본 정보 업데이트 로직 테스트 추가 - CommonBasicInfoRequestDto 객체 생성 및 활용 추가 - UserCommonAttribute의 customize() 메서드를 update() 메서드로 수정 * refactor(controller): 메서드명 올바르게 수정, 괄호 위치 수정 * feat(user): 사용자 기본 정보 업데이트 기능 추가 - UpdateBasicInfoUseCase 인터페이스 정의 - UpdateBasicInfoService 구현 - 사용자 공통 속성 업데이트 로직 추가 - 봉사자 및 센터 속성별 업데이트 로직 포함 * refactor(basicInfo): 역할 ID 인자를 제거하여 메소드 시그니처 개선 - VolunteerBasicInfoRequestDto와 CenterBasicInfoRequestDto를 업데이트하는 메소드에서 roleId 파라미터 삭제 * feat(basicInfo): 유저 기본 정보 업데이트 API 추가 - UserCommandController 클래스 생성 - 봉사자 기본 정보 업데이트 API 추가 - 센터 기본 정보 업데이트 API 추가 * refactor(controller): 기존 PostMapping을 PutMapping으로 변경 - 봉사자 및 센터 기본 정보 업데이트 엔드포인트를 PUT 메서드로 변경 - RESTful API 규칙에 따라 정보 업데이트에 PUT 메서드 활용 * test(user): 사용자 기본 정보 업데이트 서비스 테스트 추가 - 봉사자의 기본 정보를 업데이트하는 테스트 케이스 추가 - 센터의 기본 정보를 업데이트하는 테스트 케이스 추가 * refactor(user): 불필요한 주석 삭제 * refactor: 불필요한 어노테이션, 오타 수정
1 parent 145498d commit b1117c7

File tree

12 files changed

+333
-6
lines changed

12 files changed

+333
-6
lines changed

src/main/java/com/somemore/center/domain/NEWCenter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ public static NEWCenter createDefault(UUID userId) {
4343
.homepageUrl("")
4444
.build();
4545
}
46+
47+
public void update(String homepageUrl) {
48+
this.homepageUrl = homepageUrl;
49+
}
4650
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.somemore.user.controller;
2+
3+
import com.somemore.global.auth.annotation.UserId;
4+
import com.somemore.global.common.response.ApiResponse;
5+
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto;
6+
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto;
7+
import com.somemore.user.usecase.UpdateBasicInfoUseCase;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.tags.Tag;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.security.access.annotation.Secured;
12+
import org.springframework.web.bind.annotation.PutMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
import java.util.UUID;
18+
19+
@Tag(name = "User Command API", description = "유저 생성 수정 삭제 관련 API")
20+
@RestController
21+
@RequiredArgsConstructor
22+
@RequestMapping("/api/user")
23+
public class UserCommandController {
24+
25+
private final UpdateBasicInfoUseCase updateBasicInfoUseCase;
26+
27+
@Secured("ROLE_VOLUNTEER")
28+
@PutMapping("/basic-info/volunteer")
29+
@Operation(summary = "봉사자 기본 정보 업데이트", description = "봉사자의 기본 정보를 업데이트합니다.")
30+
public ApiResponse<String> registerBasicInfo(
31+
@UserId UUID userId,
32+
@RequestBody VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto
33+
) {
34+
updateBasicInfoUseCase.update(userId, volunteerBasicInfoRequestDto);
35+
return ApiResponse.ok("봉사자 기본 정보 업데이트 완료");
36+
}
37+
38+
@Secured("ROLE_CENTER")
39+
@PutMapping("/basic-info/center")
40+
@Operation(summary = "센터 기본 정보 업데이트", description = "센터의 기본 정보를 업데이트합니다.")
41+
public ApiResponse<String> registerBasicInfo(
42+
@UserId UUID userId,
43+
@RequestBody CenterBasicInfoRequestDto centerBasicInfoRequestDto
44+
) {
45+
updateBasicInfoUseCase.update(userId, centerBasicInfoRequestDto);
46+
return ApiResponse.ok("센터 기본 정보 업데이 완료");
47+
}
48+
}

src/main/java/com/somemore/user/controller/UserQueryController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ public ApiResponse<Boolean> checkUserExists(
3535
}
3636

3737
@GetMapping("/check/basic-info")
38-
@Operation(summary = "유저 기본 정보 입력 상태 확인", description = "현재 유저의 필수 입력 정보가 모두 완료되었는지 확인합니다."
39-
)
40-
public ApiResponse<Boolean> checkUserExists(
38+
@Operation(summary = "유저 기본 정보 입력 상태 확인", description = "현재 유저의 필수 입력 정보가 모두 완료되었는지 확인합니다.")
39+
public ApiResponse<Boolean> checkBasicInfo(
4140
@UserId UUID userId
4241
) {
4342
boolean isBasicInfoComplete = validateBasicInfoUseCase.isBasicInfoComplete(userId);

src/main/java/com/somemore/user/domain/UserCommonAttribute.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.somemore.global.common.entity.BaseEntity;
44
import com.somemore.global.imageupload.service.ImageUploadService;
5+
import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto;
56
import jakarta.persistence.Column;
67
import jakarta.persistence.Entity;
78
import jakarta.persistence.GeneratedValue;
@@ -44,8 +45,11 @@ public class UserCommonAttribute extends BaseEntity {
4445
@Column(name = "is_customized", nullable = false)
4546
private boolean isCustomized;
4647

47-
public void customize() {
48-
// TODO param의 정보를 필드에 업데이트
48+
public void update(CommonBasicInfoRequestDto commonBasicInfoRequestDto) {
49+
this.name = commonBasicInfoRequestDto.name();
50+
this.contactNumber = commonBasicInfoRequestDto.contactNumber();
51+
this.imgUrl = commonBasicInfoRequestDto.imgUrl();
52+
this.introduce = commonBasicInfoRequestDto.introduce();
4953
this.isCustomized = true;
5054
}
5155

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.somemore.user.dto.basicinfo;
2+
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.NotBlank;
7+
8+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
9+
public record CenterBasicInfoRequestDto(
10+
@Schema(description = "공통 기본 정보")
11+
@NotBlank(message = "공통 기본 정보는 필수 값입니다.")
12+
CommonBasicInfoRequestDto commonBasicInfo,
13+
14+
@Schema(description = "홈페이지 링크")
15+
@NotBlank(message = "홈페이지 링크는 필수 값입니다.")
16+
String homepageUrl
17+
) {
18+
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.somemore.user.dto.basicinfo;
2+
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.NotBlank;
7+
8+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
9+
public record CommonBasicInfoRequestDto(
10+
@Schema(description = "이름", example = "홍길동, 롯데리아")
11+
@NotBlank(message = "이름은 필수 값입니다.")
12+
String name,
13+
14+
@Schema(description = "연락처", example = "010-1234-5678, 02-123-4567")
15+
@NotBlank(message = "연락처는 필수 값입니다.")
16+
String contactNumber,
17+
18+
@Schema(description = "이미지 링크", example = "https://image.image")
19+
@NotBlank(message = "이미지 링크는 필수 값입니다.")
20+
String imgUrl,
21+
22+
@Schema(description = "소개 글", example = "햄부기햄북햄북어햄북스딱스함부르크햄부가우가햄비기햄부거햄부가티햄부기온앤온을 차려오거라")
23+
@NotBlank(message = "소개 글은 필수 값입니다.")
24+
String introduce
25+
) {
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.somemore.user.dto.basicinfo;
2+
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.NotBlank;
7+
8+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
9+
public record VolunteerBasicInfoRequestDto(
10+
@Schema(description = "공통 기본 정보")
11+
@NotBlank(message = "공통 기본 정보는 필수 값입니다.")
12+
CommonBasicInfoRequestDto commonBasicInfo,
13+
14+
@Schema(description = "닉네임", example = "칠가이")
15+
@NotBlank(message = "닉네임은 필수 값입니다.")
16+
String nickname,
17+
18+
@Schema(description = "성별", example = "MALE", allowableValues = {"MALE", "FEMALE"})
19+
@NotBlank(message = "성별은 필수 값입니다.")
20+
String gender
21+
) {
22+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.somemore.user.service;
2+
3+
import com.somemore.center.domain.NEWCenter;
4+
import com.somemore.center.usecase.NEWCenterQueryUseCase;
5+
import com.somemore.domains.volunteer.domain.Gender;
6+
import com.somemore.user.domain.UserCommonAttribute;
7+
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto;
8+
import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto;
9+
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto;
10+
import com.somemore.user.usecase.UpdateBasicInfoUseCase;
11+
import com.somemore.user.usecase.UserQueryUseCase;
12+
import com.somemore.volunteer.domain.NEWVolunteer;
13+
import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase;
14+
import lombok.RequiredArgsConstructor;
15+
import lombok.extern.slf4j.Slf4j;
16+
import org.springframework.stereotype.Service;
17+
import org.springframework.transaction.annotation.Transactional;
18+
19+
import java.util.UUID;
20+
21+
@Service
22+
@Transactional
23+
@Slf4j
24+
@RequiredArgsConstructor
25+
public class UpdateBasicInfoService implements UpdateBasicInfoUseCase {
26+
27+
private final UserQueryUseCase userQueryUseCase;
28+
private final NEWVolunteerQueryUseCase volunteerQueryUseCase;
29+
private final NEWCenterQueryUseCase centerQueryUseCase;
30+
31+
@Override
32+
public void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) {
33+
updateCommonAttribute(userId, volunteerBasicInfoRequestDto.commonBasicInfo());
34+
updateVolunteerAttribute(userId, volunteerBasicInfoRequestDto);
35+
}
36+
37+
@Override
38+
public void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) {
39+
updateCommonAttribute(userId, centerBasicInfoRequestDto.commonBasicInfo());
40+
updateCenterAttribute(userId, centerBasicInfoRequestDto);
41+
}
42+
43+
private void updateCommonAttribute(UUID userId, CommonBasicInfoRequestDto commonBasicInfoRequestDto) {
44+
UserCommonAttribute commonAttribute = userQueryUseCase.getCommonAttributeByUserId(userId);
45+
commonAttribute.update(commonBasicInfoRequestDto);
46+
}
47+
48+
private void updateVolunteerAttribute(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) {
49+
NEWVolunteer volunteer = volunteerQueryUseCase.getByUserId(userId);
50+
volunteer.update(volunteerBasicInfoRequestDto.nickname());
51+
volunteer.update(Gender.from(volunteerBasicInfoRequestDto.gender()));
52+
}
53+
54+
private void updateCenterAttribute(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) {
55+
NEWCenter center = centerQueryUseCase.getByUserId(userId);
56+
center.update(centerBasicInfoRequestDto.homepageUrl());
57+
}
58+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.somemore.user.usecase;
2+
3+
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto;
4+
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto;
5+
6+
import java.util.UUID;
7+
8+
public interface UpdateBasicInfoUseCase {
9+
10+
void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto);
11+
12+
void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto);
13+
}

src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public static NEWVolunteer createDefault(UUID userId) {
7777
.build();
7878
}
7979

80+
public void update(String nickname) {
81+
this.nickname = nickname;
82+
}
83+
84+
public void update(Gender gender) {
85+
this.gender = gender;
86+
}
87+
8088
public void updateVolunteerStats(int hours, int count) {
8189
this.totalVolunteerHours += hours;
8290
this.totalVolunteerCount += count;

0 commit comments

Comments
 (0)