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 @@ -26,9 +26,6 @@ public class ReportScore extends BaseEntity {
@Column(name = "grade")
private Integer grade; // 등급

@Column(name = "ranking")
private Integer ranking; // 석차

@Column(name = "student_num")
private Integer studentNum; // 수강자 수

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import hackerthon.likelion13th.canfly.grades.dto.MockResponseDto;
import hackerthon.likelion13th.canfly.grades.service.MockService;
import hackerthon.likelion13th.canfly.login.auth.mapper.CustomUserDetails;
import hackerthon.likelion13th.canfly.login.dto.CoinRequestDto;
import hackerthon.likelion13th.canfly.login.dto.CoinResponseDto;
import hackerthon.likelion13th.canfly.login.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -38,27 +40,13 @@ public ApiResponse<MockResponseDto> createMock(
@AuthenticationPrincipal CustomUserDetails customUserDetails,
@RequestBody MockRequestDto mockRequestDto) {

User user = userService.findUserByProviderId(customUserDetails.getProviderId());
User user = userService.findUserByProviderId(customUserDetails.getUsername());
MockResponseDto dto = mockService.createMock(user.getUid(), mockRequestDto);

return ApiResponse.onSuccess(SuccessCode.MOCK_CREATE_SUCCESS, dto);

}

@PostMapping("/{mockId}")
@Operation(summary = "모의고사 점수 등록", description = "어떤 모의고사의 특정 과목 성적을 입력하는 메서드입니다..")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mockscore_2012", description = "모의고사 성적 등록이 완료되었습니다."),
})
public ApiResponse<MockResponseDto> createMockScoreLists(
@PathVariable Long mockId,
@RequestBody MockRequestDto.MockScoreRequestDto mockScoreRequestDto
) {

MockResponseDto responseDto = mockService.addMockScoreToMock(mockId, mockScoreRequestDto);
return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_CREATE_SUCCESS, responseDto);
}

@GetMapping
@Operation(summary = "전체 모의고사 조회", description = "사용자가 진행했던 모든 모의고사를 조회하는 메서드입니다.")
@ApiResponses({
Expand Down Expand Up @@ -94,26 +82,30 @@ public ApiResponse<MockResponseDto.MockScoreResponseDto> getMockScore(@PathVaria
return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_GET_SUCCESS, mockScore);
}

@PutMapping("/{mockId}")
@PatchMapping("/{mockId}")
@Operation(summary = "모의고사 정보 수정", description = "특정 모의고사의 정보를 수정하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2013", description = "특정 모의고사 정보 수정이 완료되었습니다."),
})
public ApiResponse<MockResponseDto> updateMock(@PathVariable Long mockId, @RequestBody MockRequestDto mockRequestDto) {

MockResponseDto responseDto = mockService.updateMock(mockId, mockRequestDto);
return ApiResponse.onSuccess(SuccessCode.MOCK_PUT_SUCCESS, responseDto);
}

@PutMapping("/{mockId}/{mockScoreId}")
@Operation(summary = "모의고사 성적 수정", description = "특정 모의고사의 성적을 수정하는 메서드입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mockscore_2014", description = "모의고사 성적 수정이 완료되었습니다."),
})
public ApiResponse<MockResponseDto.MockScoreResponseDto> updateMockScore(@PathVariable Long mockId, @PathVariable Long mockScoreId, @RequestBody MockRequestDto.MockScoreRequestDto mockScoreRequestDto) {
MockResponseDto.MockScoreResponseDto responseDto = mockService.updateMockScore(mockId, mockScoreRequestDto);
return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_PUT_SUCCESS, responseDto);
}

// @Operation(summary = "토큰 사용 및 충전", description = "amount가 0이면 토큰 1개 사용, 0보다 크면 해당 양만큼 충전합니다.")
// @PatchMapping("/token")
// public ApiResponse<CoinResponseDto> updateUserCoins(
// @AuthenticationPrincipal CustomUserDetails userDetails, // 또는 Authentication auth 객체
// @RequestBody CoinRequestDto coinRequestDto) {
// int amount = coinRequestDto.getAmount(); //내가 볼 때 그냥 token을 다른 테이블에 추가시키는 게 나음 ㅅ;ㅂ 이거 너무 많아 정보가
// String username = userDetails.getUsername();
// User updatedUser = userService.processCoins(username, amount);
// CoinResponseDto responseDTO = CoinResponseDto.fromEntity(updatedUser);
//
// // 3. 최종적으로 변환된 DTO를 클라이언트에게 전달합니다.
// return ApiResponse.onSuccess(SuccessCode.TOKEN_PROCESS_SUCCESS, responseDTO);
// }

