From 6ddb30ac8753524782186dc24be666a14fa36753 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 17 Nov 2023 18:57:18 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8A=B9=EA=B0=80/=ED=98=9C=ED=83=9D?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/controller/EventController.java | 24 ++++++++++++++ .../java/MARKETFUBY/Event/dto/EventDto.java | 22 +++++++++++++ .../Event/service/EventService.java | 31 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/main/java/MARKETFUBY/Event/controller/EventController.java create mode 100644 src/main/java/MARKETFUBY/Event/dto/EventDto.java create mode 100644 src/main/java/MARKETFUBY/Event/service/EventService.java diff --git a/src/main/java/MARKETFUBY/Event/controller/EventController.java b/src/main/java/MARKETFUBY/Event/controller/EventController.java new file mode 100644 index 0000000..1360159 --- /dev/null +++ b/src/main/java/MARKETFUBY/Event/controller/EventController.java @@ -0,0 +1,24 @@ +package MARKETFUBY.Event.controller; + +import MARKETFUBY.Event.dto.EventDto; +import MARKETFUBY.Event.service.EventService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +public class EventController { + private final EventService eventService; + + @GetMapping("/market-benefit") + @ResponseStatus(value = HttpStatus.OK) + public List getEventList() { + List eventDtoList = eventService.getEventList(); + return eventDtoList; + } +} diff --git a/src/main/java/MARKETFUBY/Event/dto/EventDto.java b/src/main/java/MARKETFUBY/Event/dto/EventDto.java new file mode 100644 index 0000000..6c5b403 --- /dev/null +++ b/src/main/java/MARKETFUBY/Event/dto/EventDto.java @@ -0,0 +1,22 @@ +package MARKETFUBY.Event.dto; + +import MARKETFUBY.Event.domain.Event; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class EventDto{ + private Long eventId; + private String image; + + public static EventDto from(Event event) { + return EventDto.builder() + .eventId(event.getEventId()) + .image(event.getImage()) + .build(); + } +} diff --git a/src/main/java/MARKETFUBY/Event/service/EventService.java b/src/main/java/MARKETFUBY/Event/service/EventService.java new file mode 100644 index 0000000..b55a2d8 --- /dev/null +++ b/src/main/java/MARKETFUBY/Event/service/EventService.java @@ -0,0 +1,31 @@ +package MARKETFUBY.Event.service; + +import MARKETFUBY.Event.domain.Event; +import MARKETFUBY.Event.dto.EventDto; +import MARKETFUBY.Event.repository.EventRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +@Transactional +@RequiredArgsConstructor +public class EventService { + private final EventRepository eventRepository; + + // 이벤트 목록 조회 + @Transactional(readOnly = true) + public List getEventList() { + List allEvents = eventRepository.findAll(); + + List eventDtoList = new ArrayList<>(); + for (Event event : allEvents) { + Long eventId = event.getEventId(); + String image = event.getImage(); + } + return eventDtoList; + } +}