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 @@ -14,6 +14,7 @@ public enum ErrorCode implements BaseCode { // 실패
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER_4041", "존재하지 않는 회원입니다."),
USER_NOT_FOUND_BY_EMAIL(HttpStatus.NOT_FOUND, "USER_4042", "EMAIL이 존재하지 않는 회원입니다."),
USER_NOT_FOUND_BY_USERNAME(HttpStatus.NOT_FOUND, "USER_4043", "USERNAME이 존재하지 않는 회원입니다."),
INPUT_NOT_COMPLETED(HttpStatus.BAD_REQUEST, "COMMON_400", "프로필 구성에 필요한 정보들이 제공되지 않았습니다."),

// Login
WRONG_REFRESH_TOKEN(HttpStatus.NOT_FOUND, "JWT_4041", "일치하는 refresh token이 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package hackerthon.likelion13th.canfly.grades.controller;

import hackerthon.likelion13th.canfly.domain.mock.Mock;
import hackerthon.likelion13th.canfly.domain.mock.MockScore;
import hackerthon.likelion13th.canfly.domain.user.User;
import hackerthon.likelion13th.canfly.global.api.ApiResponse;
import hackerthon.likelion13th.canfly.global.api.SuccessCode;
import hackerthon.likelion13th.canfly.grades.dto.MockCreateRequest;
import hackerthon.likelion13th.canfly.grades.dto.MockCreateResponse;
import hackerthon.likelion13th.canfly.grades.dto.MockRequestDto;
import hackerthon.likelion13th.canfly.grades.dto.MockResponseDto;
import hackerthon.likelion13th.canfly.grades.service.MockService;
import hackerthon.likelion13th.canfly.login.auth.mapper.CustomUserDetails;
Expand All @@ -32,21 +29,26 @@ public class MockController {
private final MockService mockService;
private final UserService userService;


@PostMapping
@Operation(summary = "모의고사 등록", description = "특정 년도, 월에 진행한 특정 학년의 모의고사를 등록하는 메서드입니다.")
// GPT
@PostMapping("/excel")
@Operation(
summary = "모의고사 등록(엑셀 평가)",
description = "엑셀 수식으로 각 과목의 백분위/등급/누적(%)를 계산한 뒤 저장합니다. " +
"규칙: 수학 3택1, (과탐/사탐) 합산 최대 2, 제2외국어 최대 1. " +
"표준점수 과목에서 계산 결과가 (백분위=0, 등급=0, 누적=0)이면 입력 오류로 처리됩니다."
)
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2011", description = "모의고사 등록이 완료되었습니다."),
})
public ApiResponse<MockResponseDto> createMock(
public ApiResponse<MockCreateResponse> createMockByExcel(
@AuthenticationPrincipal CustomUserDetails customUserDetails,
@RequestBody MockRequestDto mockRequestDto) {

@RequestBody MockCreateRequest req
) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
MockResponseDto dto = mockService.createMock(user.getUid(), mockRequestDto);

return ApiResponse.onSuccess(SuccessCode.MOCK_CREATE_SUCCESS, dto);
MockCreateResponse res = mockService.createMockByExcel(user.getUid(), req);

return ApiResponse.onSuccess(SuccessCode.MOCK_CREATE_SUCCESS, res);
}

@GetMapping
Expand All @@ -61,16 +63,16 @@ public ApiResponse<List<MockResponseDto>> getAllMocksOfUser(@AuthenticationPrinc
List<MockResponseDto> allMocks = mockService.getAllMocksByUserId(user.getUid());

return ApiResponse.onSuccess(SuccessCode.MOCK_GET_ALL_SUCCESS, allMocks);

}

@GetMapping("/{mockId}")
@Operation(summary = "특정 모의고사 조회", description = "하나의 모의고사를 조회하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2002", description = "모의고사 조회가 완료되었습니다."),
})
public ApiResponse<MockResponseDto> getMockById(@PathVariable Long mockId) {
MockResponseDto responseDto = mockService.getMockById(mockId);
public ApiResponse<MockResponseDto> getMockById(@PathVariable Long mockId, @AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
MockResponseDto responseDto = mockService.getMockById(mockId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.MOCK_GET_SUCCESS, responseDto);
}

Expand All @@ -79,67 +81,39 @@ public ApiResponse<MockResponseDto> getMockById(@PathVariable Long mockId) {
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mockscore_2003", description = "과목 성적 조회가 완료되었습니다."),
})
public ApiResponse<MockResponseDto.MockScoreResponseDto> getMockScore(@PathVariable Long mockId, @PathVariable Long mockScoreId) {
MockResponseDto.MockScoreResponseDto mockScore = mockService.getMockScoreById(mockId, mockScoreId);
public ApiResponse<MockResponseDto.MockScoreResponseDto> getMockScore(@PathVariable Long mockId,
@PathVariable Long mockScoreId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
MockResponseDto.MockScoreResponseDto mockScore = mockService.getMockScoreById(mockId, mockScoreId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_GET_SUCCESS, mockScore);
}

// 뭔가 만들면서 이상해져서 수정할 건데, 일단 이걸로 POST+DELETE를 해야 함
// @Operation(summary = "모의고사 성적 수정", description = "특정 모의고사의 성적을 수정하는 메서드입니다.")
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2013", description = "특정 모의고사 정보 수정이 완료되었습니다."),
// })
// public ApiResponse<MockResponseDto> updateMockScore(@AuthenticationPrincipal CustomUserDetails userDetails, @PathVariable Long mockId, @RequestBody MockRequestDto mockRequestDto) {
// User user = userService.findUserByProviderId(userDetails.getUsername());
// Mock updatedMock = new Mock();
// if (mockRequestDto.getScoreLists() != null && !mockRequestDto.getScoreLists().isEmpty()) {
// List<MockRequestDto.MockScoreRequestDto> newScores = mockRequestDto.getScoreLists();
// for (MockRequestDto.MockScoreRequestDto scoreDto : newScores) {
// MockScore mockScore = MockScore.builder()
// .standardScore(scoreDto.getStandardScore())
// .percentile(scoreDto.getPercentile())
// .grade(scoreDto.getGrade())
// .cumulative(scoreDto.getCumulative())
// .category(scoreDto.getCategory())
// .name(scoreDto.getName())
// .build();
// updatedMock.addMockScore(mockScore);
// }
// }
// MockResponseDto responseDto = new MockResponseDto(updatedMock);
// return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_PUT_SUCCESS, responseDto);
// }


@DeleteMapping("/{mockId}")
@Operation(summary = "모의고사 삭제", description = "특정 모의고사를 삭제하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2004", description = "모의고사 삭제가 완료되었습니다."),
})
public ApiResponse<Boolean> deleteMock(@PathVariable Long mockId) {
mockService.deleteMock(mockId);
public ApiResponse<Boolean> deleteMock(@PathVariable Long mockId, @AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
mockService.deleteMock(mockId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.MOCK_DELETE_SUCCESS, true);
}

// GPT
@PostMapping("/excel")
@Operation(
summary = "모의고사 등록(엑셀 평가)",
description = "엑셀 수식으로 각 과목의 백분위/등급/누적(%)를 계산한 뒤 저장합니다. " +
"규칙: 수학 3택1, (과탐/사탐) 합산 최대 2, 제2외국어 최대 1. " +
"표준점수 과목에서 계산 결과가 (백분위=0, 등급=0, 누적=0)이면 입력 오류로 처리됩니다."
)
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2011", description = "모의고사 등록이 완료되었습니다."),
})
public ApiResponse<MockCreateResponse> createMockByExcel(
@AuthenticationPrincipal CustomUserDetails customUserDetails,
@RequestBody MockCreateRequest req
) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());

