Skip to content

Commit

Permalink
Feat: 이벤트 메인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
marinesnow34 committed Nov 25, 2023
1 parent 367cd71 commit df6cf5d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Event, Long> {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +18,14 @@ public class EventController {
private final EventService eventService;

@GetMapping("/banner")
public EventRes getBanners() {
return eventService.getBanners();
public ResponseEntity<EventRes> getBanners() {
EventRes eventRes = eventService.getBanners();
return new ResponseEntity<>(eventRes, HttpStatus.OK);
}

@GetMapping("/main")
public ResponseEntity<EventMainRes> getMain() {
EventMainRes EventMainRes = eventService.getMainEvents();
return new ResponseEntity<>(EventMainRes, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<CouponDetail> couponDetails = couponDetailRepository.findAll();
return eventMapper.toEventRes(couponDetails);
}

@Override
public EventMainRes getMainEvents() {
List<Event> events = getEvents();
return eventMapper.toEventMainRes(events);
}

private List<Event> getEvents() {
return eventRepository.findAll();
}
}
Original file line number Diff line number Diff line change
@@ -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<MainEventDto> mainEvents;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Component;

import com.readyvery.readyverydemo.domain.CouponDetail;
import com.readyvery.readyverydemo.domain.Event;

import lombok.RequiredArgsConstructor;

Expand All @@ -27,4 +28,14 @@ private List<BannerDto> couponDetailsToBannerDto(List<CouponDetail> couponDetail
.build()
).toList();
}

public EventMainRes toEventMainRes(List<Event> events) {
return EventMainRes.builder()
.mainEvents(events.stream().filter(Event::isActive).map(event -> MainEventDto.builder()
.imgUrl(event.getMainImg())
.redirectUrl(event.getRedirectUrl())
.build()
).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit df6cf5d

Please sign in to comment.