-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Gongjakso/feat/setting
feat: 배너 이미지 리스트 반환 API
- Loading branch information
Showing
6 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/com/gongjakso/server/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,40 @@ | ||
package com.gongjakso.server.domain.banner.controller; | ||
|
||
import com.gongjakso.server.domain.banner.dto.response.BannerRes; | ||
import com.gongjakso.server.domain.banner.service.BannerService; | ||
import com.gongjakso.server.global.common.ApplicationResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/banner") | ||
@Tag(name = "Banner", description = "메인 페이지, 공고 페이지 등의 배너 이미지 정보 반환 API") | ||
public class BannerController { | ||
|
||
private final BannerService bannerService; | ||
|
||
@Operation(description = "메인 페이지 공고 리스트 반환") | ||
@GetMapping("/main") | ||
public ApplicationResponse<List<BannerRes>> getMainImageList() { | ||
return ApplicationResponse.ok(bannerService.getMainImageList()); | ||
} | ||
|
||
@Operation(description = "프로젝트 공고 페이지 배너 리스트 반환") | ||
@GetMapping("/project") | ||
public ApplicationResponse<List<BannerRes>> getProjectImageList() { | ||
return ApplicationResponse.ok(bannerService.getProjectImageList()); | ||
} | ||
|
||
@Operation(description = "공모전 공고 페이지 배너 리스트 반환") | ||
@GetMapping("/project") | ||
public ApplicationResponse<List<BannerRes>> getContestImageList() { | ||
return ApplicationResponse.ok(bannerService.getContestImageList()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/gongjakso/server/domain/banner/dto/response/BannerRes.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 com.gongjakso.server.domain.banner.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.gongjakso.server.domain.banner.entity.Banner; | ||
import com.gongjakso.server.domain.banner.enumerate.DomainType; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record BannerRes( | ||
Long bannerId, | ||
DomainType domainType, | ||
String imageUrl, | ||
String linkUrl, | ||
Integer priority, | ||
Boolean isPost | ||
) { | ||
|
||
public static BannerRes of(Banner banner) { | ||
return BannerRes.builder() | ||
.bannerId(banner.getBannerId()) | ||
.domainType(banner.getDomainType()) | ||
.imageUrl(banner.getImageUrl()) | ||
.linkUrl(banner.getLinkUrl()) | ||
.priority(banner.getPriority()) | ||
.isPost(banner.getIsPost()) | ||
.build(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/gongjakso/server/domain/banner/entity/Banner.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,46 @@ | ||
package com.gongjakso.server.domain.banner.entity; | ||
|
||
import com.gongjakso.server.domain.banner.enumerate.DomainType; | ||
import com.gongjakso.server.global.common.BaseTimeEntity; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "banner") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Banner extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "banner_id", nullable = false, columnDefinition = "bigint") | ||
private Long bannerId; | ||
|
||
@Column(name = "domain_type", columnDefinition = "varchar(100)") | ||
@Enumerated(EnumType.STRING) | ||
private DomainType domainType; | ||
|
||
@Column(name = "image_url", columnDefinition = "text") | ||
private String imageUrl; | ||
|
||
@Column(name = "link_url", columnDefinition = "text") | ||
private String linkUrl; | ||
|
||
@Column(name = "priority", nullable = false, columnDefinition = "int") | ||
private Integer priority; | ||
|
||
@Column(name = "is_post", nullable = false, columnDefinition = "tinyint") | ||
private Boolean isPost; | ||
|
||
@Builder | ||
public Banner(String domainType, String imageUrl, String linkUrl, Integer priority) { | ||
this.domainType = DomainType.valueOf(domainType); | ||
this.imageUrl = imageUrl; | ||
this.linkUrl = linkUrl; | ||
this.priority = priority; | ||
this.isPost = Boolean.TRUE; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/gongjakso/server/domain/banner/enumerate/DomainType.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,12 @@ | ||
package com.gongjakso.server.domain.banner.enumerate; | ||
|
||
public enum DomainType { | ||
// 메인 페이지 | ||
MAIN, | ||
|
||
// 프로젝트, | ||
PROJECT, | ||
|
||
// 공모전 | ||
CONTEST | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/gongjakso/server/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,12 @@ | ||
package com.gongjakso.server.domain.banner.repository; | ||
|
||
import com.gongjakso.server.domain.banner.entity.Banner; | ||
import com.gongjakso.server.domain.banner.enumerate.DomainType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface BannerRepository extends JpaRepository<Banner, Long> { | ||
|
||
List<Banner> findAllByDomainTypeAndDeletedAtIsNullOrderByPriorityAsc(DomainType domainType); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/gongjakso/server/domain/banner/service/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,50 @@ | ||
package com.gongjakso.server.domain.banner.service; | ||
|
||
import com.gongjakso.server.domain.banner.dto.response.BannerRes; | ||
import com.gongjakso.server.domain.banner.entity.Banner; | ||
import com.gongjakso.server.domain.banner.enumerate.DomainType; | ||
import com.gongjakso.server.domain.banner.repository.BannerRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class BannerService { | ||
|
||
private final BannerRepository bannerRepository; | ||
|
||
public List<BannerRes> getMainImageList() { | ||
// Business Logic | ||
List<Banner> bannerList = bannerRepository.findAllByDomainTypeAndDeletedAtIsNullOrderByPriorityAsc(DomainType.MAIN); | ||
|
||
// Response | ||
return bannerList.stream() | ||
.map(BannerRes::of) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<BannerRes> getProjectImageList() { | ||
// Business Logic | ||
List<Banner> bannerList = bannerRepository.findAllByDomainTypeAndDeletedAtIsNullOrderByPriorityAsc(DomainType.PROJECT); | ||
|
||
// Response | ||
return bannerList.stream() | ||
.map(BannerRes::of) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<BannerRes> getContestImageList() { | ||
// Business Logic | ||
List<Banner> bannerList = bannerRepository.findAllByDomainTypeAndDeletedAtIsNullOrderByPriorityAsc(DomainType.CONTEST); | ||
|
||
// Response | ||
return bannerList.stream() | ||
.map(BannerRes::of) | ||
.collect(Collectors.toList()); | ||
} | ||
} |