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

chore : Repository 존재확인 메소드명 변경 #56

Merged
merged 1 commit into from
Oct 17, 2024
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 @@ -8,7 +8,6 @@

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
Expand All @@ -17,7 +16,6 @@
@RestController
@RequestMapping("/${spring.app.version}/careworker")
@RequiredArgsConstructor
@PreAuthorize("hasAnyAuthority('ADMIN')")
public class CareworkerController {

private final CareworkerService careworkerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public interface CareworkerRepository extends JpaRepository<Careworker, Long> {

List<Careworker> findByInstitutionId(Long institutionId);

boolean existsByEmail(String email);

Optional<Careworker> findByLineUserId(String userId);

List<Careworker> findByAlertTime(LocalTime currentTime);

Optional<Careworker> findByPhone(String phoneNumber);
boolean existsByPhone(String phone);

boolean ensureUniqueEmail(String email);

boolean ensureUniquePhone(String phone);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Careworker findCareworkerById(Long id) {
}

private void emailExists(String email) {
if (careworkerRepository.existsByEmail(email)) {
if (careworkerRepository.ensureUniqueEmail(email)) {
throw new ApplicationException(ApplicationError.DUPLICATE_EMAIL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void processCareworkerRow(Row row, List<FileDataResponseDto> successList

try {
checkDuplicate(seenPhones, phone, ApplicationError.DUPLICATE_PHONE);
validatePhone(phone, careworkerRepository.existsByPhone(phone));
validatePhone(phone, careworkerRepository.ensureUniquePhone(phone));
seenPhones.add(phone);

Careworker careworker = Careworker.builder()
Expand All @@ -104,7 +104,7 @@ private void processGuardianRow(Row row, List<FileDataResponseDto> successList,

try {
checkDuplicate(seenPhones, phone, ApplicationError.DUPLICATE_PHONE);
validatePhone(phone, guardianRepository.existsByPhone(phone));
validatePhone(phone, guardianRepository.ensureUniquePhone(phone));
seenPhones.add(phone);

Guardian guardian = Guardian.builder()
Expand All @@ -127,7 +127,7 @@ private void processRecipientRow(Row row, List<FileDataResponseDto> successList,

try {
checkDuplicate(seenCareNumbers, careNumber, ApplicationError.DUPLICATE_CARE_NUMBER);
validateCareNumber(careNumber, recipientRepository.existsByCareNumber(careNumber));
validateCareNumber(careNumber, recipientRepository.ensureUniqueCareNumber(careNumber));
seenCareNumbers.add(careNumber);

Recipient recipient = Recipient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface GuardianRepository extends JpaRepository<Guardian, Long> {

boolean existsByPhone(String phone);
boolean ensureUniquePhone(String phone);

Optional<Guardian> findByLineUserId(String userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private Guardian findGuardianById(Long guardianId) {
}

private void phoneNumberExists(String phone) {
if (guardianRepository.existsByPhone(phone)) {
if (guardianRepository.ensureUniquePhone(phone)) {
throw new ApplicationException(ApplicationError.DUPLICATE_PHONE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface InstitutionRepository extends JpaRepository<Institution, Long> {

boolean existsByInstitutionNumber(Long institutionNumber);
boolean ensureUniqueInstitutionNumber(Long institutionNumber);

Institution findByInstitutionNumber(Long institutionNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void deleteInstitutionById(Long id) {
}

private void institutionIdExists(Long institutionNumber) {
if (institutionRepository.existsByInstitutionNumber(institutionNumber)) {
if (institutionRepository.ensureUniqueInstitutionNumber(institutionNumber)) {
throw new ApplicationException(ApplicationError.DUPLICATE_INSTITUTION_NUMBER);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface RecipientRepository extends JpaRepository<Recipient, Long> {

boolean existsByCareNumber(String careNumber);
boolean ensureUniqueCareNumber(String careNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private Recipient findRecipientById(Long id) {
}

private void careNumberExists(String careNumber) {
if (recipientRepository.existsByCareNumber(careNumber)) {
if (recipientRepository.ensureUniqueCareNumber(careNumber)) {
throw new ApplicationException(ApplicationError.DUPLICATE_CARE_NUMBER);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public BaseUserDetails loadUserByUsernameAndRole(String username, Role role) {
}

private BaseUserDetails getInstitutionDetails(String userId) {
if (!institutionRepository.existsByInstitutionNumber(Long.parseLong(userId))) {
if (!institutionRepository.ensureUniqueInstitutionNumber(Long.parseLong(userId))) {
throw new ApplicationException(ApplicationError.INSTITUTION_NOT_FOUND);
}

Expand Down