-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat - 배너 정보 불러오기 #197
Merged
Merged
feat - 배너 정보 불러오기 #197
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a21a9fa
add - #196 banner domain, dto 추가
jumining 7eb34c1
add - #196 banner exception 파일 추가
jumining 1a5b420
feat - #196 배너 컨트롤러 배너 정보 불러오는 get 메소드 추가
jumining 3ae0472
feat - #196 배너 관련 Repository 인터페이스, 구현클래스 추가
jumining c39c926
feat - #196 배너 정보 불러오는 서비스 메소드 구현
jumining 6156d35
chore - #196 banner jpa repository 하나만 남기기
jumining bfd12cc
chore - #196 banner service에서 repository 형식 바꾸기
jumining File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/sopt/org/hmh/domain/banner/BannerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/sopt/org/hmh/domain/banner/BannerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/sopt/org/hmh/domain/banner/controller/BannerApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseResponse<BannerResponse>> orderGetBanner(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/sopt/org/hmh/domain/banner/controller/BannerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseResponse<BannerResponse>> orderGetBanner() { | ||
return ResponseEntity | ||
.status(BannerSuccess.GET_BANNER_SUCCESS.getHttpStatus()) | ||
.body(BaseResponse.success(BannerSuccess.GET_BANNER_SUCCESS, bannerService.getBanner())); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/sopt/org/hmh/domain/banner/exception/BannerError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sopt/org/hmh/domain/banner/exception/BannerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); } | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/sopt/org/hmh/domain/banner/exception/BannerSuccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/sopt/org/hmh/domain/banner/repository/BannerJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Banner, Long> { | ||
Optional<Banner> findTopByOrderByIdAsc(); // 디비에 배너 하나만 존재 | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Banner> findTopByOrderByIdAsc(); | ||
} | ||
19 changes: 19 additions & 0 deletions
19
src/main/java/sopt/org/hmh/domain/banner/repository/BannerRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Banner> findTopByOrderByIdAsc() { | ||
return bannerJpaRepository.findTopByOrderByIdAsc(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4. Banner 엔티티는 Jpa외에 복잡한 쿼리를 사용할 일이 없을 것 같아 JpaRepository 하나만 있는게 코드 복잡도 측면에서 더 좋을 것 같은데 어떠신가요?
저는 보통 복잡한 쿼리가 필요하여 Querydsl 사용시에 이렇게 나누는 편이라 복잡한 쿼리가 필요없다면 하나만 유지해도 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 생각입니당! 빠른 코리 감사드려요