From 2888a5de413b8d54984358894fef4596c78897a9 Mon Sep 17 00:00:00 2001 From: hyyyh0x Date: Sat, 9 Nov 2024 20:28:58 +0900 Subject: [PATCH] refactor: institution update --- .../dto/response/InstitutionResponse.java | 3 +- .../institution/entity/Institution.java | 6 ++-- .../service/InstitutionService.java | 28 +++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/dbdr/domain/institution/dto/response/InstitutionResponse.java b/src/main/java/dbdr/domain/institution/dto/response/InstitutionResponse.java index 34f6fe1d..bfdab5b5 100644 --- a/src/main/java/dbdr/domain/institution/dto/response/InstitutionResponse.java +++ b/src/main/java/dbdr/domain/institution/dto/response/InstitutionResponse.java @@ -2,7 +2,8 @@ public record InstitutionResponse( Long institutionNumber, - String institutionName + String institutionName, + String institutionLoginId ) { } diff --git a/src/main/java/dbdr/domain/institution/entity/Institution.java b/src/main/java/dbdr/domain/institution/entity/Institution.java index f09d27be..26345cfe 100644 --- a/src/main/java/dbdr/domain/institution/entity/Institution.java +++ b/src/main/java/dbdr/domain/institution/entity/Institution.java @@ -31,14 +31,16 @@ public class Institution extends BaseEntity { private String institutionName; @Builder - public Institution(String loginId,String loginPassword,Long institutionNumber, String institutionName) { + public Institution(String loginId, String loginPassword, Long institutionNumber, String institutionName) { this.loginId = loginId; this.loginPassword = loginPassword; this.institutionNumber = institutionNumber; this.institutionName = institutionName; } - public void updateInstitution(Long institutionNumber, String institutionName) { + public void updateInstitution(String loginId, String loginPassword, Long institutionNumber, String institutionName) { + this.loginId = loginId; + this.loginPassword = loginPassword; this.institutionNumber = institutionNumber; this.institutionName = institutionName; } diff --git a/src/main/java/dbdr/domain/institution/service/InstitutionService.java b/src/main/java/dbdr/domain/institution/service/InstitutionService.java index 3bada35a..13ac5d16 100644 --- a/src/main/java/dbdr/domain/institution/service/InstitutionService.java +++ b/src/main/java/dbdr/domain/institution/service/InstitutionService.java @@ -18,41 +18,45 @@ public class InstitutionService { public Institution getInstitutionById(Long id) { return institutionRepository.findById(id) - .orElseThrow(() -> new ApplicationException(ApplicationError.INSTITUTION_NOT_FOUND)); + .orElseThrow(() -> new ApplicationException(ApplicationError.INSTITUTION_NOT_FOUND)); } public InstitutionResponse getInstitutionResponseById(Long id) { Institution institution = getInstitutionById(id); return new InstitutionResponse(institution.getInstitutionNumber(), - institution.getInstitutionName()); + institution.getInstitutionName(), institution.getLoginId()); } - public InstitutionResponse updateInstitution(Long institutionId, InstitutionRequest institutionRequest) { + public InstitutionResponse updateInstitution(Long institutionId, + InstitutionRequest institutionRequest) { ensureUniqueInstitutionNumber(institutionRequest.institutionNumber()); Institution institution = getInstitutionById(institutionId); - institution.updateInstitution(institutionRequest.institutionNumber(), institutionRequest.institutionName()); + institution.updateInstitution(institutionRequest.institutionLoginId(), + institutionRequest.institutionLoginPassword(), institutionRequest.institutionNumber(), + institutionRequest.institutionName()); institutionRepository.save(institution); return new InstitutionResponse(institutionRequest.institutionNumber(), - institutionRequest.institutionName()); + institutionRequest.institutionName(), institutionRequest.institutionLoginId()); } public List getAllInstitution() { List institutionList = institutionRepository.findAll(); return institutionList.stream().map( - institution -> new InstitutionResponse(institution.getInstitutionNumber(), - institution.getInstitutionName())).toList(); + institution -> new InstitutionResponse(institution.getInstitutionNumber(), + institution.getInstitutionName(), institution.getLoginId())).toList(); } public InstitutionResponse addInstitution(InstitutionRequest institutionRequest) { ensureUniqueInstitutionNumber(institutionRequest.institutionNumber()); - Institution institution = Institution.builder().loginId(institutionRequest.institutionLoginId()) - .loginPassword(institutionRequest.institutionLoginPassword()) - .institutionNumber(institutionRequest.institutionNumber()) - .institutionName(institutionRequest.institutionName()).build(); + Institution institution = Institution.builder() + .loginId(institutionRequest.institutionLoginId()) + .loginPassword(institutionRequest.institutionLoginPassword()) + .institutionNumber(institutionRequest.institutionNumber()) + .institutionName(institutionRequest.institutionName()).build(); institution = institutionRepository.save(institution); return new InstitutionResponse(institution.getInstitutionNumber(), - institution.getInstitutionName()); + institution.getInstitutionName(), institution.getLoginId()); } public void deleteInstitutionById(Long institutionId) {