Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified backend/pirocheck/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DepositService {
private final DepositRepository depositRepository;
private final UserRepository userRepository;
private final AttendanceRepository attendanceRepository;
private final AssignmentRepository assignmentRepository; // 확인
private final AssignmentRepository assignmentRepository;

@Transactional
public DepositResDto getDeposit(Long userId) {
Expand All @@ -31,12 +31,12 @@ public DepositResDto getDeposit(Long userId) {

// 출석 실패
int failAttendanceCount = attendanceRepository.countByUserAndStatusFalse(user);
int descentAttendance = failAttendanceCount * 10000;
int descentAttendance = failAttendanceCount * 10_000;

// 과제 실패
int failAssignmentCount = assignmentRepository.countByUserAndSubmitted(user, AssignmentStatus.FAILURE); // 확인
int weakAssignmentCount = assignmentRepository.countByUserAndSubmitted(user, AssignmentStatus.INSUFFICIENT); // 확인
int descentAssignment = failAssignmentCount * 10_000 + weakAssignmentCount * 5_000;
int failAssignmentCount = assignmentRepository.countByUserAndSubmitted(user, AssignmentStatus.FAILURE);
int weakAssignmentCount = assignmentRepository.countByUserAndSubmitted(user, AssignmentStatus.INSUFFICIENT);
int descentAssignment = failAssignmentCount * 20_000 + weakAssignmentCount * 10_000;

// 방어권
int ascentDefence = deposit.getAscentDefence();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package backend.pirocheck.User.exception;

import backend.pirocheck.Attendance.dto.response.ApiResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(InvalidLoginException.class)
public ResponseEntity<ApiResponse<?>> handleInvalidLoginException(InvalidLoginException e) {
return ResponseEntity
.status(HttpStatus.UNAUTHORIZED) // 401 상태 코드
.body(ApiResponse.error(e.getMessage())); // 에러 메시지 전달
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package backend.pirocheck.User.exception;

public class InvalidLoginException extends RuntimeException{
public InvalidLoginException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backend.pirocheck.User.service;

import backend.pirocheck.User.entity.User;
import backend.pirocheck.User.exception.InvalidLoginException;
import backend.pirocheck.User.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -12,8 +13,14 @@ public class UserService {
private final UserRepository userRepository;

public User login(String name, String password) {
return userRepository.findByName(name)
.filter(user -> user.getPassword().equals(password))
.orElseThrow(() -> new IllegalArgumentException("이름 또는 비밀번호가 일치하지 않습니다."));
User user = userRepository.findByName(name)
.orElseThrow(() -> new InvalidLoginException("해당 사용자가 존재하지 않습니다."));

if (!user.getPassword().equals(password)) {
throw new InvalidLoginException("비밀번호가 일치하지 않습니다.");
}

return user;
}
}

Loading