diff --git a/src/main/java/com/example/HappyNewHere/controller/AccountController.java b/src/main/java/com/example/HappyNewHere/controller/AccountController.java index 68a365c..b4f6602 100644 --- a/src/main/java/com/example/HappyNewHere/controller/AccountController.java +++ b/src/main/java/com/example/HappyNewHere/controller/AccountController.java @@ -3,6 +3,7 @@ import com.example.HappyNewHere.dto.AccountDto; import com.example.HappyNewHere.dto.UserInfo; +import com.example.HappyNewHere.dto.request.AccountRequestDto; import com.example.HappyNewHere.service.AccountService; import com.example.HappyNewHere.service.KakaoService; import com.example.HappyNewHere.utils.JwtUtils; @@ -28,11 +29,8 @@ public class AccountController { public ResponseEntity login( @RequestParam("code") String code ) { - System.out.println("dd"); String accessToken = kakaoService.kakaoToken(code); - System.out.println(accessToken); UserInfo userInfo = kakaoService.kakaoUser(accessToken); - System.out.println(userInfo); String response = accountService.saveAccount(userInfo); return ResponseEntity.ok().body(response); @@ -41,7 +39,6 @@ public ResponseEntity login( @GetMapping("/userInfo") public ResponseEntity personalInfo(Authentication authentication ) { - accountService.findAccount(Long.parseLong(authentication.getName())); return ResponseEntity.ok().body(accountService.findAccount(Long.parseLong(authentication.getName()))); } @@ -68,17 +65,10 @@ public ResponseEntity> findUsers( // 유저 생성 (테스트용) @PostMapping("/createAccount") - public ResponseEntity createAccount( - @RequestBody AccountDto accountDto - ) { - // ResponseEntity에 AccountDto를 담아서 반환 - return ResponseEntity.ok(AccountDto.from(accountService.save(accountDto))); + public ResponseEntity createAccount( + Authentication authentication, + @RequestBody AccountRequestDto accountRequestDto + ) { + return ResponseEntity.ok(accountService.updateAccount(Long.parseLong(authentication.getName()), accountRequestDto)); } - -// @GetMapping("/test") -// public ResponseEntity test() { -// return ResponseEntity.ok().body("test"); -// } - - // } diff --git a/src/main/java/com/example/HappyNewHere/dto/request/AccountRequestDto.java b/src/main/java/com/example/HappyNewHere/dto/request/AccountRequestDto.java new file mode 100644 index 0000000..8c5ca05 --- /dev/null +++ b/src/main/java/com/example/HappyNewHere/dto/request/AccountRequestDto.java @@ -0,0 +1,12 @@ +package com.example.HappyNewHere.dto.request; + +public record AccountRequestDto( + String userId, + String nickname, + String profileImg, + String stateMsg +) { + public AccountRequestDto(String userId, String nickname, String profileImg) { + this(userId, nickname, profileImg, null); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/HappyNewHere/service/AccountService.java b/src/main/java/com/example/HappyNewHere/service/AccountService.java index d2f45bb..ec5447a 100644 --- a/src/main/java/com/example/HappyNewHere/service/AccountService.java +++ b/src/main/java/com/example/HappyNewHere/service/AccountService.java @@ -4,6 +4,7 @@ import com.example.HappyNewHere.domain.Account; import com.example.HappyNewHere.dto.AccountDto; import com.example.HappyNewHere.dto.UserInfo; +import com.example.HappyNewHere.dto.request.AccountRequestDto; import com.example.HappyNewHere.repository.AccountRepository; import com.example.HappyNewHere.utils.JwtUtils; import jakarta.transaction.Transactional; @@ -80,4 +81,11 @@ public void addStateMsg(long l, String stateMsg) { account.setStateMsg(stateMsg); accountRepository.save(account); } + + // 유저 id와 AccountRequestDto를 받아서 해당 유저의 정보를 수정한다. + public AccountDto updateAccount(Long accountId, AccountRequestDto accountRequestDto) { + // AccountId로 유저가 존재하는 지 확인하고 없을시 예외 반환 + // 있다면 userId가 동일한지 확인하고 다르다면 예외 반환 + // 이미 존재하는 유저이며, userId가 동일하다면 해당 유저의 정보를 수정한다. + } }