MockCreateResponse res = mockService.createMockByExcel(user.getUid(), req);

return ApiResponse.onSuccess(SuccessCode.MOCK_CREATE_SUCCESS, res);
}
// @PostMapping
// @Operation(summary = "모의고사 등록", description = "특정 년도, 월에 진행한 특정 학년의 모의고사를 등록하는 메서드입니다.")
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2011", description = "모의고사 등록이 완료되었습니다."),
// })
// public ApiResponse<MockResponseDto> createMock(
// @AuthenticationPrincipal CustomUserDetails customUserDetails,
// @RequestBody MockRequestDto mockRequestDto) {
//
// User user = userService.findUserByProviderId(customUserDetails.getUsername());
// MockResponseDto dto = mockService.createMock(user.getUid(), mockRequestDto);
//
// return ApiResponse.onSuccess(SuccessCode.MOCK_CREATE_SUCCESS, dto);
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,11 @@ public ApiResponse<ReportResponseDto> createReport(
@AuthenticationPrincipal CustomUserDetails customUserDetails,
@RequestBody ReportRequestDto reportRequestDto) {


User user = userService.findUserByProviderId(customUserDetails.getUsername());

ReportResponseDto responseDto = reportService.createReport(user.getUid(), reportRequestDto);
return ApiResponse.onSuccess(SuccessCode.REPORT_CREATE_SUCCESS, responseDto);
}

