-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 프로필 조회/수정
- Loading branch information
김해동
committed
Oct 18, 2023
1 parent
7afe4ff
commit 8f415d3
Showing
7 changed files
with
202 additions
and
13 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/koliving/api/my/application/dto/UserProfileUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.koliving.api.my.application.dto; | ||
|
||
import com.koliving.api.file.domain.ImageFile; | ||
import com.koliving.api.user.Gender; | ||
import com.koliving.api.user.User; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.springframework.lang.Nullable; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
|
||
@Schema(description = "작성자 정보") | ||
public record UserProfileUpdateRequest( | ||
|
||
@NotNull | ||
@Schema(description = "이미지 URL 고유 Key") | ||
Long profileId, | ||
|
||
@NotNull | ||
@Schema(description = "성별") | ||
Gender gender, | ||
|
||
@NotNull | ||
@Schema(description = "이름") | ||
String firstName, | ||
|
||
@NotNull | ||
@Schema(description = "성") | ||
String lastName, | ||
|
||
@NotNull | ||
@Schema(description = "생년월일") | ||
LocalDate birthDate, | ||
|
||
@Nullable | ||
@Schema(description = "설명") | ||
String description | ||
) { | ||
public User toUser(ImageFile imageFile) { | ||
return User.of(imageFile, gender, firstName, lastName, birthDate, description); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.koliving.api.my.ui; | ||
|
||
import com.koliving.api.base.ErrorResponse; | ||
import com.koliving.api.my.application.dto.UserProfileUpdateRequest; | ||
import com.koliving.api.user.User; | ||
import com.koliving.api.user.application.UserService; | ||
import com.koliving.api.user.application.dto.UserResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@Tag(name = "MY API", description = "MY API") | ||
@RestController | ||
@RequestMapping("api/v1/my") | ||
@RequiredArgsConstructor | ||
public class MyController { | ||
private final UserService userService; | ||
|
||
@Operation( | ||
summary = "프로필 수정", | ||
description = "프로필을 수정합니다.", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "204", | ||
description = "프로필 수정 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "프로필 수정 실패", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class)) | ||
), | ||
}) | ||
@PutMapping("/profile") | ||
public ResponseEntity<Void> updateProfile(@RequestBody UserProfileUpdateRequest request, @AuthenticationPrincipal User user) { | ||
userService.updateProfile(request, user.getId()); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
|
||
@Operation( | ||
summary = "프로필 조회", | ||
description = "프로필 정보를 조회합니다", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "프로필 조회 성공", | ||
content = @Content(schema = @Schema(implementation = UserResponse.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "프로필 조회 실패", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class)) | ||
), | ||
}) | ||
@GetMapping | ||
public ResponseEntity<UserResponse> myProfile(@AuthenticationPrincipal User user) { | ||
UserResponse response = userService.findById(user.getId()); | ||
|
||
return ResponseEntity.ok() | ||
.body(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 20 additions & 2 deletions
22
src/main/java/com/koliving/api/user/application/dto/UserResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
package com.koliving.api.user.application.dto; | ||
|
||
|
||
import com.koliving.api.file.domain.ImageFile; | ||
import com.koliving.api.user.Gender; | ||
import com.koliving.api.user.SignUpStatus; | ||
import com.koliving.api.user.User; | ||
import com.koliving.api.user.UserRole; | ||
|
||
public record UserResponse(Long id, String email, String imageUrl) { | ||
import java.time.LocalDate; | ||
|
||
public record UserResponse(Long id, String email, String firstName, String lastName, Gender gender, LocalDate birthDate, | ||
String description, ImageFile imageFile, UserRole userRole, SignUpStatus signUpStatus) { | ||
|
||
public static UserResponse valueOf(User entity) { | ||
return new UserResponse(entity.getId(), entity.getEmail(), entity.getImageUrl()); | ||
return new UserResponse( | ||
entity.getId(), | ||
entity.getEmail(), | ||
entity.getFirstName(), | ||
entity.getLastName(), | ||
entity.getGender(), | ||
entity.getBirthDate(), | ||
entity.getDescription(), | ||
entity.getImageFile(), | ||
entity.getUserRole(), | ||
entity.getSignUpStatus() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters