Skip to content

Commit

Permalink
[fix] #28 파일명 수정 및 DecisionService 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
최경환 authored and 최경환 committed Jan 23, 2025
1 parent 3d595dc commit 73d45fa
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import lombok.NoArgsConstructor;

@Entity
@Table(name = "bankAccounts")
@Table(name = "bank_account")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BankAccounts extends BaseTimeEntity {
public class BankAccount extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -37,16 +37,16 @@ public class BankAccounts extends BaseTimeEntity {
private Invitation invitation;

@Builder
private BankAccounts(AccountSide side, String accountNumber, String bankName, String accountHolder, Invitation invitation) {
private BankAccount(AccountSide side, String accountNumber, String bankName, String accountHolder, Invitation invitation) {
this.side = side;
this.accountNumber = accountNumber;
this.bankName = bankName;
this.accountHolder = accountHolder;
this.invitation = invitation;
}

public static BankAccounts createBankAccount(AccountSide side, String accountNumber, String bankName, String accountHolder, Invitation invitation) {
return BankAccounts.builder()
public static BankAccount createBankAccount(AccountSide side, String accountNumber, String bankName, String accountHolder, Invitation invitation) {
return BankAccount.builder()
.side(side)
.accountNumber(accountNumber)
.bankName(bankName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wedit.weditapp.domain.bankAccounts.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import com.wedit.weditapp.domain.bankAccounts.domain.BankAccounts;
import com.wedit.weditapp.domain.bankAccounts.domain.BankAccount;

public interface BankAccountRepository extends JpaRepository<BankAccounts, Long> {
public interface BankAccountRepository extends JpaRepository<BankAccount, Long> {
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wedit.weditapp.domain.bankAccounts.dto;

import com.wedit.weditapp.domain.bankAccounts.domain.BankAccounts;
import com.wedit.weditapp.domain.bankAccounts.domain.BankAccount;
import com.wedit.weditapp.domain.shared.AccountSide;

import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -31,7 +31,7 @@ private BankAccountDTO(AccountSide side, String accountNumber, String bankName,
this.accountHolder = accountHolder;
}

public static BankAccountDTO from(BankAccounts bankAccount) {
public static BankAccountDTO from(BankAccount bankAccount) {
return BankAccountDTO.builder()
.side(bankAccount.getSide())
.accountNumber(bankAccount.getAccountNumber())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.springframework.stereotype.Service;

import com.wedit.weditapp.domain.bankAccounts.domain.BankAccounts;
import com.wedit.weditapp.domain.bankAccounts.domain.BankAccount;
import com.wedit.weditapp.domain.bankAccounts.domain.repository.BankAccountRepository;
import com.wedit.weditapp.domain.bankAccounts.dto.BankAccountDTO;
import com.wedit.weditapp.domain.invitation.domain.Invitation;
Expand All @@ -20,9 +20,9 @@ public class BankAccountService {
private final BankAccountRepository bankAccountRepository;

// DTO 리스트를 엔티티 리스트로 변환하여 저장
public List<BankAccounts> createBankAccounts(List<BankAccountDTO> bankAccountDTOs, Invitation invitation) {
List<BankAccounts> bankAccounts = bankAccountDTOs.stream()
.map(dto -> BankAccounts.createBankAccount(
public List<BankAccount> createBankAccounts(List<BankAccountDTO> bankAccountDTOs, Invitation invitation) {
List<BankAccount> bankAccounts = bankAccountDTOs.stream()
.map(dto -> BankAccount.createBankAccount(
dto.getSide(),
dto.getAccountNumber(),
dto.getBankName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package com.wedit.weditapp.domain.comments.controller;

import com.wedit.weditapp.domain.comments.domain.Comments;
import com.wedit.weditapp.domain.comments.dto.request.CommentCreateRequestDTO;
import com.wedit.weditapp.domain.comments.dto.response.CommentResponseDTO;
import com.wedit.weditapp.domain.comments.dto.response.PagedCommentResponseDTO;
import com.wedit.weditapp.domain.comments.domain.Comment;
import com.wedit.weditapp.domain.comments.dto.request.CommentCreateRequestDto;
import com.wedit.weditapp.domain.comments.dto.response.CommentResponseDto;
import com.wedit.weditapp.domain.comments.dto.response.PagedCommentResponseDto;
import com.wedit.weditapp.domain.comments.service.CommentService;
import com.wedit.weditapp.global.response.GlobalResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comments")
@RequiredArgsConstructor
Expand All @@ -33,11 +30,11 @@ public class CommentController {
@ApiResponse(responseCode = "500", description = "서버 에러")
})
@GetMapping("/{invitationId}")
public ResponseEntity<GlobalResponseDto<PagedCommentResponseDTO>> findAllComments(
public ResponseEntity<GlobalResponseDto<PagedCommentResponseDto>> findAllComments(
@PathVariable Long invitationId,
@RequestParam(defaultValue = "1") int page){

PagedCommentResponseDTO response = commentService.findAllCommentsByInvitationId(invitationId, page);
PagedCommentResponseDto response = commentService.findAllCommentsByInvitationId(invitationId, page);
return ResponseEntity.status(HttpStatus.OK).body(GlobalResponseDto.success(response));
}

Expand All @@ -49,11 +46,11 @@ public ResponseEntity<GlobalResponseDto<PagedCommentResponseDTO>> findAllComment
@ApiResponse(responseCode = "500", description = "서버 에러")
})
@PostMapping
public ResponseEntity<GlobalResponseDto<CommentResponseDTO>> createComment(
@Valid @RequestBody CommentCreateRequestDTO commentCreateRequestDTO) {
Comments createdComment = commentService.createComment(commentCreateRequestDTO);
CommentResponseDTO response = CommentResponseDTO.from(createdComment);
public ResponseEntity<GlobalResponseDto<CommentResponseDto>> createComment(
@Valid @RequestBody CommentCreateRequestDto commentCreateRequestDTO) {

commentService.createComment(commentCreateRequestDTO);

return ResponseEntity.status(HttpStatus.CREATED).body(GlobalResponseDto.success(response));
return ResponseEntity.status(HttpStatus.CREATED).body(GlobalResponseDto.success());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Table(name = "comments")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Comments extends BaseTimeEntity {
public class Comment extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -29,14 +29,14 @@ public class Comments extends BaseTimeEntity {
private Invitation invitation;

@Builder
private Comments(String name, String content, Invitation invitation){
private Comment(String name, String content, Invitation invitation){
this.name = name;
this.content = content;
this.invitation = invitation;
}

public static Comments createComment(String name, String content, Invitation invitation){
return Comments.builder()
public static Comment createComment(String name, String content, Invitation invitation){
return Comment.builder()
.name(name)
.content(content)
.invitation(invitation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.wedit.weditapp.domain.comments.domain.repository;

import com.wedit.weditapp.domain.comments.domain.Comments;
import com.wedit.weditapp.domain.comments.domain.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;


public interface CommentRepository extends JpaRepository<Comments, Long> {
Page<Comments> findByInvitationId(Long invitationId, Pageable pageable);
public interface CommentRepository extends JpaRepository<Comment, Long> {
Page<Comment> findByInvitationId(Long invitationId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.wedit.weditapp.domain.comments.dto.request;

import com.wedit.weditapp.domain.comments.domain.Comments;
import com.wedit.weditapp.domain.invitation.domain.Invitation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CommentCreateRequestDTO {
public class CommentCreateRequestDto {

@NotBlank(message = "이름은 필수입니다.")
private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.wedit.weditapp.domain.comments.dto.response;

import com.wedit.weditapp.domain.comments.domain.Comments;
import com.wedit.weditapp.domain.comments.domain.Comment;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CommentResponseDTO {
public class CommentResponseDto {
private Long commentId;
private String name;
private String content;

@Builder
private CommentResponseDTO(Long commentId, String name, String content){
private CommentResponseDto(Long commentId, String name, String content){
this.commentId = commentId;
this.name = name;
this.content = content;
}

public static CommentResponseDTO from (Comments comment){
return CommentResponseDTO.builder()
public static CommentResponseDto from (Comment comment){
return CommentResponseDto.builder()
.commentId(comment.getId())
.name(comment.getName())
.content(comment.getContent())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package com.wedit.weditapp.domain.comments.dto.response;

import com.wedit.weditapp.domain.comments.domain.Comments;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.List;

@Getter
@NoArgsConstructor
public class PagedCommentResponseDTO {
public class PagedCommentResponseDto {

private List<CommentResponseDTO> comments;
private List<CommentResponseDto> comments;
private Boolean isLast;
private Integer currentPage;

@Builder
private PagedCommentResponseDTO(List<CommentResponseDTO> comments, Boolean isLast, Integer currentPage){
private PagedCommentResponseDto(List<CommentResponseDto> comments, Boolean isLast, Integer currentPage){
this.comments = comments;
this.isLast = isLast;
this.currentPage = currentPage;
}

public static PagedCommentResponseDTO of(Page<CommentResponseDTO> comments, Boolean isLast, Integer currentPage){
return PagedCommentResponseDTO.builder()
public static PagedCommentResponseDto of(Page<CommentResponseDto> comments, Boolean isLast, Integer currentPage){
return PagedCommentResponseDto.builder()
.comments(comments.getContent())
.isLast(isLast)
.currentPage(currentPage)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wedit.weditapp.domain.comments.service;

import com.wedit.weditapp.domain.comments.domain.Comments;
import com.wedit.weditapp.domain.comments.domain.Comment;
import com.wedit.weditapp.domain.comments.domain.repository.CommentRepository;
import com.wedit.weditapp.domain.comments.dto.request.CommentCreateRequestDTO;
import com.wedit.weditapp.domain.comments.dto.response.CommentResponseDTO;
import com.wedit.weditapp.domain.comments.dto.response.PagedCommentResponseDTO;
import com.wedit.weditapp.domain.comments.dto.request.CommentCreateRequestDto;
import com.wedit.weditapp.domain.comments.dto.response.CommentResponseDto;
import com.wedit.weditapp.domain.comments.dto.response.PagedCommentResponseDto;
import com.wedit.weditapp.domain.invitation.domain.Invitation;
import com.wedit.weditapp.domain.invitation.domain.repository.InvitationRepository;
import com.wedit.weditapp.global.error.ErrorCode;
Expand All @@ -17,9 +17,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@RequiredArgsConstructor
@Transactional
Expand All @@ -30,7 +27,7 @@ public class CommentService {
private final CommentRepository commentRepository;
private final InvitationRepository invitationRepository;

public PagedCommentResponseDTO findAllCommentsByInvitationId(Long invitationId, int page){
public PagedCommentResponseDto findAllCommentsByInvitationId(Long invitationId, int page){

// boolean existsInvitation = invitationRepository.existById(invitationId);
// if(!existsInvitation){
Expand All @@ -43,29 +40,29 @@ public PagedCommentResponseDTO findAllCommentsByInvitationId(Long invitationId,


Pageable pageable = PageRequest.of(page - 1, PAGE_SIZE, Sort.by("createdAt").descending());
Page<Comments> commentPage = commentRepository.findByInvitationId(invitationId, pageable);
Page<Comment> commentPage = commentRepository.findByInvitationId(invitationId, pageable);

if(commentPage.isEmpty()){
throw new CommonException(ErrorCode.NO_MORE_COMMENTS);
}

// Comments 엔티티 -> DTO로 변환
Page<CommentResponseDTO> commentDTOPage = commentPage.map(CommentResponseDTO::from);
Page<CommentResponseDto> commentDTOPage = commentPage.map(CommentResponseDto::from);

// 필요한 정보만으로 DTO 생성
return PagedCommentResponseDTO.of(commentDTOPage, commentPage.isLast(), page);
return PagedCommentResponseDto.of(commentDTOPage, commentPage.isLast(), page);


}

// 방명록 등록
public Comments createComment(CommentCreateRequestDTO commentCreateRequestDTO) {
public Comment createComment(CommentCreateRequestDto commentCreateRequestDTO) {

Invitation invitation = invitationRepository.findById(commentCreateRequestDTO.getInvitationId())
.orElseThrow(() -> new CommonException(ErrorCode.INVITATION_NOT_FOUND));


Comments comment = Comments.createComment(
Comment comment = Comment.createComment(
commentCreateRequestDTO.getName(),
commentCreateRequestDTO.getContent(),
invitation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Table(name = "decisions")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Decisions extends BaseTimeEntity {
public class Decision extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -38,15 +38,15 @@ public class Decisions extends BaseTimeEntity {


@Builder
private Decisions(String name, String phoneNumber, Integer addPerson, DecisionSide side){
private Decision(String name, String phoneNumber, Integer addPerson, DecisionSide side){
this.name = name;
this.phoneNumber = phoneNumber;
this.addPerson = addPerson;
this.side = side;
}

public static Decisions createDecision(String name, String phoneNumber, Integer addPerson, DecisionSide side){
return Decisions.builder()
public static Decision createDecision(String name, String phoneNumber, Integer addPerson, DecisionSide side){
return Decision.builder()
.name(name)
.phoneNumber(phoneNumber)
.addPerson(addPerson)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.wedit.weditapp.domain.decisions.domain.repository;

import com.wedit.weditapp.domain.decisions.domain.Decisions;
import com.wedit.weditapp.domain.decisions.domain.Decision;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface DecisionRepository extends JpaRepository<Decisions, Long> {
@Query("select count(d) from Decisions d where d.invitation.id = :invitationId")
Integer getAllDecisionCount(@Param("invitationId") Long invitationId);
public interface DecisionRepository extends JpaRepository<Decision, Long> {
// 총 방명록 수
@Query("SELECT count(d) FROM Decision d WHERE d.invitation.id = :invitationId")
Integer getTotalDecisionCount(@Param("invitationId") Long invitationId);

@Query("select count(d) from Decisions d where d.invitation.id = :invitationId and d.side = 'GROOM'")
// 신랑측 방명록 수
@Query("SELECT count(d) FROM Decision d WHERE d.invitation.id = :invitationId AND d.side = 'GROOM'")
Integer getGroomDecisionCount(@Param("invitationId") Long invitationId);

@Query("select count(d) from Decisions d where d.invitation.id = :invitationId and d.side = 'BRIDE'")
// 신부측 방명록 수
@Query("SELECT count(d) FROM Decision d WHERE d.invitation.id = :invitationId AND d.side = 'BRIDE'")
Integer getBrideDecisionCount(@Param("invitationId") Long invitationId);

}
Loading

0 comments on commit 73d45fa

Please sign in to comment.