diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/entity/CategoryName.java b/src/main/java/hackerthon/likelion13th/canfly/domain/entity/CategoryName.java deleted file mode 100644 index 1da3103..0000000 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/entity/CategoryName.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackerthon.likelion13th.canfly.domain.entity; - -public enum CategoryName { - KOREAN, - MATH, - ENGLISH, - KHISTORY, - SOCIAL, - SCIENCE, -} diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/field/FieldBookmark.java b/src/main/java/hackerthon/likelion13th/canfly/domain/field/FieldBookmark.java index b285c5c..da94d3f 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/field/FieldBookmark.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/field/FieldBookmark.java @@ -20,9 +20,6 @@ public class FieldBookmark extends BaseEntity { @Column(name = "fbId", nullable = false) private Integer id; - @Column(name = "fieldRecommend") - private Boolean isRecommend = false; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "fId", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/major/MajorBookmark.java b/src/main/java/hackerthon/likelion13th/canfly/domain/major/MajorBookmark.java index fd05ad5..f2b2525 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/major/MajorBookmark.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/major/MajorBookmark.java @@ -21,9 +21,6 @@ public class MajorBookmark extends BaseEntity { @Column(name = "mbId", nullable = false) private Integer id; - @Column(name = "majorRecommend") - private Boolean isRecommend = false; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "mId", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/mock/Mock.java b/src/main/java/hackerthon/likelion13th/canfly/domain/mock/Mock.java index 1dcaaf1..b521aa0 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/mock/Mock.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/mock/Mock.java @@ -34,7 +34,6 @@ public class Mock extends BaseEntity { /** 과목별 점수 리스트 */ @OneToMany(mappedBy = "mock", cascade = CascadeType.ALL, orphanRemoval = true) - @Column(name = "mock_score", nullable = true) @Builder.Default private List scoreLists = new ArrayList<>(); public void addMockScore(MockScore mockScore) { diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/mock/MockScore.java b/src/main/java/hackerthon/likelion13th/canfly/domain/mock/MockScore.java index 4f8e511..1301704 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/mock/MockScore.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/mock/MockScore.java @@ -6,9 +6,10 @@ import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; + import java.math.BigDecimal; -import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.FetchType.EAGER; @Entity @Table(name = "mockScore") @@ -32,7 +33,7 @@ public class MockScore extends BaseEntity { private Integer percentile; /** 등급 */ - @Column(name = "grade", nullable = false) + @Column(name = "grade") private Integer grade; /** 누적 백분위(%) */ @@ -47,7 +48,7 @@ public class MockScore extends BaseEntity { @Column(name = "name") private String name; - @ManyToOne(fetch = LAZY, optional = false) + @ManyToOne(fetch = EAGER, optional = false) @JoinColumn(name = "mockId", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) private Mock mock; diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/report/Report.java b/src/main/java/hackerthon/likelion13th/canfly/domain/report/Report.java index 987656b..e9d00cc 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/report/Report.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/report/Report.java @@ -2,8 +2,6 @@ import hackerthon.likelion13th.canfly.domain.entity.BaseEntity; import hackerthon.likelion13th.canfly.domain.user.User; -import hackerthon.likelion13th.canfly.domain.entity.CategoryName; -import hackerthon.likelion13th.canfly.grades.dto.ReportResponseDto; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.OnDelete; @@ -34,8 +32,7 @@ public class Report extends BaseEntity { /** 과목 카테고리명 (국어/수학) */ @Column(name = "category_name", nullable = false) - @Enumerated(EnumType.STRING) - private CategoryName categoryName; + private Integer categoryName; /** 카테고리 평균 성적(예: 3.75) */ @Column(name = "category_grade", precision = 5, scale = 2) diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/report/ReportScore.java b/src/main/java/hackerthon/likelion13th/canfly/domain/report/ReportScore.java index 5cfc199..e6fa377 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/report/ReportScore.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/report/ReportScore.java @@ -5,6 +5,7 @@ import lombok.*; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; + import java.math.BigDecimal; @Entity diff --git a/src/main/java/hackerthon/likelion13th/canfly/domain/user/User.java b/src/main/java/hackerthon/likelion13th/canfly/domain/user/User.java index 699d451..6962a3a 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/domain/user/User.java +++ b/src/main/java/hackerthon/likelion13th/canfly/domain/user/User.java @@ -35,9 +35,6 @@ public class User extends BaseEntity { @Column(name = "email", length = 50) private String email; - @Column(name = "phoneNumber", length = 20) - private String phoneNumber; - @Enumerated(EnumType.STRING) @Column(name = "sex") private Sex sex; diff --git a/src/main/java/hackerthon/likelion13th/canfly/global/api/SuccessCode.java b/src/main/java/hackerthon/likelion13th/canfly/global/api/SuccessCode.java index 1b3bb5f..9b29899 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/global/api/SuccessCode.java +++ b/src/main/java/hackerthon/likelion13th/canfly/global/api/SuccessCode.java @@ -15,6 +15,7 @@ public enum SuccessCode implements BaseCode { // 성공 USER_REISSUE_SUCCESS(HttpStatus.OK, "USER_2002", "토큰 재발급이 완료되었습니다."), USER_DELETE_SUCCESS(HttpStatus.OK, "USER_2003", "회원탈퇴가 완료되었습니다."), USER_PROFILE_UPDATE_SUCCESS(HttpStatus.OK, "USER_2006", "프로필 저장이 완료되었습니다."), + USER_INFO_GET_SUCCESS(HttpStatus.OK, "USER_2007", "유저 정보 조회가 완료되었습니다."), MOCK_CREATE_SUCCESS(HttpStatus.CREATED, "MOCK_2011", "모의고사 등록이 완료되었습니다."), MOCKSCORE_CREATE_SUCCESS(HttpStatus.CREATED, "MOCKSCORE_2011", "모의고사 성적 등록이 완료되었습니다."), diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/controller/MockController.java b/src/main/java/hackerthon/likelion13th/canfly/grades/controller/MockController.java index 8e95361..d6c5c7b 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/controller/MockController.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/controller/MockController.java @@ -1,5 +1,7 @@ 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; @@ -9,8 +11,6 @@ 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; @@ -84,31 +84,33 @@ public ApiResponse getMockScore(@PathVaria return ApiResponse.onSuccess(SuccessCode.MOCKSCORE_GET_SUCCESS, mockScore); } - @PatchMapping("/{mockId}") - @Operation(summary = "모의고사 정보 수정", description = "특정 모의고사의 정보를 수정하는 메서드입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2013", description = "특정 모의고사 정보 수정이 완료되었습니다."), - }) - public ApiResponse updateMock(@PathVariable Long mockId, @RequestBody MockRequestDto mockRequestDto) { - - MockResponseDto responseDto = mockService.updateMock(mockId, mockRequestDto); - return ApiResponse.onSuccess(SuccessCode.MOCK_PUT_SUCCESS, responseDto); - } - -// @Operation(summary = "토큰 사용 및 충전", description = "amount가 0이면 토큰 1개 사용, 0보다 크면 해당 양만큼 충전합니다.") -// @PatchMapping("/token") -// public ApiResponse 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); +// 뭔가 만들면서 이상해져서 수정할 건데, 일단 이걸로 POST+DELETE를 해야 함 +// @Operation(summary = "모의고사 성적 수정", description = "특정 모의고사의 성적을 수정하는 메서드입니다.") +// @ApiResponses({ +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Mock_2013", description = "특정 모의고사 정보 수정이 완료되었습니다."), +// }) +// public ApiResponse 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 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({ diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/controller/ReportController.java b/src/main/java/hackerthon/likelion13th/canfly/grades/controller/ReportController.java index 91001a9..a807e8e 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/controller/ReportController.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/controller/ReportController.java @@ -44,19 +44,19 @@ public ApiResponse createReport( 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 createReportScoreLists( - @PathVariable Long reportId, - @RequestBody ReportRequestDto.ReportScoreRequestDto reportScoreRequestDto - ) { - - ReportResponseDto responseDto = reportService.addReportScoreToReport(reportId, reportScoreRequestDto); - return ApiResponse.onSuccess(SuccessCode.REPORTSCORE_CREATE_SUCCESS, responseDto); - } +// @PostMapping("/{reportId}") +// @Operation(summary = "내신 점수 등록", description = "어떤 내신의 특정 과목 성적을 입력하는 메서드입니다..") +// @ApiResponses({ +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "Report_2012", description = "내신 성적 등록이 완료되었습니다."), +// }) +// public ApiResponse 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 = "사용자가 진행했던 모든 내신를 조회하는 메서드입니다.") diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/MockRequestDto.java b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/MockRequestDto.java index 7427532..209a8b6 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/MockRequestDto.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/MockRequestDto.java @@ -1,7 +1,7 @@ package hackerthon.likelion13th.canfly.grades.dto; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; + import java.math.BigDecimal; import java.util.List; diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportRequestDto.java b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportRequestDto.java index 7f75d7b..5824cd9 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportRequestDto.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportRequestDto.java @@ -1,6 +1,5 @@ package hackerthon.likelion13th.canfly.grades.dto; -import hackerthon.likelion13th.canfly.domain.entity.CategoryName; import lombok.*; import java.math.BigDecimal; @@ -14,7 +13,7 @@ public class ReportRequestDto { private Integer userGrade; private Integer term; - private CategoryName categoryName; + private Integer categoryName; private BigDecimal categoryGrade; private List scoreLists; diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportResponseDto.java b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportResponseDto.java index 06dac82..320e0ae 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportResponseDto.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/dto/ReportResponseDto.java @@ -1,6 +1,5 @@ package hackerthon.likelion13th.canfly.grades.dto; -import hackerthon.likelion13th.canfly.domain.entity.CategoryName; import hackerthon.likelion13th.canfly.domain.report.Report; import hackerthon.likelion13th.canfly.domain.report.ReportScore; import lombok.*; @@ -19,7 +18,7 @@ public class ReportResponseDto { private Long id; private Integer userGrade; private Integer term; - private CategoryName categoryName; + private Integer categoryName; private BigDecimal categoryGrade; private List scoreList = new ArrayList<>(); diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/service/MockService.java b/src/main/java/hackerthon/likelion13th/canfly/grades/service/MockService.java index 65b8fe6..ceb7f2d 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/service/MockService.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/service/MockService.java @@ -71,25 +71,25 @@ public MockResponseDto createMock(String userId, MockRequestDto mockRequestDto) return new MockResponseDto(newMock); } - - @Transactional - public MockResponseDto addMockScoreToMock(Long mockId, MockRequestDto.MockScoreRequestDto scoreRequestDto) { - Mock mock = mockRepository.findById(mockId) - .orElseThrow(() -> new IllegalArgumentException("Mock not found with id: " + mockId)); - - // DTO 필드에서 MockScore 엔티티 직접 생성 - MockScore newMockScore = MockScore.builder() - .standardScore(scoreRequestDto.getStandardScore()) - .percentile(scoreRequestDto.getPercentile()) - .grade(scoreRequestDto.getGrade()) - .cumulative(scoreRequestDto.getCumulative()) - .category(scoreRequestDto.getCategory()) - .name(scoreRequestDto.getName()) - .build(); - mock.addMockScore(newMockScore); // Mock 엔티티에 MockScore 추가 (양방향 관계 설정) - mockScoreRepository.save(newMockScore); - return new MockResponseDto(mock); - } +// 사용하지 않는 관계로 주석 처리 +// @Transactional +// public MockResponseDto addMockScoreToMock(Long mockId, MockRequestDto.MockScoreRequestDto scoreRequestDto) { +// Mock mock = mockRepository.findById(mockId) +// .orElseThrow(() -> new IllegalArgumentException("Mock not found with id: " + mockId)); +// +// // DTO 필드에서 MockScore 엔티티 직접 생성 +// MockScore newMockScore = MockScore.builder() +// .standardScore(scoreRequestDto.getStandardScore()) +// .percentile(scoreRequestDto.getPercentile()) +// .grade(scoreRequestDto.getGrade()) +// .cumulative(scoreRequestDto.getCumulative()) +// .category(scoreRequestDto.getCategory()) +// .name(scoreRequestDto.getName()) +// .build(); +// mock.addMockScore(newMockScore); // Mock 엔티티에 MockScore 추가 (양방향 관계 설정) +// mockScoreRepository.save(newMockScore); +// return new MockResponseDto(mock); +// } @Transactional(readOnly = true) public MockResponseDto getMockById(Long mockId) { @@ -124,17 +124,6 @@ public MockResponseDto.MockScoreResponseDto getMockScoreById(Long mockId, Long s return new MockResponseDto.MockScoreResponseDto(mockScore); } - @Transactional - public MockResponseDto updateMock(Long mockId, MockRequestDto mockRequestDto) { - Mock existingMock = mockRepository.findById(mockId) - .orElseThrow(() -> new IllegalArgumentException("Mock not found with id: " + mockId)); - existingMock.setExamYear(mockRequestDto.getExamYear()); - existingMock.setExamMonth(mockRequestDto.getExamMonth()); - existingMock.setExamGrade(mockRequestDto.getExamGrade()); - Mock updatedMock = mockRepository.save(existingMock); - return convertToDto(updatedMock); - } - @Transactional public MockResponseDto.MockScoreResponseDto updateMockScore(Long mockScoreId, MockRequestDto.MockScoreRequestDto scoreRequestDto) { MockScore existingMockScore = mockScoreRepository.findById(mockScoreId) @@ -149,6 +138,22 @@ public MockResponseDto.MockScoreResponseDto updateMockScore(Long mockScoreId, Mo return convertToDto(updatedMockScore); } +// if (mockRequestDto.getScoreLists() != null && !mockRequestDto.getScoreLists().isEmpty()) { +// for (MockRequestDto.MockScoreRequestDto scoreDto : mockRequestDto.getScoreLists()) { +// MockScore mockScore = MockScore.builder() +// .standardScore(scoreDto.getStandardScore()) +// .percentile(scoreDto.getPercentile()) +// .grade(scoreDto.getGrade()) +// .cumulative(scoreDto.getCumulative()) +// .category(scoreDto.getCategory()) +// .name(scoreDto.getName()) +// .build(); +// newMock.addMockScore(mockScore); +// } +// } +// user.addMock(newMock); +// mockRepository.save(newMock); + @Transactional public void deleteMock(Long mockId) { mockRepository.deleteById(mockId); diff --git a/src/main/java/hackerthon/likelion13th/canfly/grades/service/ReportService.java b/src/main/java/hackerthon/likelion13th/canfly/grades/service/ReportService.java index 6bf7abd..d5c98f9 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/grades/service/ReportService.java +++ b/src/main/java/hackerthon/likelion13th/canfly/grades/service/ReportService.java @@ -147,8 +147,6 @@ public ReportResponseDto updateReport(Long reportId, ReportRequestDto reportRequ Report existingReport = reportRepository.findById(reportId) .orElseThrow(() -> new IllegalArgumentException("Report not found with id: " + reportId)); existingReport.setCategoryName(reportRequestDto.getCategoryName()); - existingReport.setTerm(reportRequestDto.getTerm()); - existingReport.setUserGrade(reportRequestDto.getUserGrade()); Report updatedReport = reportRepository.save(existingReport); return convertToDto(updatedReport); } diff --git a/src/main/java/hackerthon/likelion13th/canfly/login/controller/UserController.java b/src/main/java/hackerthon/likelion13th/canfly/login/controller/UserController.java index 1f00a00..e9241a4 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/login/controller/UserController.java +++ b/src/main/java/hackerthon/likelion13th/canfly/login/controller/UserController.java @@ -5,9 +5,7 @@ import hackerthon.likelion13th.canfly.global.api.SuccessCode; import hackerthon.likelion13th.canfly.login.auth.dto.JwtDto; 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.dto.ProfileRequestDto; +import hackerthon.likelion13th.canfly.login.dto.*; import hackerthon.likelion13th.canfly.login.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -88,6 +86,47 @@ public ApiResponse completeProfile( return ApiResponse.onSuccess(SuccessCode.USER_PROFILE_UPDATE_SUCCESS, updated); } + @Operation(summary = "유저 전체 정보", description = "유저의 모든 정보(auth 제외)를 GET합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse( + responseCode = "USER_2007", description = "전체 정보 조회 완료") + }) + @GetMapping("/info") + public ApiResponse getAllUserInfo( + @AuthenticationPrincipal CustomUserDetails principal + ) { + String providerId = principal.getUsername(); + UserResponseDto allInfo = userService.getAllInfo(providerId); + return ApiResponse.onSuccess(SuccessCode.USER_INFO_GET_SUCCESS, allInfo); + } + + @Operation(summary = "유저 메인페이지 정보", description = "메인페이지에서 표시할 유저의 정보를 GET합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse( + responseCode = "USER_2008", description = "메인페이지 정보 조회 완료") + }) + @GetMapping("/info/mainpage") + public ApiResponse getMainPageInfo( + @AuthenticationPrincipal CustomUserDetails principal + ) { + String providerId = principal.getUsername(); + UserResponseDto basicInfo = userService.getBasicInfo(providerId); + return ApiResponse.onSuccess(SuccessCode.USER_INFO_GET_SUCCESS, basicInfo); + } + + @Operation(summary = "유저 마이페이지 정보", description = "마이페이지에서 표시할 유저의 정보를 GET합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse( + responseCode = "USER_2009", description = "마이페이지 정보 조회 완료") + }) + @GetMapping("/info/mypage") + public ApiResponse getMyPageInfo( + @AuthenticationPrincipal CustomUserDetails principal + ) { + String providerId = principal.getUsername(); + UserResponseDto myPageInfo = userService.getMypageInfo(providerId); + return ApiResponse.onSuccess(SuccessCode.USER_INFO_GET_SUCCESS, myPageInfo); + } /* @Operation(summary = "프로필 사진 첨부", description = "프로필 사진을 첨부하는 메서드입니다.") @ApiResponses(value = { diff --git a/src/main/java/hackerthon/likelion13th/canfly/login/dto/ProfileRequestDto.java b/src/main/java/hackerthon/likelion13th/canfly/login/dto/ProfileRequestDto.java index a64b137..f5a1937 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/login/dto/ProfileRequestDto.java +++ b/src/main/java/hackerthon/likelion13th/canfly/login/dto/ProfileRequestDto.java @@ -11,12 +11,6 @@ @AllArgsConstructor @NoArgsConstructor public class ProfileRequestDto { - @Schema(description = "전화번호") - @Pattern( - regexp = "^[0-9\\-]{9,15}$", - message = "전화번호 형식이 올바르지 않습니다." - ) - private String phoneNumber; @Schema(description = "성별") private Sex sex; diff --git a/src/main/java/hackerthon/likelion13th/canfly/login/dto/UserResponseDto.java b/src/main/java/hackerthon/likelion13th/canfly/login/dto/UserResponseDto.java index 1a77d6a..f967e8f 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/login/dto/UserResponseDto.java +++ b/src/main/java/hackerthon/likelion13th/canfly/login/dto/UserResponseDto.java @@ -1,4 +1,29 @@ package hackerthon.likelion13th.canfly.login.dto; +import hackerthon.likelion13th.canfly.domain.entity.Sex; +import hackerthon.likelion13th.canfly.domain.user.Address; +import hackerthon.likelion13th.canfly.domain.user.User; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor public class UserResponseDto { + private String name; + private String email; + private Sex sex; + private String highschool; + private Byte gradeNum; + private int token; + private Address address; + + public UserResponseDto(User user) { + this.name = user.getName(); + this.email = user.getEmail(); + this.sex = user.getSex(); + this.highschool = user.getHighschool(); + this.gradeNum = user.getGradeNum(); + this.token = user.getToken(); + this.address = user.getAddress(); + } } diff --git a/src/main/java/hackerthon/likelion13th/canfly/login/service/UserService.java b/src/main/java/hackerthon/likelion13th/canfly/login/service/UserService.java index cbacdb7..f5b6c05 100644 --- a/src/main/java/hackerthon/likelion13th/canfly/login/service/UserService.java +++ b/src/main/java/hackerthon/likelion13th/canfly/login/service/UserService.java @@ -11,6 +11,7 @@ import hackerthon.likelion13th.canfly.login.converter.UserConverter; import hackerthon.likelion13th.canfly.login.dto.ProfileRequestDto; import hackerthon.likelion13th.canfly.login.dto.UserRequestDto; +import hackerthon.likelion13th.canfly.login.dto.UserResponseDto; import hackerthon.likelion13th.canfly.login.repository.OAuthRepository; import hackerthon.likelion13th.canfly.login.repository.UserRepository; import jakarta.servlet.http.HttpServletRequest; @@ -20,6 +21,8 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Service; +import java.util.Optional; + @Slf4j @Service @RequiredArgsConstructor @@ -132,20 +135,19 @@ public boolean needsProfile(String providerId) { User user = findUserByProviderId(providerId); boolean missingSex = (user.getSex() == null); - boolean missingPhone = (user.getPhoneNumber() == null || user.getPhoneNumber().isBlank()); + boolean missingGradeNum = (user.getGradeNum() == null); boolean missingHighschool = (user.getHighschool() == null || user.getHighschool().isBlank()); Address addr = user.getAddress(); boolean missingAddress = (addr == null) || addr.isEmpty(); - return missingSex || missingPhone || missingHighschool || missingAddress; + return missingSex || missingGradeNum || missingHighschool || missingAddress; } @Transactional public boolean completeProfile(String providerId, ProfileRequestDto req) { User user = findUserByProviderId(providerId); - user.setPhoneNumber(req.getPhoneNumber()); user.setSex(req.getSex()); user.setHighschool(req.getHighschool()); user.setGradeNum(req.getGradeNum()); @@ -166,7 +168,7 @@ public boolean completeProfile(String providerId, ProfileRequestDto req) { public String checkMemberByName(String username) { User user = findUserByUserName(username); - if (user.getPhoneNumber() != null) return "wasUser"; + //if (user.getPhoneNumber() != null) return "wasUser"; return "newUser"; } @@ -176,31 +178,63 @@ public User findUserByUserName(String nickName) { .orElseThrow(() -> new GeneralException(ErrorCode.USER_NOT_FOUND_BY_USERNAME)); } + //코인 충전&차감 @Transactional public User processCoins(String userPId, int amount) { User user = findUserByProviderId(userPId); - if (amount < 0) { - throw new IllegalArgumentException("amount는 0 이상이어야 합니다."); - } - if (amount == 0) { - // amount가 0이면 토큰 1개 사용 - return useCoin(user); - } else { - // amount가 0보다 크면 토큰 충전 - return chargeCoin(user, amount); + throw new IllegalArgumentException("amount는 0일 수 없습니다."); } - } - public User useCoin(User user) { - if (user.getToken() <= 0) { - throw new IllegalStateException("코인이 부족하여 사용할 수 없습니다."); + else { + if (user.getToken() + amount < 0) { + throw new IllegalArgumentException("코인이 부족하여 사용할 수 없습니다."); + } else { + return controlCoin(user, amount); + } } - user.setToken(user.getToken() - 1); - return user; } - - public User chargeCoin(User user, int amount) { +// amount의 양/음 여부에 따라 충전 혹은 차감됨 + public User controlCoin(User user, int amount) { user.setToken(user.getToken() + amount); return user; } + + public UserResponseDto getAllInfo(String providerId) { + User user = findUserByProviderId(providerId); + User AllInfo = User.builder() + .name(user.getName()) + .email(user.getEmail()) + .sex(user.getSex()) + .highschool(user.getHighschool()) + .gradeNum(user.getGradeNum()) + .address(user.getAddress()) + .token(user.getToken()) + .build(); + UserResponseDto allDto = new UserResponseDto(AllInfo); + return allDto; + } + public UserResponseDto getBasicInfo(String providerId) { + User user = findUserByProviderId(providerId); + User basicInfo = User.builder() + .name(user.getName()) + .highschool(user.getHighschool()) + .gradeNum(user.getGradeNum()) + .token(user.getToken()) + .build(); + UserResponseDto basicDto = new UserResponseDto(basicInfo); + return basicDto; + } + + public UserResponseDto getMypageInfo(String providerId) { + User user = findUserByProviderId(providerId); + User mypageInfo = User.builder() + .name(user.getName()) + .highschool(user.getHighschool()) + .gradeNum(user.getGradeNum()) + .email(user.getEmail()) + .sex(user.getSex()) + .build(); + UserResponseDto mypageDto = new UserResponseDto(mypageInfo); + return mypageDto; + } }