Skip to content

Commit

Permalink
google 유저 추가정보 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeSung98 committed Dec 6, 2023
1 parent eb6b2af commit 95734bd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
12 changes: 10 additions & 2 deletions user/src/main/java/com/weather/user/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.weather.user.controller;

import com.weather.user.dto.GoogleUserDTO;
import com.weather.user.dto.MailCodeDTO;
import com.weather.user.dto.UserDTO;
import com.weather.user.service.MailService;
import com.weather.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -31,6 +29,16 @@ public ResponseEntity<UserDTO> google(@RequestBody GoogleUserDTO googleUserDTO)
return new ResponseEntity<>(result, HttpStatus.OK);
}

@PostMapping("/login/google/additional")
public ResponseEntity<UserDTO> googleAdditional(@RequestBody UserDTO userDTO) throws Exception {
log.info(" ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ google controller ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
log.info("userDTO: " + userDTO);

UserDTO result = userService.googleUserAdditional(userDTO);

return new ResponseEntity<>(result, HttpStatus.OK);
}

@PostMapping("/signup/email")
public ResponseEntity<JSONObject> verifyEmail(@RequestBody UserDTO userDTO) {
log.info(" ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ verifyEmail controller ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
Expand Down
2 changes: 1 addition & 1 deletion user/src/main/java/com/weather/user/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class UserDTO {
private int id;

private String email, name, nickname, phone, image, password, token;
private String email, name, nickname, image, password, token;

private boolean fromSocial, status;
}
6 changes: 3 additions & 3 deletions user/src/main/java/com/weather/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void addRole(UserRole role) {
roleSet.add(role);
}

public void changeNickname(String nickname) {
this.nickname = nickname;
}
public void changeNickname(String nickname) { this.nickname = nickname; }

public void changeName(String name) { this.name = name; }

public void changeImage(String image) {
this.image = image;
Expand Down
4 changes: 2 additions & 2 deletions user/src/main/java/com/weather/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ public interface UserService {

UserDTO googleUserCheck(GoogleUserDTO googleUserDTO);

UserDTO googleUserAdditional(UserDTO userDTO) throws Exception;

default User dtoToEntity(UserDTO userDTO) {
User user = User.builder()
.email(userDTO.getEmail())
.name(userDTO.getName())
.nickname(userDTO.getNickname())
.password(userDTO.getPassword())
.phone(userDTO.getPhone())
.image(userDTO.getImage())
.fromSocial(userDTO.isFromSocial())
.status(userDTO.isStatus()).build();
Expand All @@ -43,7 +44,6 @@ default UserDTO entityToDTO(User user) {
.name(user.getName())
.nickname(user.getNickname())
.password(user.getPassword())
.phone(user.getPhone())
.image(user.getImage())
.fromSocial(user.isFromSocial())
.status(user.isStatus()).build();
Expand Down
29 changes: 23 additions & 6 deletions user/src/main/java/com/weather/user/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,40 @@ public UserDTO googleUserCheck(GoogleUserDTO googleUserDTO) {
Optional<User> optionalUser = userRepository.findByEmail(email, true);

if(optionalUser.isPresent()) {
User socialUser = optionalUser.get();
UserDTO result = entityToDTO(socialUser);
User user = optionalUser.get();
UserDTO result = entityToDTO(user);
return result;
} else {
User socialUser = User.builder()
User user = User.builder()
.email(email)
.password(passwordEncoder.encode("1234"))
.image(image)
.fromSocial(true)
.status(true)
.build();
socialUser.addRole(UserRole.USER);
user.addRole(UserRole.USER);

userRepository.save(user);

UserDTO result = entityToDTO(user);
return result;
}
}

userRepository.save(socialUser);
@Override
public UserDTO googleUserAdditional(UserDTO userDTO) throws Exception{
log.info("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
Optional<User> optionalUser = userRepository.findByEmail(userDTO.getEmail(), true);

UserDTO result = entityToDTO(socialUser);
if(optionalUser.isPresent()) {
User user = optionalUser.get();
user.changeNickname(userDTO.getNickname());
user.changeName(userDTO.getName());
userRepository.save(user);
UserDTO result = entityToDTO(user);
return result;
} else {
throw new Exception("잘못 된 접근입니다.");
}
}
}

0 comments on commit 95734bd

Please sign in to comment.