Skip to content

Commit

Permalink
Merge pull request #38 from Gongjakso/feat/setting
Browse files Browse the repository at this point in the history
feat: 배너 이미지 리스트 반환 API
  • Loading branch information
dl-00-e8 authored Feb 5, 2024
2 parents e27f732 + 4f433c1 commit 2862cc7
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
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());
}
}
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();
}
}
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;
}
}
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
}
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);
}
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());
}
}

0 comments on commit 2862cc7

Please sign in to comment.