-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProfileController.java
More file actions
57 lines (51 loc) · 2.32 KB
/
ProfileController.java
File metadata and controls
57 lines (51 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package life.mosu.mosuserver.presentation.profile;
import jakarta.validation.Valid;
import life.mosu.mosuserver.application.profile.ProfileService;
import life.mosu.mosuserver.global.annotation.UserId;
import life.mosu.mosuserver.global.util.ApiResponseWrapper;
import life.mosu.mosuserver.presentation.profile.dto.EditProfileRequest;
import life.mosu.mosuserver.presentation.profile.dto.ProfileDetailResponse;
import life.mosu.mosuserver.presentation.profile.dto.SignUpProfileRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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;
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/profile")
public class ProfileController implements ProfileControllerDocs {
private final ProfileService profileService;
@PostMapping
public ResponseEntity<ApiResponseWrapper<Void>> create(
@UserId Long userId,
@Valid @RequestBody SignUpProfileRequest request
) {
profileService.registerProfile(userId, request);
return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.CREATED, "프로필 등록 성공"));
}
@PutMapping
@PreAuthorize("hasRole('USER')")
public ResponseEntity<ApiResponseWrapper<Void>> update(
@UserId Long userId,
@Valid @RequestBody EditProfileRequest request
) {
profileService.editProfile(userId, request);
return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "프로필 수정 성공"));
}
@GetMapping
@PreAuthorize("hasRole('USER')")
public ResponseEntity<ApiResponseWrapper<ProfileDetailResponse>> getProfile(
@UserId Long userId
) {
ProfileDetailResponse response = profileService.getProfile(userId);
return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "프로필 조회 성공", response));
}
}