Skip to content

Commit

Permalink
Merge pull request #22 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
[FIX] 로그인 응답 수정
  • Loading branch information
femmefatalehaein authored Sep 1, 2024
2 parents 662f43d + 4cc3496 commit 99a6662
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.ai_jeju.dto.WithdrawRequest;
import com.example.ai_jeju.handler.SignUpHandler;
import com.example.ai_jeju.service.UserService;
import com.example.ai_jeju.util.ResponseDto;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,7 +31,7 @@ public Long registerUser(@RequestBody SignUpRequest signUpRequest, HttpServletRe
}

@GetMapping("/checks")
public Map<String, Object> CheckIfUser(@RequestParam(name = "email") String email, HttpServletRequest request, HttpServletResponse response){
public ResponseDto CheckIfUser(@RequestParam(name = "email") String email, HttpServletRequest request, HttpServletResponse response){
return userService.checkIfUser(email, request, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long

//findByUserId(userId)
Optional<RefreshToken> findByUserId(Long userId);
// Optional<RefreshToken> findByEmail(String email);
}
32 changes: 18 additions & 14 deletions src/main/java/com/example/ai_jeju/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.example.ai_jeju.jwt.TokenProvider;
import com.example.ai_jeju.repository.*;
import com.example.ai_jeju.util.CookieUtil;
import com.example.ai_jeju.util.ResponseDto;
import com.example.ai_jeju.util.ResponseUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -37,42 +39,49 @@ public class UserService {

@Autowired
private UserRepository userRepository;

@Autowired
private RefreshTokenRepository refreshTokenRepository;

@Autowired
private AlbumRepository albumRepository;
@Autowired
private TokenProvider tokenProvider;
@Autowired
private ChildRepository childRepository;
@Autowired
private RefreshTokenRepository refreshTokenRepository;

@Autowired
private StoreRepository storeRepository;
/**
* login/signu up flow-1
* checkIfUser : 기존 회원여부 확인
* 기존 회원이라면 객체 (아이디만) 반환 , AccessToken 쿠키로 발급
*/
public Map<String, Object> checkIfUser(String email, HttpServletRequest request, HttpServletResponse response) {
public ResponseDto checkIfUser(String email, HttpServletRequest request, HttpServletResponse response) {
Optional<User> existingUser = userRepository.findByEmail(email);
//Optional<RefreshToken> refreshToken = refreshTokenRepository.findByEmail(email);
//String refresh_token = refreshToken.get().getRefresh_token();
//refresh_token.get
Map<String, Object> result = new HashMap<>();

if (existingUser.isPresent()) {
User user = existingUser.get();
String accessToken = tokenProvider.generateToken(user, ACCESS_TOKEN_DURATION);

return ResponseUtil.SUCCESS("로그인 완료되었습니다.", accessToken);
/*
result.put("statusCode", 1000);
result.put("message", "existinguser");
result.put("data", Map.of(
"userId", user.getId(),
"accessToken", accessToken
));
));*/
} else {
result.put("statusCode", 2000);
result.put("message", "notexistinguser");
result.put("data", null);

return ResponseUtil.FAILURE("등록되어 있지 않은 유저입니다.", null);
}

return result;

}

/**
Expand Down Expand Up @@ -165,11 +174,6 @@ public User findByEmail(String email){
()-> new IllegalArgumentException("unexpected user"));
}

// public Store findStoreById(Long id){
// return storeRepository.findById(id)
// .orElseThrow(
// ()-> new IllegalArgumentException("unexpected store"));
// }

public Optional<User> findById(Long userId){
return userRepository.findById(userId);
Expand Down Expand Up @@ -250,7 +254,7 @@ public MyPageResponse getMyPage(Long userId){
User user = userRepository.findById(userId).get();
List<Child> childs = childRepository.findAllById(userId);
// myPageResponse : 응답 객체 만들기
System.out.println(childs.get(0).getChildName());
//System.out.println(childs.get(0).getChildName());
myPageRes.setEmail(user.getEmail());
myPageRes.setName(user.getName());
myPageRes.setNickname(user.getNickname());
Expand Down

0 comments on commit 99a6662

Please sign in to comment.