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

[SKRB-165] feat: 일반 사용자가 행사 참여 신청 현황 확인 기능을 위한 DTO 생성 #17

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 8 additions & 1 deletion src/main/java/com/spaceclub/event/domain/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Event extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private Category category;

@Getter
@Embedded
private EventInfo eventInfo;

Expand All @@ -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,
Expand All @@ -55,4 +57,9 @@ public Event(Category category,
this.clubId = clubId;
}

public String getClubHost() {
// TODO Club과 연관관계 설정 후 HOST (주최자) 반환하는 메서드
return "host";
}

}
6 changes: 5 additions & 1 deletion src/main/java/com/spaceclub/event/domain/EventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
Expand All @@ -13,20 +14,23 @@
@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;

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;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/spaceclub/user/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -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/users")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 api endpoint 에는 버전 명시가 안되어있어요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하.. 성원님 그래서 이 다음 PR 테스트에서 수정했습니다..
이것 때문에 한두시간 날아갔어요

@RequiredArgsConstructor
public class UserController {

private final UserService userService;

@GetMapping("/{userId}/events")
public EventPageResponse<EventResponse, Event> getAllEvents(@PathVariable Long userId, Pageable pageable) {
Page<Event> eventPages = userService.findAllEventPages(userId, pageable);
List<EventResponse> eventResponses = eventPages.getContent()
.stream()
.map(EventResponse::from)
.toList();

return new EventPageResponse<>(eventResponses, eventPages);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.spaceclub.user.controller.dto;

import org.springframework.data.domain.Page;

import java.util.List;

public record EventPageResponse<T, E>(
List<T> data,
PageableResponse<E> pageData
) {

public EventPageResponse(List<T> data, Page<E> page) {
this(data, new PageableResponse<>(page));
}

private record PageableResponse<E>(
boolean first,
boolean last,
int pageNumber,
int size,
int totalPages,
long totalElements
) {

public PageableResponse(Page<E> page) {
this(
page.isFirst(),
page.isLast(),
page.getNumber(),
page.getSize(),
page.getTotalPages(),
page.getTotalElements()
);
}

}

}
16 changes: 16 additions & 0 deletions src/main/java/com/spaceclub/user/controller/dto/EventResponse.java
Original file line number Diff line number Diff line change
@@ -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()
);
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/spaceclub/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -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<Event> findAllEventPages(Long userId, Pageable pageable);

}