-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileController.java
More file actions
51 lines (44 loc) · 1.73 KB
/
ProfileController.java
File metadata and controls
51 lines (44 loc) · 1.73 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
package com.mycom.socket.go_socket.controller;
import com.mycom.socket.auth.security.MemberDetails;
import com.mycom.socket.go_socket.dto.request.PasswordUpdateRequest;
import com.mycom.socket.go_socket.dto.request.ProfileUpdateRequest;
import com.mycom.socket.go_socket.dto.response.ProfileResponse;
import com.mycom.socket.go_socket.entity.Member;
import com.mycom.socket.go_socket.service.MemberService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/profile")
public class ProfileController {
private final MemberService memberService;
@GetMapping
public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) {
return ProfileResponse.of(memberDetails.getMember());
}
@PutMapping
public ProfileResponse updateProfile(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody @Valid ProfileUpdateRequest request
) {
Member updatedMember = memberService.updateProfile(
memberDetails.getMember().getEmail(),
request.nickname(),
request.intro()
);
return ProfileResponse.of(updatedMember);
}
@PutMapping("/password")
public void updatePassword(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody @Valid PasswordUpdateRequest request
) {
memberService.updatePassword(
memberDetails.getMember().getEmail(),
request.currentPassword(),
request.newPassword()
);
}
}