// @PostMapping("/{reportId}")
// @Operation(summary = "내신 점수 등록", description = "어떤 내신의 특정 과목 성적을 입력하는 메서드입니다..")
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2012", description = "내신 성적 등록이 완료되었습니다."),
// })
// public ApiResponse<ReportResponseDto> createReportScoreLists(
// @PathVariable Long reportId,
// @RequestBody ReportRequestDto.ReportScoreRequestDto reportScoreRequestDto
// ) {
//
// ReportResponseDto responseDto = reportService.addReportScoreToReport(reportId, reportScoreRequestDto);
// return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_CREATE_SUCCESS, responseDto);
// }

@GetMapping
@Operation(summary = "전체 내신 조회", description = "사용자가 진행했던 모든 내신를 조회하는 메서드입니다.")
@ApiResponses({
Expand All @@ -74,8 +58,10 @@ public ApiResponse<List<ReportResponseDto>> getAllReportsOfUser(@AuthenticationP
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2002", description = "내신 조회가 완료되었습니다."),
})
public ApiResponse<ReportResponseDto> getReportById(@PathVariable Long reportId) {
ReportResponseDto responseDto = reportService.getReportById(reportId);
public ApiResponse<ReportResponseDto> getReportById(@PathVariable Long reportId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
ReportResponseDto responseDto = reportService.getReportById(reportId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.REPORT_GET_SUCCESS, responseDto);
}

Expand All @@ -84,40 +70,57 @@ public ApiResponse<ReportResponseDto> getReportById(@PathVariable Long reportId)
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2003", description = "과목 성적 조회가 완료되었습니다."),
})
public ApiResponse<ReportResponseDto.ReportScoreResponseDto> getReportScore(@PathVariable Long reportId, @PathVariable Long reportScoreId) {
ReportResponseDto.ReportScoreResponseDto reportScore = reportService.getReportScoreById(reportId, reportScoreId);
public ApiResponse<ReportResponseDto.ReportScoreResponseDto> getReportScore(@PathVariable Long reportId,
@PathVariable Long reportScoreId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
ReportResponseDto.ReportScoreResponseDto reportScore = reportService.getReportScoreById(reportId, reportScoreId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_GET_SUCCESS, reportScore);
}

@PutMapping("/{reportId}")
@Operation(summary = "내신 정보 수정", description = "특정 내신의 정보를 수정하는 메서드입니다.") //※ 규칙: 여기에서 절대로 CategoryName은 건들면 안됨
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2013", description = "특정 내신 정보 수정이 완료되었습니다."),
})
public ApiResponse<ReportResponseDto> updateReport(@PathVariable Long reportId, @RequestBody ReportRequestDto reportRequestDto) {
ReportResponseDto responseDto = reportService.updateReport(reportId, reportRequestDto);
return ApiResponse.onSuccess(SuccessCode.REPORT_PUT_SUCCESS, responseDto);
}

