Skip to content

Commit

Permalink
refactor: 테스트 로그인 - 정상 변경 (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeeerish authored Sep 26, 2024
1 parent d2bec5d commit 77b7d4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Skeep.backend.weather.service.WeatherSchedulerService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,6 +23,9 @@
@RequiredArgsConstructor
@RequestMapping("/api/ping")
public class PingController {
@Value("${test.email}")
private String testEmail;

private final UserFindService userFindService;
private final AppleService appleService;
private final LocationGridRepository locationGridRepository;
Expand All @@ -36,7 +40,10 @@ public ResponseEntity<JwtDto> login(@RequestBody @Valid String serialId) {

@PostMapping("/login/test")
public ResponseEntity<JwtDto> login() {
throw BaseException.type(GlobalErrorCode.INTERNAL_SERVER_ERROR);
// throw BaseException.type(GlobalErrorCode.INTERNAL_SERVER_ERROR);
User user = userFindService.findUserByEmail(testEmail);
JwtDto jwtDto = appleService.createJwtDto(user.getId(), user.getRole());
return ResponseEntity.ok(jwtDto);
}

@GetMapping("/location-grid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findBySerialId(String serialId);
Optional<User> findById(Long id);
Optional<User> findByIdAndStatus(Long id, EStatus status);
Optional<User> findByEmail(Email email);
}
6 changes: 6 additions & 0 deletions src/main/java/Skeep/backend/user/service/UserFindService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Skeep.backend.global.exception.BaseException;
import Skeep.backend.user.domain.EStatus;
import Skeep.backend.user.domain.Email;
import Skeep.backend.user.domain.User;
import Skeep.backend.user.domain.UserRepository;
import Skeep.backend.user.dto.UserSecurityForm;
Expand Down Expand Up @@ -37,6 +38,11 @@ public User findUserBySerialId(String serialId) {
.orElseThrow(() -> BaseException.type(UserErrorCode.NOT_FOUND_USER));
}

public User findUserByEmail(String email) {
return userRepository.findByEmail(Email.createEmail(email))
.orElseThrow(() -> BaseException.type(UserErrorCode.NOT_FOUND_USER));
}

public User findById(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> BaseException.type(UserErrorCode.NOT_FOUND_USER));
Expand Down

0 comments on commit 77b7d4c

Please sign in to comment.