@DeleteMapping("/{mockId}")
@Operation(summary = "모의고사 삭제", description = "특정 모의고사를 삭제하는 메서드입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ApiResponse<ReportResponseDto> createReport(
@RequestBody ReportRequestDto reportRequestDto) {


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

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

Expand All @@ -64,8 +64,8 @@ public ApiResponse<ReportResponseDto> createReportScoreLists(
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2001", description = "전체 내신 조회가 완료되었습니다."),
})
public ApiResponse<List<ReportResponseDto>> getAllReportsOfUser(@AuthenticationPrincipal CustomUserDetails customUserDetails) {
User user = userService.findUserByUserName(customUserDetails.getUsername());
List<ReportResponseDto> allReports = reportService.getAllReportsByUserName(user.getName());
User user = userService.findUserByProviderId(customUserDetails.getUsername());
List<ReportResponseDto> allReports = reportService.getAllReportsByUserId(user.getUid());
return ApiResponse.onSuccess(SuccessCode.REPORT_GET_ALL_SUCCESS, allReports);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class ReportRequestDto {
public static class ReportScoreRequestDto {
private String subject;
private Integer grade;
private Integer ranking;
private Integer studentNum;
private BigDecimal standardDeviation;
private Integer subjectAverage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static class ReportScoreResponseDto {
private Long scoreId;
private String subject;
private Integer grade;
private Integer ranking;
private Integer studentNum;
private BigDecimal standardDeviation;
private Integer subjectAverage;
Expand All @@ -54,7 +53,6 @@ public ReportScoreResponseDto(ReportScore reportScore) {
this.scoreId = reportScore.getId();
this.subject = reportScore.getSubject();
this.grade = reportScore.getGrade();
this.ranking = reportScore.getRanking();
this.studentNum = reportScore.getStudentNum();
this.standardDeviation = reportScore.getStandardDeviation();
this.subjectAverage = reportScore.getSubjectAverage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class MockService {


@Transactional
public MockResponseDto createMock(String userName, MockRequestDto mockRequestDto) {
User user = userRepository.findByName(userName)
public MockResponseDto createMock(String userId, MockRequestDto mockRequestDto) {
User user = userRepository.findByUid(userId)
.orElseThrow(() -> GeneralException.of(ErrorCode.USER_NOT_FOUND));

Mock newMock = Mock.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class ReportService {
private final UserRepository userRepository;

@Transactional
public ReportResponseDto createReport(String userName, ReportRequestDto reportRequestDto) {
User user = userRepository.findByName(userName)
.orElseThrow(() -> new IllegalArgumentException("User not found with name: " + userName));
public ReportResponseDto createReport(String userId, ReportRequestDto reportRequestDto) {
User user = userRepository.findByUid(userId)
.orElseThrow(() -> new IllegalArgumentException("User not found with name: " + userId));

Report newReport = Report.builder()
.categoryName(reportRequestDto.getCategoryName())
Expand All @@ -49,7 +49,6 @@ public ReportResponseDto createReport(String userName, ReportRequestDto reportRe
.subject(scoreDto.getSubject())
.grade(scoreDto.getGrade())
.achievement(scoreDto.getAchievement())
.ranking(scoreDto.getRanking())
.studentNum(scoreDto.getStudentNum())
.standardDeviation(scoreDto.getStandardDeviation())
.subjectAverage(scoreDto.getSubjectAverage())
Expand All @@ -76,7 +75,6 @@ public ReportResponseDto addReportScoreToReport(Long reportId, ReportRequestDto.
.subject(scoreRequestDto.getSubject())
.grade(scoreRequestDto.getGrade())
.achievement(scoreRequestDto.getAchievement())
.ranking(scoreRequestDto.getRanking())
.studentNum(scoreRequestDto.getStudentNum())
.standardDeviation(scoreRequestDto.getStandardDeviation())
.subjectAverage(scoreRequestDto.getSubjectAverage())
Expand Down Expand Up @@ -162,7 +160,6 @@ public ReportResponseDto.ReportScoreResponseDto updateReportScore(Long reportSco
existingReportScore.setSubject(scoreRequestDto.getSubject());
existingReportScore.setGrade(scoreRequestDto.getGrade());
existingReportScore.setAchievement(scoreRequestDto.getAchievement());
existingReportScore.setRanking(scoreRequestDto.getRanking());
existingReportScore.setStudentNum(scoreRequestDto.getStudentNum());
existingReportScore.setStandardDeviation(scoreRequestDto.getStandardDeviation());
existingReportScore.setSubjectAverage(scoreRequestDto.getSubjectAverage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public ApiResponse<Integer> deleteUser(Authentication auth) {
public ApiResponse<CoinResponseDto> updateUserCoins(
@AuthenticationPrincipal CustomUserDetails userDetails, // 또는 Authentication auth 객체
@RequestBody CoinRequestDto coinRequestDto) {
int amount = coinRequestDto.getAmount(); //내가 볼 때 그냥 token을 다른 테이블에 추가시키는 게 나음 ㅅ;ㅂ 이거 너무 많아 정보가
String username = userDetails.getUsername();
User updatedUser = userService.processCoins(username, amount);
int amount = coinRequestDto.getAmount();
String userPId = userDetails.getUsername();
User updatedUser = userService.processCoins(userPId, amount);
CoinResponseDto responseDTO = CoinResponseDto.fromEntity(updatedUser);

// 3. 최종적으로 변환된 DTO를 클라이언트에게 전달합니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public User findUserByUserName(String nickName) {
}

@Transactional
public User processCoins(String userId, int amount) {
User user = userRepository.findByUid(userId)
.orElseThrow(() -> new GeneralException(ErrorCode.USER_NOT_FOUND));
public User processCoins(String userPId, int amount) {
User user = findUserByProviderId(userPId);
if (amount < 0) {
throw new IllegalArgumentException("amount는 0 이상이어야 합니다.");
}
Expand Down