Skip to content

Commit

Permalink
Merge: develop branch 병합
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijomn committed Nov 14, 2023
2 parents 0450d61 + 9668b49 commit 1dde165
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.gaseng.checklist.controller;

import com.gaseng.checklist.dto.ChecklistResponse;
import com.gaseng.checklist.dto.ChecklistRequest;
import com.gaseng.checklist.dto.ChecklistResponse;
import com.gaseng.checklist.service.ChecklistService;
import com.gaseng.global.annotation.ExtractPayload;
import com.gaseng.global.common.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
Expand All @@ -19,18 +20,22 @@
public class ChecklistApiController {
private final ChecklistService checklistService;

@PreAuthorize("hasRole('USER')")
@Operation(summary = "체크리슀트 생성", description = "μ‚¬μš©μžκ°€ 체크리슀트λ₯Ό λ“±λ‘ν•©λ‹ˆλ‹€.")
@PostMapping(value = "")
public BaseResponse<Long> create(@RequestParam Long memId, @RequestBody @Valid ChecklistRequest request){
return new BaseResponse<>(checklistService.create(memId, request.toChecklist()));
}

@PreAuthorize("hasRole('USER')")
@Operation(summary = "체크리슀트 μˆ˜μ •", description = "μ‚¬μš©μžκ°€ 체크리슀트λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.")
@PutMapping(value = "")
public BaseResponse<Long> update(@ExtractPayload Long memId, @RequestBody @Valid ChecklistRequest request) {
return new BaseResponse<>(checklistService.update(memId, request.toChecklist()));
}

@PreAuthorize("hasRole('USER')")
@Operation(summary = "체크리슀트 쑰회", description = "μ‚¬μš©μžκ°€ 체크리슀트λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping(value = "")
public BaseResponse<ChecklistResponse> get(@ExtractPayload Long memId) {
return new BaseResponse<>(checklistService.get(memId));
Expand Down
70 changes: 53 additions & 17 deletions src/main/java/com/gaseng/kyc/controller/KycManageApiController.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,85 @@
package com.gaseng.kyc.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gaseng.global.common.BaseResponse;
import com.gaseng.kyc.dto.KycRequireResponse;
import com.gaseng.kyc.dto.KycRequireSummaryResponse;
import com.gaseng.kyc.dto.KycSaveRequest;
import com.gaseng.kyc.service.KycManageService;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "Kyc Api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/kyc")
public class KycManageApiController {
private final KycManageService kycManageService;


@PreAuthorize("hasRole('ADMIN')")
@Operation(summary = "kyc μš”μ²­ 쑰회", description = "kyc μš”μ²­μ„œλ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μš”μ²­μ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "404", description = "KYC μš”μ²­μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "500", description = "μ„œλ²„μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.")
})
@GetMapping("")
public BaseResponse<KycRequireResponse> get(@RequestParam Long kycrId) {
public BaseResponse<KycRequireResponse> get(
@Parameter(description = "kyc require id", required = true, example = "1")
@RequestParam Long kycrId
) {
return new BaseResponse<>(kycManageService.get(kycrId));
}

@Operation(summary = "kyc μš”μ²­ 전체 쑰회", description = "kyc μš”μ²­μ„œλ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")

@PreAuthorize("hasRole('ADMIN')")
@Operation(summary = "kyc μš”μ²­ 전체 쑰회", description = "kyc μš”μ²­μ„œ λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μš”μ²­μ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "500", description = "μ„œλ²„μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.")
})
@GetMapping("/all")
public BaseResponse<List<KycRequireSummaryResponse>> getAll() {
return new BaseResponse<>(kycManageService.getAll());
}


@PreAuthorize("hasRole('ADMIN')")
@Operation(summary = "kyc μ €μž₯", description = "kycλ₯Ό μ €μž₯ν•©λ‹ˆλ‹€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μš”μ²­μ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "404", description = "KYC μš”μ²­μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. / λΉ„ν™œμ„±ν™”λœ KYC μš”μ²­μž…λ‹ˆλ‹€."),
@ApiResponse(responseCode = "500", description = "μ„œλ²„μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.")
})
@PostMapping("")
public BaseResponse<Long> save(@RequestParam Long kycrId, @RequestBody @Valid KycSaveRequest request) throws Exception {
public BaseResponse<Long> save(
@Parameter(description = "kyc require id", required = true, example = "1")
@RequestParam Long kycrId,
@RequestBody @Valid KycSaveRequest request
) throws Exception {
return new BaseResponse<>(kycManageService.save(kycrId, request));
}

@PreAuthorize("hasRole('ADMIN')")
@Operation(summary = "범죄 이λ ₯ 쑰회", description = "kyc 인증을 μš”μ²­ν•œ μ‚¬μš©μžμ˜ 범죄 이λ ₯을 μ‘°νšŒν•©λ‹ˆλ‹€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μš”μ²­μ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "404", description = "KYC μš”μ²­μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. / μΌμΉ˜ν•˜λŠ” νšŒμ›μ΄ μ—†μŠ΅λ‹ˆλ‹€."),
@ApiResponse(responseCode = "500", description = "μ„œλ²„μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.")
})
@GetMapping("/criminal-records/{kycrId}")
public BaseResponse<String> getCriminalRecord(
@Parameter(description = "kyc require id", required = true, example = "1")
@PathVariable Long kycrId
) {
return new BaseResponse<>(kycManageService.getCriminalRecord(kycrId));
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/gaseng/kyc/domain/CriminalRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gaseng.kyc.domain;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "criminal_record")
public class CriminalRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long cmrId;

