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

refactor: institution update #97

Merged
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 @@ -2,7 +2,8 @@

public record InstitutionResponse(
Long institutionNumber,
String institutionName
String institutionName,
String institutionLoginId
) {

}
6 changes: 4 additions & 2 deletions src/main/java/dbdr/domain/institution/entity/Institution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstitutionResponse> getAllInstitution() {
List<Institution> 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) {
Expand Down