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: guardianInstitution 권한 추가, 코드 정리, 요약 API 수정 #131

Merged
merged 5 commits into from
Nov 13, 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 @@ -72,4 +72,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteCareworker(@PathVariable
careworkerService.deleteCareworkerByAdmin(careworkerId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "[요양보호사] 마이페이지", description = "요양보호사 본인의 정보 조회 및 수정")
@RestController
@RequestMapping("/${spring.app.version}/careworker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteCareworker(
careworkerService.deleteCareworker(careworkerId, institution.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ protected Institution mapInstitution(Long institutionId) {
return institutionService.getInstitutionById(institutionId);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ public class CareworkerRequest {
@NotBlank(message = "비밀번호는 필수 항목입니다.")
private String loginPassword;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@ public class CareworkerUpdateAdminRequest {
@Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.")
private String phone;




// 비밀번호는 수정 불가
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -28,6 +27,5 @@ public class CareworkerUpdateInstitutionRequest {
@Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.")
private String phone;


// 요양원 권한 사용자는 institutionId를 변경할 수 없음
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dbdr.domain.careworker.dto.request;


import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public class CareworkerResponse {
private String name;
private String email;
private String phone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

public interface CareworkerRepository extends JpaRepository<Careworker, Long> {


List<Careworker> findAllByInstitutionId(Long institutionId);

Optional<Careworker> findByLineUserId(String userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,4 @@ public void updateLineUserId(String userId, String phoneNumber) {
careworkerRepository.save(careworker);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public class HealthBloodPressure {

@Comment("혈압 최저")
private String diastolic;
}
}
2 changes: 1 addition & 1 deletion src/main/java/dbdr/domain/chart/entity/PhysicalClear.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public class PhysicalClear {

@Comment("목욕 유무")
private boolean bath;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dbdr.domain.core.messaging.service;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.linecorp.bot.client.LineMessagingClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.nurigo.sdk.message.response.SingleMessageSentResponse;
import net.nurigo.sdk.message.service.DefaultMessageService;


@Service
public class SmsMessagingService implements MessagingService {
private final DefaultMessageService defaultMessageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ public ResponseEntity<RecipientFileUploadResponse> uploadRecipientData(
RecipientFileUploadResponse result = excelUploadService.uploadRecipientExcel(file, institution.getId());
return ResponseEntity.ok(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public record CareworkerFileUploadResponse(
String storeName,
List<ExcelCareworkerResponse> uploadedCareworkers,
List<ExcelCareworkerResponse> failedCareworkers
) {}
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class ExcelCareworkerResponse {
private String name;
private String email;
private String phone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class ExcelGuardianResponse {
private String phone;
private Long institution;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public class ExcelRecipientResponse {
private Long institution;
private Long careworker;
private Long guardian;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public record GuardianFileUploadResponse(
String storeName,
List<ExcelGuardianResponse> uploadedGuardians,
List<ExcelGuardianResponse> failedGuardians
) {}
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public record RecipientFileUploadResponse(
String storeName,
List<ExcelRecipientResponse> uploadedRecipients,
List<ExcelRecipientResponse> failedRecipients
) {}
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ private byte[] convertWorkbookToByteArray(Workbook workbook) throws IOException
return outputStream.toByteArray();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,4 @@ private String getCellValue(Cell cell) {
private interface RowProcessor {
void process(Row row);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import dbdr.domain.guardian.dto.request.GuardianUpdateRequest;
import dbdr.domain.guardian.dto.response.GuardianResponse;
import dbdr.domain.guardian.service.GuardianService;
import dbdr.domain.institution.entity.Institution;
import dbdr.global.util.api.ApiUtils;
import dbdr.security.LoginInstitution;
import dbdr.security.model.AuthParam;
import dbdr.security.model.DbdrAuth;
import dbdr.security.model.Role;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
Expand All @@ -31,13 +37,17 @@ public class GuardianInstitutionController {

@Operation(summary = "전체 보호자 정보 조회")
@GetMapping
public ResponseEntity<ApiUtils.ApiResult<List<GuardianResponse>>> showAllGuardian() {
List<GuardianResponse> guardianResponseList = guardianService.getAllGuardian();
@DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION)
public ResponseEntity<ApiUtils.ApiResult<List<GuardianResponse>>> showAllGuardian(
@Parameter(hidden = true) @LoginInstitution Institution institution) {
List<GuardianResponse> guardianResponseList = guardianService.getAllGuardianByInstitutionId(
institution.getId());
return ResponseEntity.ok(ApiUtils.success(guardianResponseList));
}

@Operation(summary = "보호자 한 사람의 정보 조회")
@GetMapping("/{guardianId}")
@DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.GUARDIAN_ID, id = "guardianId")
public ResponseEntity<ApiUtils.ApiResult<GuardianResponse>> showOneGuardian(
@PathVariable("guardianId") Long guardianId) {
GuardianResponse guardianResponse = guardianService.getGuardianById(guardianId);
Expand All @@ -46,14 +56,18 @@ public ResponseEntity<ApiUtils.ApiResult<GuardianResponse>> showOneGuardian(

@Operation(summary = "보호자 추가")
@PostMapping
@DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION)
public ResponseEntity<ApiUtils.ApiResult<GuardianResponse>> addGuardian(
@Valid @RequestBody GuardianRequest guardianRequest) {
GuardianResponse guardianResponse = guardianService.addGuardian(guardianRequest);
@Valid @RequestBody GuardianRequest guardianRequest,
@Parameter(hidden = true) @LoginInstitution Institution institution) {
GuardianResponse guardianResponse = guardianService.addGuardianByInstitution(
guardianRequest, institution.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(ApiUtils.success(guardianResponse));
}

@Operation(summary = "보호자 정보 수정")
@PutMapping("/{guardianId}")
@DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.GUARDIAN_ID, id = "guardianId")
public ResponseEntity<ApiUtils.ApiResult<GuardianResponse>> updateGuardian(
@PathVariable("guardianId") Long guardianId,
@Valid @RequestBody GuardianUpdateRequest guardianRequest) {
Expand All @@ -64,7 +78,9 @@ public ResponseEntity<ApiUtils.ApiResult<GuardianResponse>> updateGuardian(

@Operation(summary = "보호자 삭제")
@DeleteMapping("/{guardianId}")
public ResponseEntity<ApiUtils.ApiResult<String>> deleteGuardian(@PathVariable("guardianId") Long guardianId) {
@DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.GUARDIAN_ID, id = "guardianId")
public ResponseEntity<ApiUtils.ApiResult<String>> deleteGuardian(
@PathVariable("guardianId") Long guardianId) {
guardianService.deleteGuardianById(guardianId);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface GuardianRepository extends JpaRepository<Guardian, Long> {
List<Guardian> findByAlertTime(LocalTime currentTime);

Optional<Guardian> findByPhone(String phone);

List<Guardian> findAllByInstitutionId(Long institutionId);
}
30 changes: 30 additions & 0 deletions src/main/java/dbdr/domain/guardian/service/GuardianService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public List<GuardianResponse> getAllGuardian() {
.toList();
}

@Transactional(readOnly = true)
public List<GuardianResponse> getAllGuardianByInstitutionId(Long institutionId) {
List<Guardian> guardianList = guardianRepository.findAllByInstitutionId(institutionId);
return guardianList.stream()
.map(guardian -> new GuardianResponse(guardian.getId(), guardian.getPhone(),
guardian.getName(),
guardian.getInstitution().getId(),
guardian.isActive()))
.toList();
}

@Transactional
public GuardianResponse addGuardian(GuardianRequest guardianRequest) {
ensureUniquePhone(guardianRequest.phone());
Expand All @@ -103,6 +114,25 @@ public GuardianResponse addGuardian(GuardianRequest guardianRequest) {
guardian.getInstitution().getId(), guardian.isActive());
}

@Transactional
public GuardianResponse addGuardianByInstitution(GuardianRequest guardianRequest, Long institutionId) {
ensureUniquePhone(guardianRequest.phone());
Institution institution = institutionRepository.findById(institutionId)
.orElseThrow(() -> new ApplicationException(
ApplicationError.INSTITUTION_NOT_FOUND));
String password = passwordEncoder.encode(guardianRequest.loginPassword());
Guardian guardian = Guardian.builder().phone(guardianRequest.phone())
.name(guardianRequest.name())
.phone(guardianRequest.phone())
.loginPassword(password)
.institution(institution)
.build();
guardian = guardianRepository.save(guardian);
alarmService.createGuardianAlarm(guardian);
return new GuardianResponse(guardian.getId(), guardian.getPhone(), guardian.getName(),
guardian.getInstitution().getId(), guardian.isActive());
}

@Transactional
public void deleteGuardianById(Long guardianId) {
Guardian guardian = findGuardianById(guardianId);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/dbdr/domain/institution/entity/Institution.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@ public void updateInstitution(String loginId, String loginPassword, Long institu
this.institutionNumber = institutionNumber;
this.institutionName = institutionName;
}

public void updatePassword(String encodedPassword) {
this.loginPassword = encodedPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
public interface InstitutionRepository extends JpaRepository<Institution, Long> {

boolean existsByInstitutionNumber(Long institutionNumber);
boolean existsByInstitutionName(String institutionName);
boolean existsByLoginId(String loginId);

Institution findByInstitutionNumber(Long institutionNumber);
Institution findByLoginId(String loginId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteRecipient(
recipientService.deleteRecipientForCareworker(recipientId, careworker.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ public ResponseEntity<ApiUtils.ApiResult<RecipientResponse>> getRecipientById(
return ResponseEntity.ok(ApiUtils.success(recipient));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteRecipient(
recipientService.deleteRecipientForInstitution(recipientId, institution.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ public class RecipientRequest {
@Schema(description = "돌봄대상자의 보호자 아이디", example = "11")
@NotNull(message = "보호자 ID는 필수 항목입니다.")
private Long guardianId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public class RecipientUpdateCareworkerRequest {
private LocalDate startDate;

// institutionId, careworkerId, guardianId는 수정 불가
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ public class RecipientUpdateInstitutionRequest {
@NotNull(message = "보호자 ID는 필수 항목입니다.")
private Long guardianId;


}
}
5 changes: 1 addition & 4 deletions src/main/java/dbdr/domain/recipient/entity/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,4 @@ public void updateRecipientForAdmin(RecipientRequest recipientDTO, Institution i
this.guardian = guardian;
} //관리자용




}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public interface RecipientRepository extends JpaRepository<Recipient, Long> {
Optional<Recipient> findByIdAndInstitutionId(Long recipientId, Long institutionId);

Optional<Recipient> findByIdAndGuardianId(Long recipientId, Long guardianId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,4 @@ private RecipientResponse toResponse(Recipient recipient) {
recipient.getGuardian() != null ? recipient.getGuardian().getId() : null
);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/dbdr/global/configuration/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dbdr.global.configuration;


import io.lettuce.core.ClientOptions;
import io.lettuce.core.SocketOptions;
import java.time.Duration;
Expand Down
Loading