private String cmrName;

private String cmrPhone;

private String cmrContent;
}
10 changes: 8 additions & 2 deletions src/main/java/com/gaseng/kyc/dto/KycRequireSummaryResponse.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.gaseng.kyc.dto;

import java.time.LocalDateTime;

import com.gaseng.kyc.domain.KycRequire;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;

public record KycRequireSummaryResponse (
@Schema(description = "kyc require id", example = "1")
Long id,

@Schema(description = "kyc require member name", example = "홍길동")
String name,

@Schema(description = "kyc require created date", example = "2023-11-08T06:49:55.451533")
LocalDateTime createdAt
) {
public static KycRequireSummaryResponse toResponse(KycRequire require) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gaseng/kyc/dto/KycSaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import com.gaseng.kyc.domain.KycNoticeStatus;
import com.gaseng.kyc.domain.KycRequire;
import com.gaseng.member.domain.Member;
import io.swagger.v3.oas.annotations.media.Schema;

public record KycSaveRequest (
@ValidEnum(enumClass = KycNoticeStatus.class)
@Schema(description = "kyc notice status", example = "0 반렀 / 1 거절 / 2 승인")
KycNoticeStatus status,

@Schema(description = "kyc notice description", example = "kyc 곡지 λ‚΄μš©μž…λ‹ˆλ‹€.")
String description
) {
public KycNotice toEntity(Member member, KycRequire require) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gaseng/kyc/exception/KycErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum KycErrorCode implements ErrorCode {
KYC_REQUIRE_NOT_FOUND(HttpStatus.NOT_FOUND, "KYC_001", "KYC μš”μ²­μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."),
KYC_REQUIRE_INACTIVE(HttpStatus.NOT_FOUND, "KYC_002", "λΉ„ν™œμ„±ν™”λœ KYC μš”μ²­μž…λ‹ˆλ‹€."),
KYC_NOTICE_NOT_FOUND(HttpStatus.NOT_FOUND, "KYC_003", "곡지가 μ—†μŠ΅λ‹ˆλ‹€."),
KYC_REQUIRE_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "KYC_004", "μΌμΉ˜ν•˜λŠ” νšŒμ›μ΄ μ—†μŠ΅λ‹ˆλ‹€."),
;

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gaseng.kyc.repository;

import com.gaseng.kyc.domain.CriminalRecord;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CriminalRecordRepository extends JpaRepository<CriminalRecord, Long> {
boolean existsByCmrNameAndCmrPhone(String name, String phone);
}
49 changes: 42 additions & 7 deletions src/main/java/com/gaseng/kyc/service/KycManageService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.gaseng.kyc.service;

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

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

import com.gaseng.global.exception.BaseException;
import com.gaseng.kyc.domain.Kyc;
import com.gaseng.kyc.domain.KycNotice;
Expand All @@ -15,13 +9,19 @@
import com.gaseng.kyc.dto.KycRequireSummaryResponse;
import com.gaseng.kyc.dto.KycSaveRequest;
import com.gaseng.kyc.exception.KycErrorCode;
import com.gaseng.kyc.repository.CriminalRecordRepository;
import com.gaseng.kyc.repository.KycNoticeRepository;
import com.gaseng.kyc.repository.KycRepository;
import com.gaseng.kyc.repository.KycRequireRepository;
import com.gaseng.member.domain.Member;
import com.gaseng.member.domain.MemberStatus;

import com.gaseng.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional(readOnly = true)
Expand All @@ -31,9 +31,13 @@ public class KycManageService {
private final KycRequireRepository kycRequireRepository;
private final KycNoticeRepository kycNoticeRepository;
private final KycInterface kycInterface;
private final CriminalRecordRepository criminalRecordRepository;
private final MemberRepository memberRepository;

public static int STATUS_ACTIVE = 0;
public static int STATUS_INACTIVE = 1;
public static String EXISTS_CRIMINAL_RECORD = "범죄 이λ ₯이 μžˆμŠ΅λ‹ˆλ‹€.";
public static String NOT_EXISTS_CRIMINAL_RECORD = "범죄 이λ ₯이 μ—†μŠ΅λ‹ˆλ‹€.";

@Transactional
public KycRequireResponse get(Long kycrId) {
Expand Down Expand Up @@ -92,6 +96,20 @@ public Long save(Long kycrId, KycSaveRequest request) throws Exception {
return kycNoticeRepository.save(noticeEntity).getKycnId();

}

public String getCriminalRecord(Long kycrId) {

KycRequire kycRequire = kycRequireRepository.findById(kycrId)
.orElseThrow(() -> BaseException.type(KycErrorCode.KYC_REQUIRE_NOT_FOUND));

String kycrName = kycRequire.getKycrName();
String memPhone = kycRequire.getMember().getMemPhone();

validateIsExistsMember(kycrName, memPhone);

return validateCriminalRecord(kycrName, memPhone);

}

private void saveKyc(Member member) {

Expand All @@ -104,4 +122,21 @@ private void saveKyc(Member member) {

}

private void validateIsExistsMember(String kycrName, String memPhone) {

if (!memberRepository.existsByMemNameAndMemPhone(kycrName, memPhone)) {
throw BaseException.type(KycErrorCode.KYC_REQUIRE_MEMBER_NOT_FOUND);
}

}

private String validateCriminalRecord(String kycrName, String memPhone) {

boolean isExists = criminalRecordRepository.existsByCmrNameAndCmrPhone(kycrName, memPhone);

return isExists
? EXISTS_CRIMINAL_RECORD
: NOT_EXISTS_CRIMINAL_RECORD;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByMemEmail(Email memEmail);
Optional<Member> findByMemId(Long id);
Member findByMemPhone(String memPhone);
boolean existsByMemNameAndMemPhone(String kycrName, String memPhone);

@Query("SELECT m.memId AS memId, m.memName AS memName FROM Member m WHERE m.memRole = :memRole ")
List<MemberListQueryProjection> findMemberByMemRole(@Param("memRole") Role memRole);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.gaseng.global.annotation.ExtractPayload;
import com.gaseng.global.common.BaseResponse;
import com.gaseng.sharehouse.domain.Sharehouse;
import com.gaseng.sharehouse.dto.*;
import com.gaseng.sharehouse.service.SharehouseService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -34,15 +33,14 @@ public BaseResponse<SharehouseDetailResponse> get(
return new BaseResponse<>(sharehouseService.get(shrId));
}

@Operation(summary = "μ‰μ–΄ν•˜μš°μŠ€ κΈ€ λͺ©λ‘ 쑰회", description = "μ‚¬μš©μžκ°€ μ‰μ–΄ν•˜μš°μŠ€ κΈ€ λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@Operation(summary = "μ‰μ–΄ν•˜μš°μŠ€ κΈ€ λͺ©λ‘ 쑰회", description = "μ‚¬μš©μžκ°€ μ‰μ–΄ν•˜μš°μŠ€ κΈ€ 전체 λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping(value = "/all")
public BaseResponse<List<SharehouseResponse>> getAll(
@Parameter(description = "size of page", required = true, example = "10")
@RequestParam(value = "page") int pageSize,
@Parameter(description = "last sharehouse id in the list (default = -1)", example = "10")
@RequestParam(value = "index", defaultValue = "-1", required = false) Long lastShrId) {


@RequestParam(value = "index", defaultValue = "-1", required = false) Long lastShrId
) {
return new BaseResponse<>(sharehouseService.getAll(pageSize, lastShrId));
}

Expand Down Expand Up @@ -78,14 +76,17 @@ public BaseResponse<Long> delete(
public BaseResponse<Slice<SharehouseListResponse>> mySharehouse(
@ExtractPayload Long memId,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "5") int size) {
@RequestParam(value = "size", defaultValue = "5") int size
) {
Pageable pageable = PageRequest.of(page, size);
return new BaseResponse<> (sharehouseService.mySharehouse(memId, pageable));
}


@Operation(summary = "λ‚΄κ°€ μ“΄ κΈ€ 쑰회", description = "μ‚¬μš©μžκ°€ λ‚΄κ°€ μ“΄ κΈ€ λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/my-share")
public BaseResponse<List<SharehouseListResponse>> getMyShareHouse(
@ExtractPayload Long memId) {
@ExtractPayload Long memId
) {
return new BaseResponse<> (sharehouseService.getMySharehouse(memId));
}
}
Loading

0 comments on commit 1dde165

Please sign in to comment.