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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@Getter
public class CreateAssignmentRequest {
private Integer assignmentId;

private String title;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.example.Piroin.project.domain.assignment.enums;

public enum AssignmentStatus {
SUCCESS,
INSUFFICIENT,
FAILURE,
PENDING

SUCCESS, // 정상 제출 (0원)

INSUFFICIENT_MINOR, // 경미한 불충분 (-10000)

INSUFFICIENT_MAJOR, // 심각한 불충분 (-20000)

FAILURE, // 미제출 (-20000)

PENDING // 아직 채점 안 됨
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ List<AssignmentItem> findByUserIdAndAssignmentWeek(
);

Optional<AssignmentItem> findById(Integer id);

List<AssignmentItem> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,20 @@ public String expireActiveAttendance() {
return attendanceService.expireActiveAttendanceCode();
}

// 4. 출석 상태 변경 (관리자 전용)
// 현재는 출석만 변경되지만 나중에 출석 & 과제 변경으로 바꿀 예정
@Operation(summary = "출석 상태 변경", description = "관리자가 특정 사용자의 출석 상태를 변경합니다.")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "출석 상태 변경 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "잘못된 요청"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "출석 기록을 찾을 수 없음")
})

@PutMapping("/admin/users/{userId}/status")
public boolean updateUserStatus(
@Parameter(description = "사용자 ID", example = "1")
@PathVariable Integer userId,
@RequestBody UpdateUserStatusReq req) {
return attendanceService.updateUserStatus(userId, req);
}
// // 4. 출석 상태 변경 (관리자 전용)
// // 현재는 출석만 변경되지만 나중에 출석 & 과제 변경으로 바꿀 예정
// @Operation(summary = "출석 상태 변경", description = "관리자가 특정 사용자의 출석 상태를 변경합니다.")
// @ApiResponses(value = {
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "출석 상태 변경 성공"),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "잘못된 요청"),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "출석 기록을 찾을 수 없음")
// })
// @PutMapping("/admin/users/{userId}/status")
// public boolean updateUserStatus(
// @Parameter(description = "사용자 ID", example = "1")
// @PathVariable Integer userId,
// @RequestBody UpdateUserStatusReq req) {
// return attendanceService.updateUserStatus(userId, req);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public interface AttendanceRepository extends JpaRepository<Attendance, Long> {

Optional<Attendance> findById(Integer id);

// List<Attendance> findByUserId(Long userId);

//Optional<Attendance> findByUserIdAndStudySessionId(Integer userId, Long studySessionId);


// 연관관계 필드명이 attendanceCode 라면 내부 ID인 Id를 조합하여 명명
Optional<Attendance> findByUserIdAndAttendanceCodeId(Long userId, Long attendanceCodeId);
Expand All @@ -43,6 +39,8 @@ Optional<Attendance> findByUserIdAndAttendanceCodeId(
Integer attendanceCodeId
);

List<Attendance> findByAttendanceCodeId(Integer id);

// 특정 날짜에 발급된 출석 코드의 개수를 세는 메서드
//long countByAttendanceDate(String attendanceDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public AttendanceCode generateCodeAndCreateAttendances(LocalDate date) { // [수
activeCode.expire();
}

for (AttendanceCode activeCode : activeCodes) {
activeCode.expire();

List<Attendance> attendances =
attendanceRepository.findByAttendanceCodeId(activeCode.getId());

for (Attendance attendance : attendances) {
depositService.recalculateDeposit(attendance.getUser().getId());
}
}


// 4. 4자리 랜덤 코드 생성 및 차수(Order) 계산
String code = String.valueOf(ThreadLocalRandom.current().nextInt(1000, 10000));
String attendanceOrder = String.valueOf(codeCountOfDay + 1); // 1회차, 2회차, 3회차
Expand Down Expand Up @@ -226,46 +238,46 @@ public List<AttendanceStatusRes> findByUserId(Integer userId) {
.sorted(Comparator.comparing(AttendanceStatusRes::getDate).reversed())
.toList();
}

