Skip to content

Commit

Permalink
✨ [FEAT] 페이지네이션 #10
Browse files Browse the repository at this point in the history
  • Loading branch information
7beunseo committed Nov 27, 2024
1 parent ebf09a0 commit 00721fa
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 46 deletions.
64 changes: 32 additions & 32 deletions spring/src/main/java/umc/spring/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,38 @@ public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public CommandLineRunner run(ApplicationContext context) {
return args -> {
// 내가 진행중, 진행 완료한 미션 모아서 보는 쿼리(페이징 포함)
MissionQueryServiceImpl missionService = context.getBean(MissionQueryServiceImpl.class);

String username = "eunseo";

missionService.findUserMission(username, MissionStatus.INPROGRESS, 0, 5)
.forEach(System.out::println);


// 리뷰 작성하는 쿼리,
//* 사진의 경우는 일단 배제
CommentQueryServiceImpl commentService = context.getBean(CommentQueryServiceImpl.class);

System.out.println(commentService.createComment(username, 1L, "너무좋아요", 4.5f));


// 홈 화면 쿼리
//(현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함)
Long regionId = 1L;
missionService.findMissionByLocation(username, regionId, 0, 5)
.forEach(System.out::println);

// 마이 페이지 화면 쿼리
UserQueryServiceImpl userService = context.getBean(UserQueryServiceImpl.class);

System.out.println(userService.getUserInfo(username));

};
}
// @Bean
// public CommandLineRunner run(ApplicationContext context) {
// return args -> {
// // 내가 진행중, 진행 완료한 미션 모아서 보는 쿼리(페이징 포함)
// MissionQueryServiceImpl missionService = context.getBean(MissionQueryServiceImpl.class);
//
// String username = "eunseo";
//
// missionService.findUserMission(username, MissionStatus.INPROGRESS, 0, 5)
// .forEach(System.out::println);
//
//
// // 리뷰 작성하는 쿼리,
// //* 사진의 경우는 일단 배제
// CommentQueryServiceImpl commentService = context.getBean(CommentQueryServiceImpl.class);
//
// System.out.println(commentService.createComment(username, 1L, "너무좋아요", 4.5f));
//
//
// // 홈 화면 쿼리
// //(현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함)
// Long regionId = 1L;
// missionService.findMissionByLocation(username, regionId, 0, 5)
// .forEach(System.out::println);
//
// // 마이 페이지 화면 쿼리
// UserQueryServiceImpl userService = context.getBean(UserQueryServiceImpl.class);
//
// System.out.println(userService.getUserInfo(username));
//
// };
// }
}


Expand Down
37 changes: 33 additions & 4 deletions spring/src/main/java/umc/spring/controller/CommentController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package umc.spring.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import umc.spring.apiPayload.ApiResponse;
import umc.spring.converter.CommentConverter.CommentConverter;
import umc.spring.converter.MarketConverter.MarketConverter;
Expand All @@ -16,6 +20,9 @@
import umc.spring.dto.market.MarketRequestDTO;
import umc.spring.dto.market.MarketResponseDTO;
import umc.spring.service.CommentService.CommentService;
import umc.spring.validation.annotation.CheckPage;

import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -30,4 +37,26 @@ public ApiResponse<CommentResponseDTO.createResponseDTO> createComment(@RequestB
return ApiResponse.onSuccess(CommentConverter.toCreateResponseDTO(comment));
}

// 내가 작성한 리뷰 목록 API (페이징)
@Operation(summary = "내가 작성한 리뷰 목록 조회 API",description = "내가 작성한 리뷰를 조회하는 API이며, 페이징을 포함합니다. query String 으로 page 번호를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
// 계속 userId를 파라미터로 인식해서 주석처리
// @Parameters({
// @Parameter(name = "userId", description = "유저의 아이디, path variable 입니다! (토큰이 없어서 임시로 이걸로 받음)")
// })
@GetMapping("/{userId}")
public ApiResponse<CommentResponseDTO.myCommentListDTO> myComment(
@PathVariable("userId") Long userId,
@RequestParam("page") @CheckPage int page
) {
Page<Comment> comments = commentService.getMyCommentList(userId, page);
return ApiResponse.onSuccess(CommentConverter.myCommentListDTO(comments));
}


}
33 changes: 33 additions & 0 deletions spring/src/main/java/umc/spring/controller/MarketController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package umc.spring.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.hibernate.annotations.Check;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import umc.spring.apiPayload.ApiResponse;
import umc.spring.converter.CommentConverter.CommentConverter;
import umc.spring.converter.MarketConverter.MarketConverter;
import umc.spring.converter.MissionConverter.MissionConverter;
import umc.spring.domain.Comment;
import umc.spring.domain.Market;
import umc.spring.domain.Mission;
import umc.spring.dto.market.MarketRequestDTO;
import umc.spring.dto.market.MarketResponseDTO;
import umc.spring.dto.mission.MissionResponseDTO;
import umc.spring.service.LocationService.MarketServiceImpl;
import umc.spring.validation.annotation.CheckPage;

@RestController
@RequiredArgsConstructor
Expand All @@ -21,4 +33,25 @@ public ApiResponse<MarketResponseDTO.createResponseDTO> createMarket(@RequestBod
Market market = marketService.createMarket(request);
return ApiResponse.onSuccess(MarketConverter.toCreateResponseDTO(market));
}

