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; } }