// 6. 유저 상태 변경 (관리자)
// 컨트롤러 부분은 출석만 받는데 여기는 출석&과제 둘 다 받아서 추후에 수정 예정
@Transactional
public boolean updateUserStatus(Integer userId, UpdateUserStatusReq req) {
boolean updated = false;

// 출석 상태 변경 코드
if (req.getAttendanceId() != null && req.getAttendanceStatus() != null) {
Attendance attendance = attendanceRepository.findById(req.getAttendanceId())
.orElseThrow(() -> new IllegalArgumentException("출석 기록을 찾을 수 없습니다."));

if (!attendance.getUser().getId().equals(userId)) {
throw new IllegalArgumentException("요청된 사용자와 출석 기록의 사용자가 일치하지 않습니다.");
}

attendance.updateStatus(req.getAttendanceStatus());
updated = true;
}

// 과제 상태 변경 코드
if (req.getAssignmentItemId() != null && req.getAssignmentStatus() != null) {
AssignmentItem assignmentItem = assignmentItemRepository.findById(Math.toIntExact(req.getAssignmentItemId()))
.orElseThrow(() -> new IllegalArgumentException("과제 기록을 찾을 수 없습니다."));

if (!assignmentItem.getUser().getId().equals(userId)) {
throw new IllegalArgumentException("요청된 사용자와 과제 기록의 사용자가 일치하지 않습니다.");
}

assignmentItem.updateSubmitted(req.getAssignmentStatus());
updated = true;
}

// 출석 변경 → 보증금 재계산 (과제 변경도 포함이 되어 있나..?)
if (updated) {
depositService.recalculateDeposit(Long.valueOf(userId));
}

return updated;
}
//
// // 6. 유저 상태 변경 (관리자)
// // 컨트롤러 부분은 출석만 받는데 여기는 출석&과제 둘 다 받아서 추후에 수정 예정
// @Transactional
// public boolean updateUserStatus(Integer userId, UpdateUserStatusReq req) {
// boolean updated = false;
//
// // 출석 상태 변경 코드
// if (req.getAttendanceId() != null && req.getAttendanceStatus() != null) {
// Attendance attendance = attendanceRepository.findById(req.getAttendanceId())
// .orElseThrow(() -> new IllegalArgumentException("출석 기록을 찾을 수 없습니다."));
//
// if (!attendance.getUser().getId().equals(userId)) {
// throw new IllegalArgumentException("요청된 사용자와 출석 기록의 사용자가 일치하지 않습니다.");
// }
//
// attendance.updateStatus(req.getAttendanceStatus());
// updated = true;
// }
//
// // 과제 상태 변경 코드
// if (req.getAssignmentItemId() != null && req.getAssignmentStatus() != null) {
// AssignmentItem assignmentItem = assignmentItemRepository.findById(Math.toIntExact(req.getAssignmentItemId()))
// .orElseThrow(() -> new IllegalArgumentException("과제 기록을 찾을 수 없습니다."));
//
// if (!assignmentItem.getUser().getId().equals(userId)) {
// throw new IllegalArgumentException("요청된 사용자와 과제 기록의 사용자가 일치하지 않습니다.");
// }
//
// assignmentItem.updateSubmitted(req.getAssignmentStatus());
// updated = true;
// }
//
// // 출석 변경 → 보증금 재계산 (과제 변경도 포함이 되어 있나..?)
// if (updated) {
// depositService.recalculateDeposit(Long.valueOf(userId));
// }
//
// return updated;
// }


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum CurriculumErrorCode {
SESSION_DATE_NOT_FOUND(
HttpStatus.BAD_REQUEST,
"CURRICULUM405",
"해당 날짜의 세션이 없습니다. 세션을 먼저 생성해주세요."
"해당 주차/요일의 세션이 존재하지 않습니다. 세션을 먼저 생성해주세요."
);

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Deposit {
@Column(name = "ascent_defence", nullable = false)
private Integer ascentDefence;

// 출석 차감액만 새로 계산할 때 사용
public void updateAttendanceAmount(Integer descentAttendance) {
this.descentAttendance = descentAttendance;

Expand All @@ -51,6 +52,22 @@ public void updateAttendanceAmount(Integer descentAttendance) {
+ this.ascentDefence;
}

// 과제 차감 + 출석 차감을 한 번에 재계산할 때 사용
public void updateDepositAmount(
Integer descentAssignment,
Integer descentAttendance
) {
this.descentAssignment = descentAssignment;
this.descentAttendance = descentAttendance;

int baseAmount = 100_000;

this.amount = baseAmount
- this.descentAssignment
- this.descentAttendance
+ this.ascentDefence;
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DepositService {
private final UserRepository userRepository;
private final AttendanceRepository attendanceRepository;

// 보증금 재계산 로직 (운영진이 출석/과제 여부 수정 시)
// 1. 보증금 재계산 로직 (운영진이 출석/과제 여부 수정 시, 출석코드 만료 시)
@Transactional
public void recalculateDeposit(Long userId) {
User user = userRepository.findById(userId)
Expand All @@ -37,7 +37,7 @@ public void recalculateDeposit(Long userId) {
deposit.updateAttendanceAmount(descentAttendance);
}

// 보증금 조회 로직
// 2. 보증금 조회 로직
public DepositResponse getMyDeposit(Long userId) {

Deposit deposit = depositRepository.findByUserId(userId)
Expand Down
Loading
Loading