From e1e8b5f9dfb8cce02263946bc69383287017cab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=AF=E1=86=AB=E1=84=8C=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=89=E1=85=AE=E1=86=AB?= Date: Sat, 14 Sep 2024 08:55:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=20[=E2=99=BB=EF=B8=8F=20refactor/#134]:=20?= =?UTF-8?q?AuthSwagger=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20Swagger=20=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 각 API 메서드에 대해 Swagger 주석 추가 - `filter` API 및 `signUp` API 헤더 정보 설명 보완 --- .../org/terning/terningserver/controller/AuthController.java | 2 +- .../terningserver/controller/swagger/AuthSwagger.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/terning/terningserver/controller/AuthController.java b/src/main/java/org/terning/terningserver/controller/AuthController.java index 45522ba..33f3496 100644 --- a/src/main/java/org/terning/terningserver/controller/AuthController.java +++ b/src/main/java/org/terning/terningserver/controller/AuthController.java @@ -48,7 +48,7 @@ public ResponseEntity> reissueToken( @PostMapping("/sign-up") public ResponseEntity> signUp( - @RequestHeader("authId") String authId, + @RequestHeader("Authorization") String authId, @RequestBody SignUpRequestDto request ) { diff --git a/src/main/java/org/terning/terningserver/controller/swagger/AuthSwagger.java b/src/main/java/org/terning/terningserver/controller/swagger/AuthSwagger.java index fd46b21..cfdb603 100644 --- a/src/main/java/org/terning/terningserver/controller/swagger/AuthSwagger.java +++ b/src/main/java/org/terning/terningserver/controller/swagger/AuthSwagger.java @@ -1,6 +1,7 @@ package org.terning.terningserver.controller.swagger; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -20,23 +21,27 @@ public interface AuthSwagger { @Operation(summary = "소셜 로그인", description = "AuthType에 맞는 소셜 로그인 API") ResponseEntity> signIn( + @Parameter(name = "Authorization", description = "", example = "authAccessToken") @RequestHeader("Authorization") String authAccessToken, @RequestBody SignInRequestDto request ); @Operation(summary = "토큰 재발급", description = "토큰 재발급 API") ResponseEntity> reissueToken( + @Parameter(name = "Authorization", description = "", example = "refreshToken") @RequestHeader("Authorization") String refreshToken ); @Operation(summary = "사용자 필터링 정보 생성", description = "사용자 필터링 정보 생성 API") ResponseEntity> filter( + @Parameter(name = "User-Id", description = "", example = "userId") @RequestHeader("User-Id") Long userId, @RequestBody SignUpFilterRequestDto request ); @Operation(summary = "회원가입", description = "회원가입 API") ResponseEntity> signUp( + @Parameter(name = "Authorization", description = "", example = "authId") @RequestHeader("authId") String authId, @RequestBody SignUpRequestDto request ); From 1a2a718ab09a247ee6d749d2b382ae88d12ddb93 Mon Sep 17 00:00:00 2001 From: Willy Date: Thu, 19 Sep 2024 13:18:33 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[=E2=99=BB=EF=B8=8F=20refactor]=20=ED=99=88?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20>=20=EA=B3=A7=20=EB=A7=88=EA=B0=90?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EA=B4=80=EC=8B=AC=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HomeController.java | 6 +- .../response/UpcomingScrapResponseDto.java | 56 +++++++++++-------- .../repository/scrap/ScrapRepository.java | 2 +- .../terningserver/service/ScrapService.java | 4 +- .../service/ScrapServiceImpl.java | 9 ++- 5 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/terning/terningserver/controller/HomeController.java b/src/main/java/org/terning/terningserver/controller/HomeController.java index 3c82c30..af85d8f 100644 --- a/src/main/java/org/terning/terningserver/controller/HomeController.java +++ b/src/main/java/org/terning/terningserver/controller/HomeController.java @@ -41,8 +41,10 @@ public ResponseEntity>> getUpcomi @AuthenticationPrincipal Long userId ){ - List scrapList = scrapService.getUpcomingScrap(userId); + boolean hasScrapped = scrapService.hasUserScrapped(userId); + List scrapList = scrapService.getUpcomingScrap(userId); - return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, scrapList)); + UpcomingScrapResponseDto responseDto = new UpcomingScrapResponseDto(hasScrapped, scrapList); + return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, responseDto)); } } diff --git a/src/main/java/org/terning/terningserver/dto/user/response/UpcomingScrapResponseDto.java b/src/main/java/org/terning/terningserver/dto/user/response/UpcomingScrapResponseDto.java index 73a6959..6fc834f 100644 --- a/src/main/java/org/terning/terningserver/dto/user/response/UpcomingScrapResponseDto.java +++ b/src/main/java/org/terning/terningserver/dto/user/response/UpcomingScrapResponseDto.java @@ -4,33 +4,41 @@ import org.terning.terningserver.domain.Scrap; import org.terning.terningserver.util.DateUtil; +import java.util.List; + @Builder public record UpcomingScrapResponseDto( - Long internshipAnnouncementId, - String companyImage, - String dDay, - String title, - String workingPeriod, - boolean isScrapped, - String color, - String deadline, - String startYearMonth, - String companyInfo + boolean hasScrapped, + List scraps ) { - public static UpcomingScrapResponseDto of(final Scrap scrap){ - String startYearMonth = scrap.getInternshipAnnouncement().getStartYear() + "년 " + scrap.getInternshipAnnouncement().getStartMonth() + "월"; + @Builder + public record ScrapDetail( + Long internshipAnnouncementId, + String companyImage, + String dDay, + String title, + String workingPeriod, + boolean isScrapped, + String color, + String deadline, + String startYearMonth, + String companyInfo + ) { + public static ScrapDetail of(final Scrap scrap) { + String startYearMonth = scrap.getInternshipAnnouncement().getStartYear() + "년 " + scrap.getInternshipAnnouncement().getStartMonth() + "월"; - return UpcomingScrapResponseDto.builder() - .internshipAnnouncementId(scrap.getInternshipAnnouncement().getId()) - .companyImage(scrap.getInternshipAnnouncement().getCompany().getCompanyImage()) - .dDay(DateUtil.convert(scrap.getInternshipAnnouncement().getDeadline())) - .title(scrap.getInternshipAnnouncement().getTitle()) - .deadline(DateUtil.convertDeadline(scrap.getInternshipAnnouncement().getDeadline())) - .isScrapped(true) // 스크랩된 항목이므로 항상 true - .color(scrap.getColorToHexValue()) - .workingPeriod(scrap.getInternshipAnnouncement().getWorkingPeriod()) - .startYearMonth(startYearMonth) - .companyInfo(scrap.getInternshipAnnouncement().getCompany().getCompanyInfo()) - .build(); + return ScrapDetail.builder() + .internshipAnnouncementId(scrap.getInternshipAnnouncement().getId()) + .companyImage(scrap.getInternshipAnnouncement().getCompany().getCompanyImage()) + .dDay(DateUtil.convert(scrap.getInternshipAnnouncement().getDeadline())) + .title(scrap.getInternshipAnnouncement().getTitle()) + .deadline(DateUtil.convertDeadline(scrap.getInternshipAnnouncement().getDeadline())) + .isScrapped(true) // 스크랩된 항목이므로 항상 true + .color(scrap.getColorToHexValue()) + .workingPeriod(scrap.getInternshipAnnouncement().getWorkingPeriod()) + .startYearMonth(startYearMonth) + .companyInfo(scrap.getInternshipAnnouncement().getCompany().getCompanyInfo()) + .build(); + } } } diff --git a/src/main/java/org/terning/terningserver/repository/scrap/ScrapRepository.java b/src/main/java/org/terning/terningserver/repository/scrap/ScrapRepository.java index e4d0d1c..daeb384 100644 --- a/src/main/java/org/terning/terningserver/repository/scrap/ScrapRepository.java +++ b/src/main/java/org/terning/terningserver/repository/scrap/ScrapRepository.java @@ -14,7 +14,7 @@ public interface ScrapRepository extends JpaRepository, ScrapReposi void deleteByInternshipAnnouncementIdAndUserId(Long internshipId, Long userId); - List findByUserIdAndInternshipAnnouncement_DeadlineBetween(Long userId, LocalDate start, LocalDate end); + boolean existsByUserId(Long userId); } diff --git a/src/main/java/org/terning/terningserver/service/ScrapService.java b/src/main/java/org/terning/terningserver/service/ScrapService.java index 820faf5..e3b7072 100644 --- a/src/main/java/org/terning/terningserver/service/ScrapService.java +++ b/src/main/java/org/terning/terningserver/service/ScrapService.java @@ -11,7 +11,9 @@ import java.util.List; public interface ScrapService { - List getUpcomingScrap(Long userId); + + boolean hasUserScrapped(long userId); + List getUpcomingScrap(long userId); void createScrap(Long internshipAnnouncementId, CreateScrapRequestDto request, Long userId); diff --git a/src/main/java/org/terning/terningserver/service/ScrapServiceImpl.java b/src/main/java/org/terning/terningserver/service/ScrapServiceImpl.java index 9bee889..a239f71 100644 --- a/src/main/java/org/terning/terningserver/service/ScrapServiceImpl.java +++ b/src/main/java/org/terning/terningserver/service/ScrapServiceImpl.java @@ -39,11 +39,16 @@ public class ScrapServiceImpl implements ScrapService { private final UserRepository userRepository; @Override - public List getUpcomingScrap(Long userId){ + public boolean hasUserScrapped(long userId) { + return scrapRepository.existsByUserId(userId); + } + + @Override + public List getUpcomingScrap(long userId){ LocalDate today = LocalDate.now(); LocalDate oneWeekFromToday = today.plusDays(7); return scrapRepository.findScrapsByUserIdAndDeadlineBetweenOrderByDeadline(userId, today, oneWeekFromToday).stream() - .map(UpcomingScrapResponseDto::of) + .map(UpcomingScrapResponseDto.ScrapDetail::of) .toList(); } From d672e45cc7d05dd97f5654b4987eaf4043918d2f Mon Sep 17 00:00:00 2001 From: Willy Date: Thu, 19 Sep 2024 13:43:42 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[=E2=99=BB=EF=B8=8F=20refactor]=20=ED=99=88?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20>=20=EA=B3=A7=20=EB=A7=88=EA=B0=90?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EA=B4=80=EC=8B=AC=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?:=20=EC=9D=91=EB=8B=B5=20=EB=B6=84=EA=B8=B0=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terningserver/controller/HomeController.java | 12 +++++++++--- .../exception/enums/SuccessMessage.java | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/terning/terningserver/controller/HomeController.java b/src/main/java/org/terning/terningserver/controller/HomeController.java index af85d8f..bda9e47 100644 --- a/src/main/java/org/terning/terningserver/controller/HomeController.java +++ b/src/main/java/org/terning/terningserver/controller/HomeController.java @@ -13,8 +13,7 @@ import java.util.List; -import static org.terning.terningserver.exception.enums.SuccessMessage.SUCCESS_GET_ANNOUNCEMENTS; -import static org.terning.terningserver.exception.enums.SuccessMessage.SUCCESS_GET_UPCOMING_ANNOUNCEMENTS; +import static org.terning.terningserver.exception.enums.SuccessMessage.*; @RestController @RequiredArgsConstructor @@ -45,6 +44,13 @@ public ResponseEntity>> getUpcomi List scrapList = scrapService.getUpcomingScrap(userId); UpcomingScrapResponseDto responseDto = new UpcomingScrapResponseDto(hasScrapped, scrapList); - return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, responseDto)); + + if(!hasScrapped){ + return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_NO_SCRAP, responseDto)); + } else if (scrapList.isEmpty()) { + return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_EMPTY_LIST, responseDto)); + } else { + return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, responseDto)); + } } } diff --git a/src/main/java/org/terning/terningserver/exception/enums/SuccessMessage.java b/src/main/java/org/terning/terningserver/exception/enums/SuccessMessage.java index 4f97534..af067cd 100644 --- a/src/main/java/org/terning/terningserver/exception/enums/SuccessMessage.java +++ b/src/main/java/org/terning/terningserver/exception/enums/SuccessMessage.java @@ -9,6 +9,8 @@ public enum SuccessMessage { // 홈 화면 SUCCESS_GET_ANNOUNCEMENTS(200, "인턴 공고 불러오기를 성공했습니다"), SUCCESS_GET_UPCOMING_ANNOUNCEMENTS(200, "곧 마감인 인턴 공고 요청을 성공했습니다"), + SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_NO_SCRAP(200, "아직 스크랩된 인턴 공고가 없어요!"), + SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_EMPTY_LIST(200, "일주일 내에 마감인 공고가 없어요\n캘린더에서 스크랩한 공고 일정을 확인해 보세요"), // 소셜 로그인 SUCCESS_SIGN_IN(200, "소셜 로그인에 성공하였습니다"),