You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Override
public boolean createProject(ProjectRequest projectRequest) {
Project project = Project.builder()
.name(projectRequest.getName())
.adminId(projectRequest.getAdminId())
.status(Status.ACTIVATION.getValue())
.detail(projectRequest.getDetail())
.build();
Project savedProject = projectRepository.save(project);
if(!Objects.equals(project, savedProject)) {
throw new ProjectCreationFailedException("프로젝트 생성 중 오류가 발생하였습니다");
}
ProjectMember.Pk projectMemberPk = new ProjectMember.Pk(savedProject.getAdminId(), savedProject.getId());
ProjectMember projectMember = ProjectMember.builder()
.pk(projectMemberPk)
.project(savedProject)
.build();
ProjectMember savedProjectMember = projectMemberRepository.save(projectMember);
if(!Objects.equals(projectMember, savedProjectMember)) {
throw new ProjectMemberAddFailedException("멤버 등록 중 오류가 발생하였습니다");
}
return true;
}
다음과 같이 Service layer에 에러 검출 로직을 작성해 보았습니다
Equals로 저장하려고 한 객체와 저장 후(save()) 리턴되는 값을 서로 비교하며, 다르면 Exception을 던집니다! @EqualsAndHashCode Annotation 적용이 필요합니다!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
다음과 같이
Service
layer에 에러 검출 로직을 작성해 보았습니다Equals로 저장하려고 한 객체와 저장 후(
save()
) 리턴되는 값을 서로 비교하며, 다르면 Exception을 던집니다!@EqualsAndHashCode
Annotation 적용이 필요합니다!Beta Was this translation helpful? Give feedback.
All reactions