Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 이벤트 메인 구현 #76

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}