// 내가 작성한 리뷰 목록 API (페이징)
@Operation(summary = "market에 해당하는 미션 조회 API",description = "market id에 해당하는 미션을 조회하는 API이며, 페이징을 포함합니다. query String 으로 page 번호를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MARKET001", description = "가게를 찾을 수 없습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
// @Parameters({
// @Parameter(name = "userId", description = "유저의 아이디, path variable 입니다! (토큰이 없어서 임시로 이걸로 받음)")
// })
@GetMapping("/mission/{marketId}")
public ApiResponse<MissionResponseDTO.marketMissionListResponseDTO> marketMission(
@PathVariable("marketId") Long marketId,
@RequestParam("page") @CheckPage int page
){
Page<Mission> missions = marketService.getMarketMission(marketId, page);
return ApiResponse.onSuccess(MissionConverter.marketMissionListResponseDTO(missions));
}
}
29 changes: 25 additions & 4 deletions spring/src/main/java/umc/spring/controller/MissionController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package umc.spring.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import umc.spring.apiPayload.ApiResponse;
import umc.spring.converter.MarketConverter.MarketConverter;
import umc.spring.converter.MissionConverter.MissionConverter;
Expand All @@ -16,6 +18,7 @@
import umc.spring.dto.mission.MissionRequestDTO;
import umc.spring.dto.mission.MissionResponseDTO;
import umc.spring.service.MissionService.MissionService;
import umc.spring.validation.annotation.CheckPage;

@RestController
@RequiredArgsConstructor
Expand All @@ -29,4 +32,22 @@ public ApiResponse<MissionResponseDTO.createResponseDTO> createMission(@RequestB
Mission mission = missionService.createMission(request);
return ApiResponse.onSuccess(MissionConverter.toCreateResponseDTO(mission));
}

// 내가 진행중인 미션 목록
@Operation(summary = "내가 진행중인 미션 조회 API",description = "내가 진행중인 미션을 조회하는 API이며, 페이징을 포함합니다. query String 으로 page 번호를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER001", description = "유저를 찾을 수 없습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
@GetMapping("/in-progress/{userId}")
public ApiResponse<MissionResponseDTO.marketMissionListResponseDTO> marketMission(
@PathVariable("userId") Long userId,
@RequestParam("page") @CheckPage int page
){
Page<Mission> missions = missionService.getMarketMission(userId, page);
return ApiResponse.onSuccess(MissionConverter.marketMissionListResponseDTO(missions));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package umc.spring.converter.CommentConverter;

import org.springframework.data.domain.Page;
import umc.spring.domain.Comment;
import umc.spring.dto.comment.CommentRequestDTO;
import umc.spring.dto.comment.CommentResponseDTO;

import java.util.List;
import java.util.stream.Collectors;

public class CommentConverter {

public static Comment toComment(CommentRequestDTO.createDTO request) {
Expand All @@ -20,4 +24,28 @@ public static CommentResponseDTO.createResponseDTO toCreateResponseDTO(Comment c
.content(comment.getContent())
.build();
}

public static CommentResponseDTO.myCommentDTO myCommentDTO(Comment comment) {
return CommentResponseDTO.myCommentDTO.builder()
.id(comment.getId())
.writer(comment.getWriter())
.marketName(comment.getMarket().getName())
.star(comment.getStar())
.content(comment.getContent())
.build();
}

public static CommentResponseDTO.myCommentListDTO myCommentListDTO (Page<Comment> comments) {
List<CommentResponseDTO.myCommentDTO> commentDTOList = comments.stream()
.map(CommentConverter::myCommentDTO).toList();

return CommentResponseDTO.myCommentListDTO.builder()
.isFirst(comments.isFirst())
.isLast(comments.isLast())
.totalPage(comments.getTotalPages())
.totalElements(comments.getTotalElements())
.listSize(commentDTOList.size())
.commentList(commentDTOList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package umc.spring.converter.MissionConverter;

import org.springframework.data.domain.Page;
import umc.spring.converter.CommentConverter.CommentConverter;
import umc.spring.domain.Mission;
import umc.spring.dto.comment.CommentResponseDTO;
import umc.spring.dto.mission.MissionRequestDTO;
import umc.spring.dto.mission.MissionResponseDTO;

import java.util.List;

public class MissionConverter {

public static Mission toMission(MissionRequestDTO.createDTO request) {
Expand All @@ -19,4 +24,27 @@ public static MissionResponseDTO.createResponseDTO toCreateResponseDTO(Mission m
.point(mission.getPoint())
.build();
}

public static MissionResponseDTO.missionMissionResponseDTO missionMissionResponseDTO(Mission mission) {
return MissionResponseDTO.missionMissionResponseDTO.builder()
.id(mission.getId())
.endDate(mission.getEndDate())
.point(mission.getPoint())
.content(mission.getContent())
.build();
}

public static MissionResponseDTO.marketMissionListResponseDTO marketMissionListResponseDTO(Page<Mission> missionPage) {
List<MissionResponseDTO.missionMissionResponseDTO> missionMissionResponseDTOS = missionPage.stream()
.map(MissionConverter::missionMissionResponseDTO).toList();

return MissionResponseDTO.marketMissionListResponseDTO.builder()
.isFirst(missionPage.isFirst())
.isLast(missionPage.isLast())
.totalPage(missionPage.getTotalPages())
.totalElements(missionPage.getTotalElements())
.listSize(missionMissionResponseDTOS.size())
.marketMissionResponseDTO(missionMissionResponseDTOS)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package umc.spring.dto.comment;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import jakarta.persistence.*;
import lombok.*;
import umc.spring.domain.Market;
import umc.spring.domain.User;

import java.util.List;

public class CommentResponseDTO {

Expand All @@ -16,4 +18,29 @@ public static class createResponseDTO {
private Float star;
private String content;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class myCommentListDTO {
List<myCommentDTO> commentList;
Integer listSize;
Integer totalPage;
Long totalElements;
Boolean isFirst;
Boolean isLast;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class myCommentDTO {
private Long id;
private String writer;
private Float star;
private String content;
private String marketName;
}
}
Loading

0 comments on commit 00721fa

Please sign in to comment.