Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 특정 청첩장에 참석의사 등록 API 구현 #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BankAccount extends BaseTimeEntity {
@Column(nullable = false)
private String accountHolder;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "invitation_id", nullable = false)
private Invitation invitation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface BankAccountRepository extends JpaRepository<BankAccount, Long>
List<BankAccount> findByInvitation(Invitation invitation);

BankAccount findByInvitationAndSide(Invitation invitation, AccountSide side);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.wedit.weditapp.domain.comments.controller;
package com.wedit.weditapp.domain.comment.controller;

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.domain.comment.dto.request.CommentCreateRequestDto;
import com.wedit.weditapp.domain.comment.dto.response.CommentResponseDto;
import com.wedit.weditapp.domain.comment.dto.response.PagedCommentResponseDto;
import com.wedit.weditapp.domain.comment.service.CommentService;
import com.wedit.weditapp.global.response.GlobalResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wedit.weditapp.domain.comments.domain;
package com.wedit.weditapp.domain.comment.domain;

import com.wedit.weditapp.domain.invitation.domain.Invitation;
import com.wedit.weditapp.domain.shared.BaseTimeEntity;
Expand All @@ -24,7 +24,7 @@ public class Comment extends BaseTimeEntity {
@Column(nullable = false)
private String content;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "invitation_id", nullable = false)
private Invitation invitation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.wedit.weditapp.domain.comments.domain.repository;
package com.wedit.weditapp.domain.comment.domain.repository;

import com.wedit.weditapp.domain.comments.domain.Comment;
import com.wedit.weditapp.domain.comment.domain.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


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,4 +1,4 @@
package com.wedit.weditapp.domain.comments.dto.request;
package com.wedit.weditapp.domain.comment.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wedit.weditapp.domain.comments.dto.response;
package com.wedit.weditapp.domain.comment.dto.response;

import com.wedit.weditapp.domain.comments.domain.Comment;
import com.wedit.weditapp.domain.comment.domain.Comment;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wedit.weditapp.domain.comments.dto.response;
package com.wedit.weditapp.domain.comment.dto.response;

import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wedit.weditapp.domain.comments.service;
package com.wedit.weditapp.domain.comment.service;

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.comment.domain.Comment;
import com.wedit.weditapp.domain.comment.domain.repository.CommentRepository;
import com.wedit.weditapp.domain.comment.dto.request.CommentCreateRequestDto;
import com.wedit.weditapp.domain.comment.dto.response.CommentResponseDto;
import com.wedit.weditapp.domain.comment.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 Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.wedit.weditapp.domain.decision.controller;

import com.wedit.weditapp.domain.decision.dto.request.DecisionCreateRequestDto;
import com.wedit.weditapp.domain.decision.dto.response.DecisionResponseDto;
import com.wedit.weditapp.domain.decision.service.DecisionService;
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;

