Skip to content

Commit

Permalink
#22 스캘레톤 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
yooonwodyd committed Dec 22, 2023
1 parent f6f7fc8 commit 4c2e8cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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())));
}

Expand All @@ -68,17 +65,10 @@ public ResponseEntity<Page<AccountDto>> findUsers(

// 유저 생성 (테스트용)
@PostMapping("/createAccount")
public ResponseEntity<AccountDto> 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");
// }

//
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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가 동일하다면 해당 유저의 정보를 수정한다.
}
}

0 comments on commit 4c2e8cb

Please sign in to comment.