@PutMapping("/{reportId}/{reportScoreId}")
@Operation(summary = "내신 성적 수정", description = "특정 내신의 성적을 수정하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2014", description = "내신 성적 수정이 완료되었습니다."),
})
public ApiResponse<ReportResponseDto.ReportScoreResponseDto> updateReportScore(@PathVariable Long reportId, @PathVariable Long reportScoreId, @RequestBody ReportRequestDto.ReportScoreRequestDto reportScoreRequestDto) {
ReportResponseDto.ReportScoreResponseDto responseDto = reportService.updateReportScore(reportScoreId, reportScoreRequestDto);
return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_PUT_SUCCESS, responseDto);
}


@DeleteMapping("/{reportId}")
@Operation(summary = "내신 삭제", description = "특정 내신를 삭제하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2004", description = "내신 삭제가 완료되었습니다."),
})
public ApiResponse<Boolean> deleteReport(@PathVariable Long reportId) {
reportService.deleteReport(reportId);
public ApiResponse<Boolean> deleteReport(@PathVariable Long reportId, @AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByProviderId(customUserDetails.getUsername());
reportService.deleteReport(reportId, user.getUid());
return ApiResponse.onSuccess(SuccessCode.REPORT_DELETE_SUCCESS, true);
}

// @PostMapping("/{reportId}")
// @Operation(summary = "내신 점수 등록", description = "어떤 내신의 특정 과목 성적을 입력하는 메서드입니다..")
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2012", description = "내신 성적 등록이 완료되었습니다."),
// })
// public ApiResponse<ReportResponseDto> createReportScoreLists(
// @PathVariable Long reportId,
// @RequestBody ReportRequestDto.ReportScoreRequestDto reportScoreRequestDto
// ) {
//
// ReportResponseDto responseDto = reportService.addReportScoreToReport(reportId, reportScoreRequestDto);
// return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_CREATE_SUCCESS, responseDto);
// }

// @PutMapping("/{reportId}")
// @Operation(summary = "내신 정보 수정", description = "특정 내신의 정보를 수정하는 메서드입니다.") //※ 규칙: 여기에서 절대로 CategoryName은 건들면 안됨
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2013", description = "특정 내신 정보 수정이 완료되었습니다."),
// })
// public ApiResponse<ReportResponseDto> updateReport(@PathVariable Long reportId, @RequestBody ReportRequestDto reportRequestDto) {
// ReportResponseDto responseDto = reportService.updateReport(reportId, reportRequestDto);
// return ApiResponse.onSuccess(SuccessCode.REPORT_PUT_SUCCESS, responseDto);
// }
//
// @PutMapping("/{reportId}/{reportScoreId}")
// @Operation(summary = "내신 성적 수정", description = "특정 내신의 성적을 수정하는 메서드입니다.")
// @ApiResponses({
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2014", description = "내신 성적 수정이 완료되었습니다."),
// })
// public ApiResponse<ReportResponseDto.ReportScoreResponseDto> updateReportScore(@PathVariable Long reportId, @PathVariable Long reportScoreId, @RequestBody ReportRequestDto.ReportScoreRequestDto reportScoreRequestDto) {
// ReportResponseDto.ReportScoreResponseDto responseDto = reportService.updateReportScore(reportScoreId, reportScoreRequestDto);
// return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_PUT_SUCCESS, responseDto);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class ReportRequestDto {
private Integer userGrade;
private Integer term;
private Integer categoryName;
private BigDecimal categoryGrade;
private List<ReportScoreRequestDto> scoreLists;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public interface MockRepository extends JpaRepository<Mock, Long> {
Optional<Mock> findByUserUidAndExamYearAndExamMonthAndExamGrade(
String uid, Integer examYear, Integer examMonth, Integer examGrade
);

Optional<Mock> findByIdAndUser_Uid(Long mockId, String userId);

void deleteByIdAndUser_Uid(Long id, String userUid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface ReportRepository extends JpaRepository<Report, Long> {


List<Report> findByUser(User user);

Optional<Report> findByUserAndUserGradeAndTermAndCategoryName(
User user, Integer userGrade, Integer term, Integer categoryName
);

Optional<Report> findByIdAndUser_Uid(Long reportId, String userId);

void deleteByIdAndUser_Uid(Long reportId, String userId);
}
Loading