@RestController
@RequestMapping("/api/decisions")
@RequiredArgsConstructor
public class DecisionController {

private final DecisionService decisionService;

// 특정 청첩장에 참석의사 등록 API
@Operation(summary = "참석의사 등록", description = "특정 청첩장에 참석의사를 등록합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "참석의사 등록 성공"),
@ApiResponse(responseCode = "409", description = "청첩장을 찾을 수 없습니다."),
@ApiResponse(responseCode = "500", description = "서버 에러")
})
@PostMapping
public ResponseEntity<GlobalResponseDto<DecisionResponseDto>> createDecision(
@Valid @RequestBody DecisionCreateRequestDto decisionCreateRequestDTO) {

decisionService.createDecision(decisionCreateRequestDTO);

return ResponseEntity.status(HttpStatus.CREATED).body(GlobalResponseDto.success());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wedit.weditapp.domain.decisions.domain;
package com.wedit.weditapp.domain.decision.domain;

import com.wedit.weditapp.domain.invitation.domain.Invitation;
import com.wedit.weditapp.domain.shared.BaseTimeEntity;
Expand Down Expand Up @@ -32,25 +32,27 @@ public class Decision extends BaseTimeEntity {
@Column(name = "side", nullable = false)
private DecisionSide side;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "invitation_id", nullable = false)
private Invitation invitation;


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

public static Decision createDecision(String name, String phoneNumber, Integer addPerson, DecisionSide side){
public static Decision createDecision(String name, String phoneNumber, Integer addPerson, DecisionSide side, Invitation invitation){
return Decision.builder()
.name(name)
.phoneNumber(phoneNumber)
.addPerson(addPerson)
.side(side)
.invitation(invitation)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.wedit.weditapp.domain.decisions.domain.repository;
package com.wedit.weditapp.domain.decision.domain.repository;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wedit.weditapp.domain.decisions.dto.request;
package com.wedit.weditapp.domain.decision.dto.request;

import com.wedit.weditapp.domain.shared.DecisionSide;
import jakarta.validation.constraints.NotBlank;
Expand All @@ -21,4 +21,7 @@ public class DecisionCreateRequestDto {

@NotNull(message = "신랑측인지 신부측인지 선택해주세요.")
private DecisionSide side;

@NotNull(message = "청첩장 ID는 필수입니다.")
private Long invitationId;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wedit.weditapp.domain.decisions.dto.response;
package com.wedit.weditapp.domain.decision.dto.response;

import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wedit.weditapp.domain.decisions.dto.response;
package com.wedit.weditapp.domain.decision.dto.response;

import com.wedit.weditapp.domain.decisions.domain.Decision;
import com.wedit.weditapp.domain.decision.domain.Decision;
import com.wedit.weditapp.domain.shared.DecisionSide;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.wedit.weditapp.domain.decision.service;

import com.wedit.weditapp.domain.decision.domain.Decision;
import com.wedit.weditapp.domain.decision.domain.repository.DecisionRepository;
import com.wedit.weditapp.domain.decision.dto.request.DecisionCreateRequestDto;
import com.wedit.weditapp.domain.decision.dto.response.CountResponseDto;
import com.wedit.weditapp.domain.invitation.domain.Invitation;
import com.wedit.weditapp.domain.invitation.domain.repository.InvitationRepository;
import com.wedit.weditapp.global.error.ErrorCode;
import com.wedit.weditapp.global.error.exception.CommonException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class DecisionService {

private final DecisionRepository decisionRepository;

private final InvitationRepository invitationRepository;

// 특정 청첩장의 참석의사 누계 조회
public CountResponseDto getDecisionCounts(Long invitationId){
// invitationId 유효성 검사
if (invitationId == null || invitationId <= 0){
throw new CommonException(ErrorCode.INVALID_INVITATION_ID);
}

Integer totalCount = decisionRepository.getTotalDecisionCount(invitationId);
Integer groomCount = decisionRepository.getGroomDecisionCount(invitationId);
Integer brideCount = decisionRepository.getBrideDecisionCount(invitationId);

return CountResponseDto.of(totalCount, groomCount, brideCount);
}

// 특정 청첩장에 참석의사 등록
public Decision createDecision(DecisionCreateRequestDto decisionCreateRequestDTO) {

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


Decision decision = Decision.createDecision(
decisionCreateRequestDTO.getName(),
decisionCreateRequestDTO.getPhoneNumber(),
decisionCreateRequestDTO.getAddPerson(),
decisionCreateRequestDTO.getSide(),
invitation
);

return decisionRepository.save(decision);
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import com.wedit.weditapp.domain.image.domain.Image;
import com.wedit.weditapp.domain.invitation.domain.Invitation;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ImageRepository extends JpaRepository<Image, Long> {
// 특정 Invitation의 모든 이미지를 location 순서대로 조회
List<Image> findByInvitation(Invitation invitation);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.UUID;

import org.springframework.data.domain.Pageable;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/wedit/weditapp/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public enum ErrorCode {
INVITATION_NOT_FOUND(404, "INVITATION_NOT_FOUND", "청첩장을 찾을 수 없습니다."),
INVALID_INVITATION_DATE(400, "INVALID_INVITATION_DATE", "유효하지 않은 날짜입니다."),
ACCOUNT_OPTION_REQUIRED(400, "ACCOUNT_OPTION_REQUIRED", "계좌 옵션이 활성화되어야 합니다."),
IMAGE_UPLOAD_FAILED(500, "IMAGE_UPLOAD_FAILED", "이미지 업로드에 실패하였습니다.");
IMAGE_UPLOAD_FAILED(500, "IMAGE_UPLOAD_FAILED", "이미지 업로드에 실패하였습니다."),
INVALID_INVITATION_ID(400, "INVALID_INVITATION_ID", "잘못된 청첩장 id 입니다.");

private final int status;
private final String code;
Expand Down
Loading