From 686151d893bab3f11d8e8f12854fc6a74a78f730 Mon Sep 17 00:00:00 2001 From: Junho Hwang <72647031+juno-junho@users.noreply.github.com> Date: Thu, 26 Oct 2023 22:44:11 -0700 Subject: [PATCH] =?UTF-8?q?[SKRB-165]=20feat:=20=EC=9D=BC=EB=B0=98=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EA=B0=80=20=ED=96=89=EC=82=AC=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20=EC=8B=A0=EC=B2=AD=20=ED=98=84=ED=99=A9=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20DTO=20=EB=B0=8F=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=83=9D=EC=84=B1=20(#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/spaceclub/event/domain/Event.java | 9 ++++- .../com/spaceclub/event/domain/EventInfo.java | 6 ++- .../user/controller/UserController.java | 35 +++++++++++++++++ .../controller/dto/EventPageResponse.java | 38 +++++++++++++++++++ .../user/controller/dto/EventResponse.java | 16 ++++++++ .../spaceclub/user/service/UserService.java | 13 +++++++ 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/spaceclub/user/controller/UserController.java create mode 100644 src/main/java/com/spaceclub/user/controller/dto/EventPageResponse.java create mode 100644 src/main/java/com/spaceclub/user/controller/dto/EventResponse.java create mode 100644 src/main/java/com/spaceclub/user/service/UserService.java diff --git a/src/main/java/com/spaceclub/event/domain/Event.java b/src/main/java/com/spaceclub/event/domain/Event.java index cfe9e1dd..bf1ad5d8 100644 --- a/src/main/java/com/spaceclub/event/domain/Event.java +++ b/src/main/java/com/spaceclub/event/domain/Event.java @@ -26,6 +26,7 @@ public class Event extends BaseTimeEntity { @Enumerated(EnumType.STRING) private Category category; + @Getter @Embedded private EventInfo eventInfo; @@ -38,10 +39,11 @@ public class Event extends BaseTimeEntity { @Embedded private FormInfo formInfo; + @Getter private Long clubId; @Builder - public Event(Category category, + private Event(Category category, EventInfo eventInfo, BankInfo bankInfo, TicketInfo ticketInfo, @@ -55,4 +57,9 @@ public Event(Category category, this.clubId = clubId; } + public String getClubHost() { + // TODO Club과 연관관계 설정 후 HOST (주최자) 반환하는 메서드 + return "host"; + } + } diff --git a/src/main/java/com/spaceclub/event/domain/EventInfo.java b/src/main/java/com/spaceclub/event/domain/EventInfo.java index 00c1d25b..4c398311 100644 --- a/src/main/java/com/spaceclub/event/domain/EventInfo.java +++ b/src/main/java/com/spaceclub/event/domain/EventInfo.java @@ -4,6 +4,7 @@ import lombok.AccessLevel; import lombok.Builder; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.NoArgsConstructor; import java.time.LocalDate; @@ -13,12 +14,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class EventInfo { + @Getter private String title; + @Getter private String content; private LocalDate startDate; + @Getter private String location; private int capacity; @@ -26,7 +30,7 @@ public class EventInfo { private String poster; @Builder - public EventInfo(String title, String content, LocalDate startDate, String location, int capacity, String poster) { + private EventInfo(String title, String content, LocalDate startDate, String location, int capacity, String poster) { this.title = title; this.content = content; this.startDate = startDate; diff --git a/src/main/java/com/spaceclub/user/controller/UserController.java b/src/main/java/com/spaceclub/user/controller/UserController.java new file mode 100644 index 00000000..6c9537c4 --- /dev/null +++ b/src/main/java/com/spaceclub/user/controller/UserController.java @@ -0,0 +1,35 @@ +package com.spaceclub.user.controller; + +import com.spaceclub.event.domain.Event; +import com.spaceclub.user.controller.dto.EventPageResponse; +import com.spaceclub.user.controller.dto.EventResponse; +import com.spaceclub.user.service.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/users") +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; + + @GetMapping("/{userId}/events") + public EventPageResponse getAllEvents(@PathVariable Long userId, Pageable pageable) { + Page eventPages = userService.findAllEventPages(userId, pageable); + List eventResponses = eventPages.getContent() + .stream() + .map(EventResponse::from) + .toList(); + + return new EventPageResponse<>(eventResponses, eventPages); + } + +} diff --git a/src/main/java/com/spaceclub/user/controller/dto/EventPageResponse.java b/src/main/java/com/spaceclub/user/controller/dto/EventPageResponse.java new file mode 100644 index 00000000..1a153237 --- /dev/null +++ b/src/main/java/com/spaceclub/user/controller/dto/EventPageResponse.java @@ -0,0 +1,38 @@ +package com.spaceclub.user.controller.dto; + +import org.springframework.data.domain.Page; + +import java.util.List; + +public record EventPageResponse( + List data, + PageableResponse pageData +) { + + public EventPageResponse(List data, Page page) { + this(data, new PageableResponse<>(page)); + } + + private record PageableResponse( + boolean first, + boolean last, + int pageNumber, + int size, + int totalPages, + long totalElements + ) { + + public PageableResponse(Page page) { + this( + page.isFirst(), + page.isLast(), + page.getNumber(), + page.getSize(), + page.getTotalPages(), + page.getTotalElements() + ); + } + + } + +} diff --git a/src/main/java/com/spaceclub/user/controller/dto/EventResponse.java b/src/main/java/com/spaceclub/user/controller/dto/EventResponse.java new file mode 100644 index 00000000..1714c493 --- /dev/null +++ b/src/main/java/com/spaceclub/user/controller/dto/EventResponse.java @@ -0,0 +1,16 @@ +package com.spaceclub.user.controller.dto; + +import com.spaceclub.event.domain.Event; + +public record EventResponse(Long id, String title, String location, String host) { + + public static EventResponse from(Event event) { + return new EventResponse( + event.getId(), + event.getEventInfo().getTitle(), + event.getEventInfo().getLocation(), + event.getClubHost() + ); + } + +} diff --git a/src/main/java/com/spaceclub/user/service/UserService.java b/src/main/java/com/spaceclub/user/service/UserService.java new file mode 100644 index 00000000..3767e9ff --- /dev/null +++ b/src/main/java/com/spaceclub/user/service/UserService.java @@ -0,0 +1,13 @@ +package com.spaceclub.user.service; + +import com.spaceclub.event.domain.Event; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +@Service +public interface UserService { + + Page findAllEventPages(Long userId, Pageable pageable); + +}