Skip to content

Commit

Permalink
[feature/Inhabas#252] [내 정보] 내가 쓴 게시글, 댓글, 예산신청 목록 조회 기능 구현
Browse files Browse the repository at this point in the history
[feature/Inhabas#252] [내 정보] 내가 쓴 게시글, 댓글, 예산신청 목록 조회 기능 구현
  • Loading branch information
whitem4rk authored Mar 24, 2024
2 parents 31d4637 + 2ca304c commit e625dd8
Show file tree
Hide file tree
Showing 19 changed files with 963 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class BudgetSupportApplication extends BaseBoard {
@Column(name = "DATE_CHECKED", columnDefinition = "DATETIME(0)")
private LocalDateTime dateChecked;

@Column(name = "DATE_DEPOSITED", columnDefinition = "DATETIME(0)")
private LocalDateTime dateDeposited;

public String getDetails() {
return details.getValue();
}
Expand Down Expand Up @@ -151,6 +154,7 @@ public void reject(String reason, Member memberInCharge) {
public void complete(Member memberInCharge) {
if (this.isApproved()) {
this.status = RequestStatus.COMPLETED;
this.dateDeposited = LocalDateTime.now();
this.memberInCharge = memberInCharge;
} else {
throw new StatusNotFollowProceduresException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.persistence.*;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class Comment extends BaseEntity {
private Boolean isDeleted = false;

/* constructor */

@Builder
public Comment(String content, Member writer, BaseBoard parentBoard) {
this.content = new Content(content);
this.writtenBy(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Menu extends BaseEntity {
@Embedded private MenuName name;

@Enumerated(EnumType.STRING)
@Column(name = "TYPE", length = 20, nullable = false)
@Column(name = "TYPE", length = 50, nullable = false)
private MenuType type;

@Embedded private Description description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.inhabas.api.domain.myInfo.dto;

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;

@NoArgsConstructor
@Getter
public class MyBoardDto {

// 게시글 id
@NotNull @Positive private Long id;

@NotNull private Integer menuId;

@NotNull private String menuName;

@NotBlank private String title;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
private LocalDateTime dateCreated;

@Builder
public MyBoardDto(
Long id, Integer menuId, String menuName, String title, LocalDateTime dateCreated) {
this.id = id;
this.menuId = menuId;
this.menuName = menuName;
this.title = title;
this.dateCreated = dateCreated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.inhabas.api.domain.myInfo.dto;

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.RequestStatus;
import io.swagger.v3.oas.annotations.media.Schema;

@Getter
@NoArgsConstructor
public class MyBudgetSupportApplicationDto {

@NotNull private Long id;

@NotNull private RequestStatus status;

@NotBlank private String title;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
private LocalDateTime dateCreated;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
private LocalDateTime dateChecked;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
private LocalDateTime dateDeposited;

@Builder
public MyBudgetSupportApplicationDto(
Long id,
RequestStatus status,
String title,
LocalDateTime dateCreated,
LocalDateTime dateChecked,
LocalDateTime dateDeposited) {
this.id = id;
this.status = status;
this.title = title;
this.dateCreated = dateCreated;
this.dateChecked = dateChecked;
this.dateDeposited = dateDeposited;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.inhabas.api.domain.myInfo.dto;

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;

@NoArgsConstructor
@Getter
public class MyCommentDto {

// ParentsBoard의 게시판 id
@NotNull @Positive private Long id;

// ParentsBoard의 menuId
@NotNull private Integer menuId;

// ParentsBoard의 메뉴 이름
@NotNull private String menuName;

// 댓글의 내용
@NotBlank private String content;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
private LocalDateTime dateCreated;

@Builder
public MyCommentDto(
Long id, Integer menuId, String menuName, String content, LocalDateTime dateCreated) {
this.id = id;
this.menuId = menuId;
this.menuName = menuName;
this.content = content;
this.dateCreated = dateCreated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.inhabas.api.domain.myInfo.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.inhabas.api.domain.normalBoard.domain.NormalBoard;

public interface MyInfoRepository
extends JpaRepository<NormalBoard, Long>, MyInfoRepositoryCustom {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.inhabas.api.domain.myInfo.repository;

import java.util.List;

import com.inhabas.api.domain.myInfo.dto.MyBoardDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentDto;

public interface MyInfoRepositoryCustom {

List<MyBoardDto> findAllBoardsByMemberId(Long memberId);

List<MyCommentDto> findAllCommentsByMemberId(Long memberId);

List<MyBudgetSupportApplicationDto> findAllBudgetSupportApplicationsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.inhabas.api.domain.myInfo.repository;

import static com.inhabas.api.domain.board.domain.QBaseBoard.baseBoard;
import static com.inhabas.api.domain.budget.domain.QBudgetSupportApplication.budgetSupportApplication;
import static com.inhabas.api.domain.comment.domain.QComment.comment;

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

import lombok.RequiredArgsConstructor;

import com.inhabas.api.domain.budget.domain.BudgetSupportApplication;
import com.inhabas.api.domain.comment.domain.Comment;
import com.inhabas.api.domain.myInfo.dto.MyBoardDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentDto;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;

@RequiredArgsConstructor
public class MyInfoRepositoryImpl implements MyInfoRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public List<MyBoardDto> findAllBoardsByMemberId(Long memberId) {
return queryFactory
.select(
Projections.constructor(
MyBoardDto.class,
baseBoard.id,
baseBoard.menu.id,
baseBoard.menu.name.value,
baseBoard.title.value,
baseBoard.dateCreated))
.from(baseBoard)
.where(
baseBoard
.writer
.id
.eq(memberId)
// budgetSupportApplication은 예산신청 조회가 따로 있으므로, 게시판 조회 범주에서 제외
.and(baseBoard.instanceOf(BudgetSupportApplication.class).not()))
.orderBy(baseBoard.dateCreated.desc())
.fetch();
}

@Override
public List<MyCommentDto> findAllCommentsByMemberId(Long memberId) {
List<Comment> comments =
queryFactory
.selectFrom(comment)
.where(comment.writer.id.eq(memberId))
.orderBy(comment.dateCreated.desc())
.fetch();

return comments.stream()
.map(
comment ->
new MyCommentDto(
comment.getParentBoard().getId(),
comment.getParentBoard().getMenu().getId(),
comment.getParentBoard().getMenu().getName(),
comment.getContent(),
comment.getDateCreated()))
.collect(Collectors.toList());
}

@Override
public List<MyBudgetSupportApplicationDto> findAllBudgetSupportApplicationsByMemberId(
Long memberId) {
return queryFactory
.select(
Projections.constructor(
MyBudgetSupportApplicationDto.class,
budgetSupportApplication.id,
budgetSupportApplication.status,
budgetSupportApplication.title.value,
budgetSupportApplication.dateCreated,
budgetSupportApplication.dateChecked,
budgetSupportApplication.dateDeposited))
.from(budgetSupportApplication)
.where(budgetSupportApplication.applicant.id.eq(memberId))
.orderBy(budgetSupportApplication.dateCreated.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.inhabas.api.domain.myInfo.usecase;

import java.util.List;

import com.inhabas.api.domain.myInfo.dto.MyBoardDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentDto;

public interface MyInfoService {
List<MyBoardDto> getMyBoards(Long memberId);

List<MyCommentDto> getMyComments(Long memberId);

List<MyBudgetSupportApplicationDto> getMyBudgetSupportApplications(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.inhabas.api.domain.myInfo.usecase;

import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.inhabas.api.domain.myInfo.dto.MyBoardDto;
import com.inhabas.api.domain.myInfo.dto.MyBudgetSupportApplicationDto;
import com.inhabas.api.domain.myInfo.dto.MyCommentDto;
import com.inhabas.api.domain.myInfo.repository.MyInfoRepository;

@Service
@Slf4j
@RequiredArgsConstructor
public class MyInfoServiceImpl implements MyInfoService {

private final MyInfoRepository myInfoRepository;

// 현재 로그인한 유저의 모든 게시글을 불러온다.
@Override
@Transactional(readOnly = true)
public List<MyBoardDto> getMyBoards(Long memberId) {

List<MyBoardDto> myBoardDtoList = new ArrayList<>();

myBoardDtoList.addAll(myInfoRepository.findAllBoardsByMemberId(memberId));

return myBoardDtoList;
}

// 현재 로그인한 유저의 모든 댓글을 불러온다.
@Override
@Transactional(readOnly = true)
public List<MyCommentDto> getMyComments(Long memberId) {

List<MyCommentDto> myCommentDtoList = new ArrayList<>();

myCommentDtoList.addAll(myInfoRepository.findAllCommentsByMemberId(memberId));

return myCommentDtoList;
}

// 현재 로그인한 유저의 모든 예산 신청 내역을 불러온다.
@Override
@Transactional(readOnly = true)
public List<MyBudgetSupportApplicationDto> getMyBudgetSupportApplications(Long memberId) {

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

budgetSupportApplicationDtoList.addAll(
myInfoRepository.findAllBudgetSupportApplicationsByMemberId(memberId));

return budgetSupportApplicationDtoList;
}
}
Loading

0 comments on commit e625dd8

Please sign in to comment.