-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SKRB-165] feat: 일반 사용자가 행사 참여 신청 현황 확인 기능을 위한 DTO 및 컨트롤러 생성 (#17)
- Loading branch information
1 parent
9eb157f
commit 686151d
Showing
6 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/spaceclub/user/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/spaceclub/user/controller/dto/EventPageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/java/com/spaceclub/user/controller/dto/EventResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |