diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Event.java b/src/main/java/com/readyvery/readyverydemo/domain/Event.java index c484789..a2dd278 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/Event.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/Event.java @@ -30,6 +30,10 @@ public class Event extends BaseTimeEntity { @Column(name = "main_img") private String mainImg; + // 이벤트 리다이렉트 url + @Column(name = "redirect_url") + private String redirectUrl; + // 이벤트 진행 여부 @Column(name = "is_active") private boolean isActive; diff --git a/src/main/java/com/readyvery/readyverydemo/domain/repository/EventRepository.java b/src/main/java/com/readyvery/readyverydemo/domain/repository/EventRepository.java new file mode 100644 index 0000000..95969b1 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/repository/EventRepository.java @@ -0,0 +1,8 @@ +package com.readyvery.readyverydemo.domain.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.readyvery.readyverydemo.domain.Event; + +public interface EventRepository extends JpaRepository { +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java b/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java index 02d9064..bc6a9a3 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java +++ b/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java @@ -1,9 +1,12 @@ package com.readyvery.readyverydemo.src.event; +import org.springframework.http.HttpStatus; +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 com.readyvery.readyverydemo.src.event.dto.EventMainRes; import com.readyvery.readyverydemo.src.event.dto.EventRes; import lombok.RequiredArgsConstructor; @@ -15,7 +18,14 @@ public class EventController { private final EventService eventService; @GetMapping("/banner") - public EventRes getBanners() { - return eventService.getBanners(); + public ResponseEntity getBanners() { + EventRes eventRes = eventService.getBanners(); + return new ResponseEntity<>(eventRes, HttpStatus.OK); + } + + @GetMapping("/main") + public ResponseEntity getMain() { + EventMainRes EventMainRes = eventService.getMainEvents(); + return new ResponseEntity<>(EventMainRes, HttpStatus.OK); } } diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/EventService.java b/src/main/java/com/readyvery/readyverydemo/src/event/EventService.java index 9f77f2a..d2755a4 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/event/EventService.java +++ b/src/main/java/com/readyvery/readyverydemo/src/event/EventService.java @@ -1,7 +1,10 @@ package com.readyvery.readyverydemo.src.event; +import com.readyvery.readyverydemo.src.event.dto.EventMainRes; import com.readyvery.readyverydemo.src.event.dto.EventRes; public interface EventService { EventRes getBanners(); + + EventMainRes getMainEvents(); } diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/EventServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/event/EventServiceImpl.java index 7b7de2a..d54eda4 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/event/EventServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/event/EventServiceImpl.java @@ -5,7 +5,10 @@ import org.springframework.stereotype.Service; import com.readyvery.readyverydemo.domain.CouponDetail; +import com.readyvery.readyverydemo.domain.Event; import com.readyvery.readyverydemo.domain.repository.CouponDetailRepository; +import com.readyvery.readyverydemo.domain.repository.EventRepository; +import com.readyvery.readyverydemo.src.event.dto.EventMainRes; import com.readyvery.readyverydemo.src.event.dto.EventMapper; import com.readyvery.readyverydemo.src.event.dto.EventRes; @@ -16,10 +19,21 @@ public class EventServiceImpl implements EventService { private final EventMapper eventMapper; private final CouponDetailRepository couponDetailRepository; + private final EventRepository eventRepository; @Override public EventRes getBanners() { List couponDetails = couponDetailRepository.findAll(); return eventMapper.toEventRes(couponDetails); } + + @Override + public EventMainRes getMainEvents() { + List events = getEvents(); + return eventMapper.toEventMainRes(events); + } + + private List getEvents() { + return eventRepository.findAll(); + } } diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMainRes.java b/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMainRes.java new file mode 100644 index 0000000..711c98b --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMainRes.java @@ -0,0 +1,12 @@ +package com.readyvery.readyverydemo.src.event.dto; + +import java.util.List; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class EventMainRes { + private List mainEvents; +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMapper.java b/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMapper.java index 13c9643..eed2074 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMapper.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Component; import com.readyvery.readyverydemo.domain.CouponDetail; +import com.readyvery.readyverydemo.domain.Event; import lombok.RequiredArgsConstructor; @@ -27,4 +28,14 @@ private List couponDetailsToBannerDto(List couponDetail .build() ).toList(); } + + public EventMainRes toEventMainRes(List events) { + return EventMainRes.builder() + .mainEvents(events.stream().filter(Event::isActive).map(event -> MainEventDto.builder() + .imgUrl(event.getMainImg()) + .redirectUrl(event.getRedirectUrl()) + .build() + ).toList()) + .build(); + } } diff --git a/src/main/java/com/readyvery/readyverydemo/src/event/dto/MainEventDto.java b/src/main/java/com/readyvery/readyverydemo/src/event/dto/MainEventDto.java new file mode 100644 index 0000000..f68e010 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/event/dto/MainEventDto.java @@ -0,0 +1,11 @@ +package com.readyvery.readyverydemo.src.event.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class MainEventDto { + private String imgUrl; + private String redirectUrl; +}