Skip to content

Commit

Permalink
[feature/Inhabas#252] 내가 쓴 예산신청내역 controller 구현 및 리펙토링
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 committed Mar 19, 2024
1 parent 3380b24 commit 4191092
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@NoArgsConstructor
@Getter
public class MyPostsDto {
public class MyBoardsDto {

// 게시글 id
@NotNull @Positive private Long id;
Expand All @@ -28,7 +28,7 @@ public class MyPostsDto {
String dateCreated;

@Builder
MyPostsDto(Long id, String menuName, String title, String dateCreated) {
MyBoardsDto(Long id, String menuName, String title, String dateCreated) {
this.id = id;
this.menuName = menuName;
this.title = title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.List;

import com.inhabas.api.domain.myInfo.dto.MyBoardsDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentsDto;
import com.inhabas.api.domain.myInfo.dto.MyPostsDto;

public interface MyInfoRepositoryCustom {

List<MyPostsDto> findAllBoardsByMemberId(Long memberId);
List<MyBoardsDto> findAllBoardsByMemberId(Long memberId);

List<MyCommentsDto> findAllCommentsByMemberId(Long memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import lombok.RequiredArgsConstructor;

import com.inhabas.api.domain.myInfo.dto.MyBoardsDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentsDto;
import com.inhabas.api.domain.myInfo.dto.MyPostsDto;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;

Expand All @@ -20,11 +20,11 @@ public class MyInfoRepositoryImpl implements MyInfoRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<MyPostsDto> findAllBoardsByMemberId(Long memberId) {
public List<MyBoardsDto> findAllBoardsByMemberId(Long memberId) {
return queryFactory
.select(
Projections.constructor(
MyPostsDto.class,
MyBoardsDto.class,
baseBoard.id,
baseBoard.menu.id,
baseBoard.menu.name.value,
Expand Down Expand Up @@ -60,6 +60,7 @@ public List<MyBudgetSupportApplicationDto> findAllBudgetSupportAllpicationByMemb
.select(
Projections.constructor(
MyBudgetSupportApplicationDto.class,
budgetSupportApplication.id,
budgetSupportApplication.status,
budgetSupportApplication.title.value,
budgetSupportApplication.dateCreated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import java.util.List;

import com.inhabas.api.domain.myInfo.dto.MyBoardsDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentsDto;
import com.inhabas.api.domain.myInfo.dto.MyPostsDto;

public interface MyInfoService {
List<MyPostsDto> getMyBoards();
List<MyBoardsDto> getMyBoards();

List<MyCommentsDto> getMyComments();

List<MyBudgetSupportApplicationDto> getMyBudgetApplicationSupports();
List<MyBudgetSupportApplicationDto> getMyBudgetSupportApplications();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.springframework.transaction.annotation.Transactional;

import com.inhabas.api.auth.domain.error.authException.InvalidAuthorityException;
import com.inhabas.api.domain.myInfo.dto.MyBoardsDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentsDto;
import com.inhabas.api.domain.myInfo.dto.MyPostsDto;
import com.inhabas.api.domain.myInfo.repository.MyInfoRepository;

@Service
Expand All @@ -26,21 +26,21 @@ public class MyInfoServiceImpl implements MyInfoService {
// 현재 로그인한 유저의 모든 게시글을 불러온다.
@Override
@Transactional(readOnly = true)
public List<MyPostsDto> getMyBoards() {
public List<MyBoardsDto> getMyBoards() {

List<MyPostsDto> myPostsDtoList = new ArrayList<>();
List<MyBoardsDto> myBoardsDtoList = new ArrayList<>();

if (SecurityContextHolder.getContext() == null) {
throw new InvalidAuthorityException();
}
Long memberId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

myPostsDtoList.addAll(myInfoRepository.findAllBoardsByMemberId(memberId));
myBoardsDtoList.addAll(myInfoRepository.findAllBoardsByMemberId(memberId));
if (SecurityContextHolder.getContext() == null) {
throw new InvalidAuthorityException();
}

return myPostsDtoList;
return myBoardsDtoList;
}

// 현재 로그인한 유저의 모든 댓글을 불러온다.
Expand All @@ -66,7 +66,7 @@ public List<MyCommentsDto> getMyComments() {
// 현재 로그인한 유저의 모든 예산 신청 내역을 불러온다.
@Override
@Transactional(readOnly = true)
public List<MyBudgetSupportApplicationDto> getMyBudgetApplicationSupports() {
public List<MyBudgetSupportApplicationDto> getMyBudgetSupportApplications() {

List<MyBudgetSupportApplicationDto> budgetSupportApplicationDtoList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import com.inhabas.api.auth.domain.error.ErrorResponse;
import com.inhabas.api.auth.domain.oauth2.member.dto.*;
import com.inhabas.api.domain.member.usecase.MemberProfileService;
import com.inhabas.api.domain.myInfo.dto.MyBoardsDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentsDto;
import com.inhabas.api.domain.myInfo.usecase.MyInfoService;
import com.inhabas.api.global.dto.PageInfoDto;
import com.inhabas.api.global.dto.PagedResponseDto;
import com.inhabas.api.global.util.PageUtil;
Expand All @@ -38,6 +42,7 @@
public class MyProfileController {

private final MemberProfileService memberProfileService;
private final MyInfoService myInfoService;

@Operation(summary = "내 정보 조회", description = "사용자 자신의 정보만 조회 가능")
@ApiResponses(
Expand Down Expand Up @@ -227,4 +232,82 @@ public ResponseEntity<Void> handleMyInfoRequest(

// [모임, 글, 댓글, 예산신청 조회] 추후 개발 예정

@Operation(summary = "내가 쓴 게시글 목록 조회")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = {@Content(schema = @Schema(implementation = UpdateNameRequestDto.class))}),
})
@GetMapping("/myInfo/boards")
public ResponseEntity<PagedResponseDto<MyBoardsDto>> getBoardList(
@Parameter(description = "페이지", example = "0")
@RequestParam(name = "page", defaultValue = "0")
int page,
@Parameter(description = "페이지당 개수", example = "10")
@RequestParam(name = "size", defaultValue = "10")
int size,
@Authenticated Long memberId) {

Pageable pageable = PageRequest.of(page, size);
List<MyBoardsDto> allDtoList = myInfoService.getMyBoards();
List<MyBoardsDto> pagedDtoList = PageUtil.getPagedDtoList(pageable, allDtoList);

PageImpl<MyBoardsDto> myBoardsDtoPage =
new PageImpl<>(pagedDtoList, pageable, allDtoList.size());
PageInfoDto pageInfoDto = new PageInfoDto(myBoardsDtoPage);

return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtoList));
}

@Operation(summary = "내가 쓴 댓글 목록 조회")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = {@Content(schema = @Schema(implementation = UpdateNameRequestDto.class))}),
})
@GetMapping("/myInfo/comments")
public ResponseEntity<PagedResponseDto<MyCommentsDto>> getCommentsList(
@Parameter(description = "페이지", example = "0")
@RequestParam(name = "page", defaultValue = "0")
int page,
@Parameter(description = "페이지당 개수", example = "10")
@RequestParam(name = "size", defaultValue = "10")
int size,
@Authenticated Long memberId) {

Pageable pageable = PageRequest.of(page, size);
List<MyCommentsDto> allDtoList = myInfoService.getMyComments();
List<MyCommentsDto> pagedDtoList = PageUtil.getPagedDtoList(pageable, allDtoList);

PageImpl<MyCommentsDto> myCommentsDtoPage =
new PageImpl<>(pagedDtoList, pageable, allDtoList.size());
PageInfoDto pageInfoDto = new PageInfoDto(myCommentsDtoPage);

return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtoList));
}

@GetMapping("/myInfo/budgetSupportApplications")
public ResponseEntity<PagedResponseDto<MyBudgetSupportApplicationDto>>
getBudgetSupportApplicationsList(
@Parameter(description = "페이지", example = "0")
@RequestParam(name = "page", defaultValue = "0")
int page,
@Parameter(description = "페이지당 개수", example = "10")
@RequestParam(name = "size", defaultValue = "10")
int size,
@Authenticated Long memberId) {

Pageable pageable = PageRequest.of(page, size);
List<MyBudgetSupportApplicationDto> allDtoList = myInfoService.getMyBudgetSupportApplications();
List<MyBudgetSupportApplicationDto> pagedDtoList =
PageUtil.getPagedDtoList(pageable, allDtoList);

PageImpl<MyBudgetSupportApplicationDto> myBudgetSupportApplicationDtoPage =
new PageImpl<>(pagedDtoList, pageable, allDtoList.size());
PageInfoDto pageInfoDto = new PageInfoDto(myBudgetSupportApplicationDtoPage);

return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtoList));
}
}

0 comments on commit 4191092

Please sign in to comment.