Skip to content

Commit

Permalink
Merge pull request #175 from kakao-tech-campus-2nd-step3/Develop
Browse files Browse the repository at this point in the history
[Master] ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘ ์ˆ˜์ • ๋ฐ ๋‘ ๋ฒˆ ํ˜ธ์ถœ๋  ๊ฒฝ์šฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ
  • Loading branch information
minsu-cnu authored Nov 13, 2024
2 parents 91f1400 + c1fea2b commit 42b1efb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/team18/team18_be/contract/entity/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
Expand All @@ -31,7 +31,7 @@ public class Contract {
private String pdfFileUrl;
private String imageFileUrlV;
private String pdfFileUrlV;
@ManyToOne
@OneToOne
@JoinColumn(name = "applyId")
private Apply apply;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.itextpdf.text.DocumentException;
import jakarta.transaction.Transactional;
import java.io.IOException;
import java.util.Optional;
import org.springframework.stereotype.Service;
import team18.team18_be.apply.ApplyStatusEnum.ApplyStatus;
import team18.team18_be.apply.entity.Apply;
Expand All @@ -15,6 +16,7 @@
import team18.team18_be.contract.dto.response.ContractResponse;
import team18.team18_be.contract.entity.Contract;
import team18.team18_be.contract.repository.ContractRepository;
import team18.team18_be.exception.ContractAlreadyExistsException;
import team18.team18_be.exception.NotFoundException;

@Service
Expand All @@ -36,6 +38,12 @@ public ContractService(ContractRepository contractRepository, ApplyRepository ap
public void handleEmployerContractCreation(ContractRequest request, User user)
throws DocumentException, IOException {

Optional<Contract> optional = contractRepository.findByApplyId(request.applyId());

if (!optional.isEmpty()) {
throw new ContractAlreadyExistsException("์ด๋ฏธ ์ƒ์„ฑ๋œ ๊ทผ๋กœ๊ณ„์•ฝ์„œ์ž…๋‹ˆ๋‹ค.");
}

String dirName = "contracts";
String fileName = user.getId() + "_" + request.applyId() + ".pdf";
String fileNameV = user.getId() + "_" + request.applyId() + "V.pdf";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team18.team18_be.exception;

public class ContractAlreadyExistsException extends RuntimeException {

public ContractAlreadyExistsException() {
}

public ContractAlreadyExistsException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ public ResponseEntity<ExceptionResponse> handleResumeAlreadyExistsException(
ExceptionResponse exceptionResponse = new ExceptionResponse(e.getMessage());
return new ResponseEntity<>(exceptionResponse, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(value = ContractAlreadyExistsException.class)
public ResponseEntity<ExceptionResponse> handleContractAlreadyExistsException(
ContractAlreadyExistsException e) {
ExceptionResponse exceptionResponse = new ExceptionResponse(e.getMessage());
return new ResponseEntity<>(exceptionResponse, HttpStatus.BAD_REQUEST);
}
}

0 comments on commit 42b1efb

Please sign in to comment.