Skip to content

Commit

Permalink
[SKRB-165] feat: 일반 사용자가 행사 참여 신청 현황 확인 기능을 위한 DTO 및 컨트롤러 생성 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho authored Oct 27, 2023
1 parent 9eb157f commit 686151d
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
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/v1/users")
@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);

}

0 comments on commit 686151d

Please sign in to comment.