Skip to content

Commit

Permalink
Merge pull request #8 from MARKETFUBY/feat/event
Browse files Browse the repository at this point in the history
[차소연] 특가/혜택 목록 조회 구현
  • Loading branch information
Soyeon-Cha authored Nov 17, 2023
2 parents 72e6e36 + 6ddb30a commit 4f67843
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/MARKETFUBY/Event/controller/EventController.java
Original file line number Diff line number Diff line change
@@ -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<EventDto> getEventList() {
List<EventDto> eventDtoList = eventService.getEventList();
return eventDtoList;
}
}
22 changes: 22 additions & 0 deletions src/main/java/MARKETFUBY/Event/dto/EventDto.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
31 changes: 31 additions & 0 deletions src/main/java/MARKETFUBY/Event/service/EventService.java
Original file line number Diff line number Diff line change
@@ -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<EventDto> getEventList() {
List<Event> allEvents = eventRepository.findAll();

List<EventDto> eventDtoList = new ArrayList<>();
for (Event event : allEvents) {
Long eventId = event.getEventId();
String image = event.getImage();
}
return eventDtoList;
}
}

0 comments on commit 4f67843

Please sign in to comment.