Skip to content

Commit

Permalink
Feature: 브리더 인증받기 및 매칭 신청 api수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suxxxxhyun committed Sep 13, 2023
1 parent 95d7595 commit 447df1e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

Expand All @@ -27,18 +28,21 @@
public class MatchingFormDto {

@Schema(description = "브리더 식별자 id", example = "1")
@NotBlank(message = "브리더 정보는 필수 입력 값입니다.")
@NotNull(message = "브리더 정보는 필수 입력 값입니다.")
private Long breederId;
@NotBlank(message = "강아지 정보는 필수 입력 값입니다.")

@NotNull(message = "강아지 정보는 필수 입력 값입니다.")
@Schema(description = "강아지 식별자 id", example = "1")
private Long dogId;

@NotBlank(message = "문항1은 필수 입력 값입니다.")
@Schema(description = "문항 1", example = "잘 키우겠습니다 ~")
@Size(max = 2000, message = "문항1의 최대 글자수는 2000자입니다.")
private String pledgeContent1;

@NotBlank(message = "문항2는 필수 입력 값입니다.")
@Schema(description = "문항 2", example = "잘 키우겠습니다 ~")
@Size(max = 2000, message = "문항1의 최대 글자수는 2000자입니다.")
@Size(max = 2000, message = "문항2의 최대 글자수는 2000자입니다.")
private String pledgeContent2;

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.petree.domain.member.repository;

import com.example.petree.domain.member.domain.Admin;
import com.example.petree.domain.member.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AdminRepository extends JpaRepository<Admin,Long> {
Admin findByRole(Role role);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import com.example.petree.domain.breeder.domain.Breeder;
import com.example.petree.domain.breeder.repository.BreederRepository;

import com.example.petree.domain.member.domain.Admin;
import com.example.petree.domain.member.domain.Member;

import com.example.petree.domain.member.domain.Role;
import com.example.petree.domain.member.repository.AdminRepository;
import com.example.petree.domain.member.repository.MemberRepository;
import com.example.petree.domain.verification.domain.Certification;
import com.example.petree.domain.verification.domain.Status;
Expand Down Expand Up @@ -60,6 +64,7 @@ public class VerificationController {
private final VerificationService verificationService;
private final BreederRepository breederRepository;
private final MemberRepository memberRepository;
private final AdminRepository adminRepository;
private final Response response;


Expand All @@ -84,10 +89,15 @@ public ResponseEntity<?> addVerification(
}
Breeder breeder = breederRepository.findByEmail(principal.getName()).orElse(null);
if(breeder != null) {
verificationService.addVerification(breeder, verificationFormDto);
return response.success(HttpStatus.OK, verificationFormDto);
}else {
return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "브리더 회원이 아닙니다."));}

Admin admin =adminRepository.findByRole(Role.ADMIN);
if (admin != null) {
verificationService.addVerification(breeder, verificationFormDto, admin);
return response.success(HttpStatus.OK, verificationFormDto);
} else {
return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "관리자를 찾을 수 없습니다."));
}
} else {
return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "브리더 회원이 아닙니다."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public class VerificationRequest {
@OneToMany(mappedBy = "verificationRequest",cascade = CascadeType.ALL)
private List<AttachedFile> verificationFiles = new ArrayList<>();

public VerificationRequest(LocalDate submitDate, Breeder breeder, Admin admin) {
public VerificationRequest(LocalDate submitDate, Breeder breeder) {
this.submitDate= submitDate;
this.breeder=breeder;
this.admin=admin;
}

public void addAttachedFile(AttachedFile attachedFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ public class VerificationFormDto {
//@JsonProperty("breeder_id")
private Long breederId;

@Schema(description = "관리자 식별자 id")
private Long adminId;

@Schema(description = "자격증 분류 선택 (반려동물종합관리사 OR 반려동물행동교정사)",example = "COMPREHENSIVE_PET_MANAGER")
private Certification certification;

@Schema(description = "브리더 증명 파일 업로드 리스트")
@Schema(description = "브리더 증명 파일 업로드")
@JsonSerialize(using = ToStringSerializer.class)
private List<MultipartFile> verificationFiles;
private MultipartFile verificationFiles;


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


import com.example.petree.domain.member.domain.Admin;
import com.example.petree.domain.member.domain.Member;
import com.example.petree.domain.member.repository.AdminRepository;
import com.example.petree.domain.breeder.domain.Breeder;
import com.example.petree.domain.breeder.repository.BreederRepository;
import com.example.petree.domain.member.repository.MemberRepository;
import com.example.petree.domain.verification.domain.*;
import com.example.petree.domain.verification.dto.VerificationFormDto;
import com.example.petree.domain.verification.dto.VerificationListDto;
Expand Down Expand Up @@ -59,7 +61,7 @@ public class VerificationService {
private final VerificationRequestRepository verificationRequestRepository;
private final VerificationApprovalRepository verificationApprovalRepository;
private RequestSpecification requestSpecification;
private final AdminRepository adminRepository;
private final MemberRepository memberRepository;
private final BreederRepository breederRepository;
private final S3Util s3Util;
private final FileUtil fileUtil;
Expand All @@ -76,25 +78,25 @@ public class VerificationService {
*/
// 브리더가 관리자에게 자료를 첨부하여 인증 요청을 보내는 메소드
@Transactional
public void addVerification(Breeder breeder, VerificationFormDto verificationFormDto) {
Admin admin = adminRepository.findById(verificationFormDto.getAdminId())
.orElseThrow(() -> new IllegalArgumentException("관리자에게 요청을 보낼 수 없습니다."));
public void addVerification(Breeder breeder, VerificationFormDto verificationFormDto, Admin admin) {


// 새로운 요청을 생성한다.
VerificationRequest verificationRequest = new VerificationRequest(LocalDate.now(), breeder, admin);
VerificationRequest verificationRequest = new VerificationRequest(LocalDate.now(), breeder);
// 처리 상태는 Watting으로 자동으로 저장한다.
verificationRequest.setStatus(Status.WAITING);

// 파일을 여러 개 첨부한다
for (MultipartFile multipartFile : verificationFormDto.getVerificationFiles()) {
String originalName = multipartFile.getOriginalFilename();
String filename = UUID.randomUUID().toString() + "." + fileUtil.extractExt(originalName);
String res = s3Util.upload(multipartFile, "verification-file", filename);
AttachedFile verificationFiles = new AttachedFile(originalName, filename, res, verificationRequest);
verificationRequest.addAttachedFile(verificationFiles);
verificationRequest.setCertification(verificationFormDto.getCertification());
}

MultipartFile multipartFile = verificationFormDto.getVerificationFiles();
String originalName = multipartFile.getOriginalFilename();
String filename = UUID.randomUUID().toString() + "." + fileUtil.extractExt(originalName);
String res = s3Util.upload(multipartFile, "verification-file", filename);
AttachedFile verificationFiles = new AttachedFile(originalName, filename, res, verificationRequest);
verificationRequest.addAttachedFile(verificationFiles);
verificationRequest.setCertification(verificationFormDto.getCertification());

// 관리자를 할당합니다.
verificationRequest.setAdmin(admin);
verificationRequestRepository.save(verificationRequest);
}

Expand Down

0 comments on commit 447df1e

Please sign in to comment.