Skip to content

Commit

Permalink
#3 fix : 로그인 응답 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Apr 17, 2023
1 parent 1cc9251 commit 6538235
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/com/zatch/zatchserver/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class UserController {
examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
})
@PostMapping("/new")
@ApiOperation(value = "회원가입", notes = "회원가입 API", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "회원가입/로그인", notes = "회원가입/로그인 API", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpServletResponse response) {
// 이메일을 통해 회원가입 or 로그인 check
String isSignup = userService.loginOrSignup(postUserReqDto.getEmail());
Expand Down Expand Up @@ -79,13 +79,16 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS
// 토큰
String email = postUserReqDto.getEmail();
String userId = userService.getUserId(email);
String nickname = userService.getNickname(email);
String accessToken = authService.issueAccessToken(Long.valueOf(userId));
response.addHeader("ACCESS_TOKEN", accessToken);
String token = userService.token(Long.valueOf(userId), accessToken);

System.out.println("token >>>>> "+token);

return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.LOGIN_SUCCESS, new GetUserReqDto(email)+" / accessToken : "+token+" / userId : "+userId), HttpStatus.OK);
GetUserResDto getUserResDto = new GetUserResDto(Long.valueOf(userId), postUserReqDto.getName(), nickname, email);

return ResponseEntity.ok().body(getUserResDto);
}

@GetMapping("/logout")
Expand Down Expand Up @@ -151,8 +154,12 @@ public ResponseEntity getMypage(@PathVariable("userId") Long userId) {
}
}

@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = GetUserResDto.class,
examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
})
@PostMapping("/{userId}/upload_profile")
@ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API")
@ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) {
try {
System.out.println("param_image : "+image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public Long insert(User user) {
}
}

@Override
public String getNickname(String email) {
try{
String sql = "SELECT nickname from user WHERE email = ?";
Object[] params = {email};
System.out.println("Get Nickname SQL select");
String nickname = String.valueOf(jdbcTemplate.queryForList(sql, params).get(0).get("nickname"));
System.out.println("Nickname : " + nickname);
return nickname;
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Nickname Not Found");
}
}

// 닉네임 수정
@Override
public Long modifyNickname(Long userId, String newNickname) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface UserRepository {

Long insert(User user);

String getNickname(String email);

Long modifyNickname(Long userId, String newNickname);

List<Map<String, Object>> profile(Long userId);
Expand All @@ -30,4 +32,5 @@ public interface UserRepository {
String uploadProfile(MultipartFile image, Long userId);

String patchProfile(MultipartFile image, Long userId);

}
2 changes: 2 additions & 0 deletions src/main/java/com/zatch/zatchserver/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface UserService {

List<User> getAll();

String getNickname(String email);

Long modifyNickname(Long userId, String newNickname);

String profile(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public List<User> getAll() {
return null;
}

@Override
public String getNickname(String email) {
return userRepository.getNickname(email);
}

@Override
public Long modifyNickname(Long userId, String newNickname) {
return userRepository.modifyNickname(userId, newNickname);
Expand Down

0 comments on commit 6538235

Please sign in to comment.