From a21a9fa9025907db5d1a5c110fefd263a2e0bb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 19 Nov 2024 13:38:29 +0900 Subject: [PATCH 1/7] =?UTF-8?q?add=20-=20#196=20banner=20domain,=20dto=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/hmh/domain/banner/Banner.java | 25 +++++++++++++++++++ .../org/hmh/domain/banner/BannerResponse.java | 20 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/banner/Banner.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/BannerResponse.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/Banner.java b/src/main/java/sopt/org/hmh/domain/banner/Banner.java new file mode 100644 index 00000000..09c54308 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/Banner.java @@ -0,0 +1,25 @@ +package sopt.org.hmh.domain.banner; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static jakarta.persistence.GenerationType.IDENTITY; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Banner { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + + private String title; + private String subTitle; + private String imageUrl; + private String linkUrl; +} diff --git a/src/main/java/sopt/org/hmh/domain/banner/BannerResponse.java b/src/main/java/sopt/org/hmh/domain/banner/BannerResponse.java new file mode 100644 index 00000000..2a2d831f --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/BannerResponse.java @@ -0,0 +1,20 @@ +package sopt.org.hmh.domain.banner; + +import lombok.Builder; + +@Builder +public record BannerResponse( + String title, + String subTitle, + String imageUrl, + String linkUrl +) { + public static BannerResponse of(Banner banner) { + return BannerResponse.builder() + .title(banner.getTitle()) + .subTitle(banner.getSubTitle()) + .imageUrl(banner.getImageUrl()) + .linkUrl(banner.getLinkUrl()) + .build(); + } +} From 7eb34c1e7dc2dbcb1394977d45df3d031b7f2a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 19 Nov 2024 13:38:52 +0900 Subject: [PATCH 2/7] =?UTF-8?q?add=20-=20#196=20banner=20exception=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/banner/exception/BannerError.java | 30 +++++++++++++++++++ .../banner/exception/BannerException.java | 7 +++++ .../banner/exception/BannerSuccess.java | 30 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/banner/exception/BannerError.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/exception/BannerException.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/exception/BannerSuccess.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/exception/BannerError.java b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerError.java new file mode 100644 index 00000000..4340d78d --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerError.java @@ -0,0 +1,30 @@ +package sopt.org.hmh.domain.banner.exception; + +import lombok.AllArgsConstructor; +import org.springframework.http.HttpStatus; +import sopt.org.hmh.global.common.exception.base.ErrorBase; + +@AllArgsConstructor +public enum BannerError implements ErrorBase { + + BANNER_NOT_FOUND(HttpStatus.NOT_FOUND, "배너를 찾을 수 없습니다."), + ; + + private final HttpStatus status; + private final String errorMessage; + + @Override + public int getHttpStatusCode() { + return status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/banner/exception/BannerException.java b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerException.java new file mode 100644 index 00000000..9c8ba48f --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerException.java @@ -0,0 +1,7 @@ +package sopt.org.hmh.domain.banner.exception; + +import sopt.org.hmh.global.common.exception.base.ExceptionBase; + +public class BannerException extends ExceptionBase { + public BannerException(BannerError error) { super(error); } +} \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/banner/exception/BannerSuccess.java b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerSuccess.java new file mode 100644 index 00000000..3ec98db9 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/exception/BannerSuccess.java @@ -0,0 +1,30 @@ +package sopt.org.hmh.domain.banner.exception; + +import lombok.AllArgsConstructor; +import org.springframework.http.HttpStatus; +import sopt.org.hmh.global.common.exception.base.SuccessBase; + +@AllArgsConstructor +public enum BannerSuccess implements SuccessBase { + + GET_BANNER_SUCCESS(HttpStatus.OK, "배너 정보 불러오기에 성공하였습니다."), + ; + + private final HttpStatus status; + private final String successMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getSuccessMessage() { + return this.successMessage; + } +} From 1a5b4207de7c3f86de54de7b90ba6ed32409167e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 19 Nov 2024 13:39:23 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat=20-=20#196=20=EB=B0=B0=EB=84=88=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=B0=B0=EB=84=88=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20get?= =?UTF-8?q?=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/banner/controller/BannerApi.java | 29 +++++++++++++++++++ .../banner/controller/BannerController.java | 27 +++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/banner/controller/BannerApi.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/controller/BannerController.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/controller/BannerApi.java b/src/main/java/sopt/org/hmh/domain/banner/controller/BannerApi.java new file mode 100644 index 00000000..3d9aff8c --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/controller/BannerApi.java @@ -0,0 +1,29 @@ +package sopt.org.hmh.domain.banner.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import sopt.org.hmh.domain.banner.BannerResponse; +import sopt.org.hmh.global.common.response.BaseResponse; + +@Tag(name = "배너 관련 API") +public interface BannerApi { + + @Operation( + summary = "배너 정보를 불러오는 API", + responses = { + @ApiResponse( + responseCode = "200", + description = "배너 정보 불러오기에 성공하였습니다."), + @ApiResponse( + responseCode = "404", + description = "배너를 찾을 수 없습니다.", + content = @Content), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류입니다.", + content = @Content)}) + ResponseEntity> orderGetBanner(); +} diff --git a/src/main/java/sopt/org/hmh/domain/banner/controller/BannerController.java b/src/main/java/sopt/org/hmh/domain/banner/controller/BannerController.java new file mode 100644 index 00000000..257ae403 --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/controller/BannerController.java @@ -0,0 +1,27 @@ +package sopt.org.hmh.domain.banner.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.hmh.domain.banner.BannerResponse; +import sopt.org.hmh.domain.banner.BannerService; +import sopt.org.hmh.domain.banner.exception.BannerSuccess; +import sopt.org.hmh.global.common.response.BaseResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v2/banner") +public class BannerController implements BannerApi { + + private final BannerService bannerService; + + @Override + @GetMapping + public ResponseEntity> orderGetBanner() { + return ResponseEntity + .status(BannerSuccess.GET_BANNER_SUCCESS.getHttpStatus()) + .body(BaseResponse.success(BannerSuccess.GET_BANNER_SUCCESS, bannerService.getBanner())); + } +} From 3ae0472a7ca85b00231b8650307840112a4b5573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 19 Nov 2024 13:39:51 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat=20-=20#196=20=EB=B0=B0=EB=84=88=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20Repository=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4,=20=EA=B5=AC=ED=98=84=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BannerJpaRepository.java | 10 ++++++++++ .../banner/repository/BannerRepository.java | 9 +++++++++ .../repository/BannerRepositoryImpl.java | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java create mode 100644 src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java new file mode 100644 index 00000000..88e0e09b --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java @@ -0,0 +1,10 @@ +package sopt.org.hmh.domain.banner.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import sopt.org.hmh.domain.banner.Banner; + +import java.util.Optional; + +public interface BannerJpaRepository extends JpaRepository { + Optional findTopByOrderByIdAsc(); // 디비에 배너 하나만 존재 +} diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java new file mode 100644 index 00000000..ebf20adf --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java @@ -0,0 +1,9 @@ +package sopt.org.hmh.domain.banner.repository; + +import sopt.org.hmh.domain.banner.Banner; + +import java.util.Optional; + +public interface BannerRepository { + Optional findTopByOrderByIdAsc(); +} diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java new file mode 100644 index 00000000..abe85ace --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java @@ -0,0 +1,19 @@ +package sopt.org.hmh.domain.banner.repository; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import sopt.org.hmh.domain.banner.Banner; + +import java.util.Optional; + +@Repository +@RequiredArgsConstructor +public class BannerRepositoryImpl implements BannerRepository { + + private final BannerJpaRepository bannerJpaRepository; + + @Override + public Optional findTopByOrderByIdAsc() { + return bannerJpaRepository.findTopByOrderByIdAsc(); + } +} From c39c926ac68ae06b661f435753c75ebb84b886ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 19 Nov 2024 13:40:04 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat=20-=20#196=20=EB=B0=B0=EB=84=88=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hmh/domain/banner/BannerService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/sopt/org/hmh/domain/banner/BannerService.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/BannerService.java b/src/main/java/sopt/org/hmh/domain/banner/BannerService.java new file mode 100644 index 00000000..ac0e7f9a --- /dev/null +++ b/src/main/java/sopt/org/hmh/domain/banner/BannerService.java @@ -0,0 +1,20 @@ +package sopt.org.hmh.domain.banner; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import sopt.org.hmh.domain.banner.exception.BannerError; +import sopt.org.hmh.domain.banner.exception.BannerException; +import sopt.org.hmh.domain.banner.repository.BannerRepository; + +@Service +@RequiredArgsConstructor +public class BannerService { + + private final BannerRepository bannerRepository; + + public BannerResponse getBanner() { + return bannerRepository.findTopByOrderByIdAsc() + .map(BannerResponse::of) + .orElseThrow(() -> new BannerException(BannerError.BANNER_NOT_FOUND)); + } +} From 6156d3567399178eb7ae12d7539ce424814cbe1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Wed, 20 Nov 2024 12:14:04 +0900 Subject: [PATCH 6/7] =?UTF-8?q?chore=20-=20#196=20banner=20jpa=20repositor?= =?UTF-8?q?y=20=ED=95=98=EB=82=98=EB=A7=8C=20=EB=82=A8=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{repository => }/BannerJpaRepository.java | 3 +-- .../banner/repository/BannerRepository.java | 9 --------- .../repository/BannerRepositoryImpl.java | 19 ------------------- 3 files changed, 1 insertion(+), 30 deletions(-) rename src/main/java/sopt/org/hmh/domain/banner/{repository => }/BannerJpaRepository.java (73%) delete mode 100644 src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java delete mode 100644 src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java b/src/main/java/sopt/org/hmh/domain/banner/BannerJpaRepository.java similarity index 73% rename from src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java rename to src/main/java/sopt/org/hmh/domain/banner/BannerJpaRepository.java index 88e0e09b..4580ec20 100644 --- a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java +++ b/src/main/java/sopt/org/hmh/domain/banner/BannerJpaRepository.java @@ -1,7 +1,6 @@ -package sopt.org.hmh.domain.banner.repository; +package sopt.org.hmh.domain.banner; import org.springframework.data.jpa.repository.JpaRepository; -import sopt.org.hmh.domain.banner.Banner; import java.util.Optional; diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java deleted file mode 100644 index ebf20adf..00000000 --- a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package sopt.org.hmh.domain.banner.repository; - -import sopt.org.hmh.domain.banner.Banner; - -import java.util.Optional; - -public interface BannerRepository { - Optional findTopByOrderByIdAsc(); -} diff --git a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java deleted file mode 100644 index abe85ace..00000000 --- a/src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package sopt.org.hmh.domain.banner.repository; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; -import sopt.org.hmh.domain.banner.Banner; - -import java.util.Optional; - -@Repository -@RequiredArgsConstructor -public class BannerRepositoryImpl implements BannerRepository { - - private final BannerJpaRepository bannerJpaRepository; - - @Override - public Optional findTopByOrderByIdAsc() { - return bannerJpaRepository.findTopByOrderByIdAsc(); - } -} From bfd12cc8d17543af43c2672e45c4efe0d8c304bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Wed, 20 Nov 2024 12:14:36 +0900 Subject: [PATCH 7/7] =?UTF-8?q?chore=20-=20#196=20banner=20service?= =?UTF-8?q?=EC=97=90=EC=84=9C=20repository=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EB=B0=94=EA=BE=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/sopt/org/hmh/domain/banner/BannerService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/sopt/org/hmh/domain/banner/BannerService.java b/src/main/java/sopt/org/hmh/domain/banner/BannerService.java index ac0e7f9a..e548f7bf 100644 --- a/src/main/java/sopt/org/hmh/domain/banner/BannerService.java +++ b/src/main/java/sopt/org/hmh/domain/banner/BannerService.java @@ -4,13 +4,12 @@ import org.springframework.stereotype.Service; import sopt.org.hmh.domain.banner.exception.BannerError; import sopt.org.hmh.domain.banner.exception.BannerException; -import sopt.org.hmh.domain.banner.repository.BannerRepository; @Service @RequiredArgsConstructor public class BannerService { - private final BannerRepository bannerRepository; + private final BannerJpaRepository bannerRepository; public BannerResponse getBanner() { return bannerRepository.findTopByOrderByIdAsc()