From df6cf5d418b717dc5e499d1e0ddbdd9496496345 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Sun, 26 Nov 2023 00:15:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/readyvery/readyverydemo/domain/Event.java | 4 ++++ .../domain/repository/EventRepository.java | 8 ++++++++ .../readyverydemo/src/event/EventController.java | 14 ++++++++++++-- .../readyverydemo/src/event/EventService.java | 3 +++ .../readyverydemo/src/event/EventServiceImpl.java | 14 ++++++++++++++ .../readyverydemo/src/event/dto/EventMainRes.java | 12 ++++++++++++ .../readyverydemo/src/event/dto/EventMapper.java | 11 +++++++++++ .../readyverydemo/src/event/dto/MainEventDto.java | 11 +++++++++++ 8 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/repository/EventRepository.java create mode 100644 src/main/java/com/readyvery/readyverydemo/src/event/dto/EventMainRes.java create mode 100644 src/main/java/com/readyvery/readyverydemo/src/event/dto/MainEventDto.java diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Event.java b/src/main/java/com/readyvery/readyverydemo/domain/Event.java index c4847893..a2dd2782 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 00000000..95969b13 --- /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 02d90649..bc6a9a3c 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 9f77f2a8..d2755a42 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 7b7de2ad..d54eda42 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 00000000..711c98bb --- /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 13c96434..eed2074b 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 00000000..f68e010c --- /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; +} From a6017d02b7565fb6c792ab638e05faf246c5af16 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Sun, 26 Nov 2023 00:16:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyvery/readyverydemo/src/event/EventController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 bc6a9a3c..aee3435a 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java +++ b/src/main/java/com/readyvery/readyverydemo/src/event/EventController.java @@ -25,7 +25,7 @@ public ResponseEntity getBanners() { @GetMapping("/main") public ResponseEntity getMain() { - EventMainRes EventMainRes = eventService.getMainEvents(); - return new ResponseEntity<>(EventMainRes, HttpStatus.OK); + EventMainRes eventMainRes = eventService.getMainEvents(); + return new ResponseEntity<>(eventMainRes, HttpStatus.OK); } }