From 806c158bedf0d8a19b7ec86f2a961d67ca060998 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 24 Nov 2023 06:50:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20event=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=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 --- .../java/MARKETFUBY/Event/dto/EventDto.java | 14 ++++++-------- .../Event/repository/EventRepository.java | 3 ++- .../MARKETFUBY/Event/service/EventService.java | 18 +++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/MARKETFUBY/Event/dto/EventDto.java b/src/main/java/MARKETFUBY/Event/dto/EventDto.java index 6c5b403..2a0872e 100644 --- a/src/main/java/MARKETFUBY/Event/dto/EventDto.java +++ b/src/main/java/MARKETFUBY/Event/dto/EventDto.java @@ -7,16 +7,14 @@ import lombok.Getter; @Getter -@Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) public class EventDto{ - private Long eventId; - private String image; + private Long eventId; + private String image; - public static EventDto from(Event event) { - return EventDto.builder() - .eventId(event.getEventId()) - .image(event.getImage()) - .build(); + @Builder + public EventDto(Event event){ + this.eventId = event.getEventId(); + this.image = event.getImage(); } } diff --git a/src/main/java/MARKETFUBY/Event/repository/EventRepository.java b/src/main/java/MARKETFUBY/Event/repository/EventRepository.java index ce3084c..04885b4 100644 --- a/src/main/java/MARKETFUBY/Event/repository/EventRepository.java +++ b/src/main/java/MARKETFUBY/Event/repository/EventRepository.java @@ -1,10 +1,11 @@ package MARKETFUBY.Event.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import MARKETFUBY.Event.domain.Event; public interface EventRepository extends JpaRepository { - + List findAll(); } diff --git a/src/main/java/MARKETFUBY/Event/service/EventService.java b/src/main/java/MARKETFUBY/Event/service/EventService.java index b55a2d8..87fdee4 100644 --- a/src/main/java/MARKETFUBY/Event/service/EventService.java +++ b/src/main/java/MARKETFUBY/Event/service/EventService.java @@ -7,8 +7,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; +import java.util.Stack; +import java.util.stream.Collectors; @Service @Transactional @@ -17,15 +18,14 @@ 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(); - } + List eventList = new Stack<>(); + eventList = eventRepository.findAll(); + List eventDtoList = eventList.stream() + .map(h -> EventDto.builder() + .event(h) + .build()) + .collect(Collectors.toList()); return eventDtoList; } }