Skip to content

Commit

Permalink
api 버그 수정 완료 (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
20jcode authored Nov 10, 2024
1 parent 6a71fb2 commit 3f3d21f
Show file tree
Hide file tree
Showing 83 changed files with 878 additions and 778 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -22,6 +23,7 @@
@RestController
@RequestMapping("/${spring.app.version}/admin")
@RequiredArgsConstructor
@Slf4j
public class AdminController {

private final AdminService adminService;
Expand All @@ -43,6 +45,8 @@ public ResponseEntity<String> getAdmin(@PathVariable(name = "id") Long id){
@Operation(summary = "서버관리자 추가")
@PostMapping("/add")
public ResponseEntity<Void> addAdmin(@RequestBody AdminCreateRequest adminCreateRequest){

log.info("어드민 생성 시작, {} {}", adminCreateRequest.loginId(), adminCreateRequest.loginPassword());
adminService.addAdmin(adminCreateRequest);
return ResponseEntity.ok().build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dbdr/domain/admin/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void addAdmin(AdminCreateRequest adminCreateRequest) {
.loginId(adminCreateRequest.loginId())
.loginPassword(passwordEncoder.encode(adminCreateRequest.loginPassword()))
.build();
addAdmin(admin);
adminRepository.save(admin);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dbdr.domain.careworker.controller;

import dbdr.domain.careworker.dto.request.CareworkerRequestDTO;
import dbdr.domain.careworker.dto.response.CareworkerResponseDTO;
import dbdr.domain.careworker.dto.request.CareworkerRequest;
import dbdr.domain.careworker.dto.response.CareworkerResponse;
import dbdr.domain.careworker.service.CareworkerService;
import dbdr.domain.institution.service.InstitutionService;
import dbdr.global.util.api.ApiUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,38 +24,38 @@ public class CareworkerAdminController {
private final CareworkerService careworkerService;
private final InstitutionService institutionService;

@Operation(summary = "전체 요양보호사 정보 조회")
@Operation(summary = "전체 요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping
public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponseDTO>>> getAllCareworkers() {
List<CareworkerResponseDTO> careworkers = careworkerService.getAllCareworkers();
public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponse>>> getAllCareworkers() {
List<CareworkerResponse> careworkers = careworkerService.getAllCareworkers();
return ResponseEntity.ok(ApiUtils.success(careworkers));
}


@Operation(summary = "요양보호사 정보 조회")
@Operation(summary = "요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> getCareworkerById(
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> getCareworkerById(
@PathVariable Long careworkerId) {
CareworkerResponseDTO careworker = careworkerService.getCareworkerResponseById(careworkerId);
CareworkerResponse careworker = careworkerService.getCareworkerResponseById(careworkerId);
return ResponseEntity.ok(ApiUtils.success(careworker));
}

@Operation(summary = "요양보호사 추가")
@Operation(summary = "요양보호사 추가", security = @SecurityRequirement(name = "JWT"))
@PostMapping
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> createCareworker(
@Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO newCareworker = careworkerService.createCareworker(careworkerDTO, careworkerDTO.getInstitutionId());
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> createCareworker(
@Valid @RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse newCareworker = careworkerService.createCareworker(careworkerDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(ApiUtils.success(newCareworker));

}


@Operation(summary = "요양보호사 정보 수정 ")
@Operation(summary = "요양보호사 정보 수정 ", security = @SecurityRequirement(name = "JWT"))
@PutMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> updateCareworker(
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> updateCareworker(
@PathVariable Long careworkerId,
@Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO updatedCareworker = careworkerService.updateCareworkerByAdmin(careworkerId, careworkerDTO);
@Valid @RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse updatedCareworker = careworkerService.updateCareworkerByAdmin(careworkerId, careworkerDTO);
return ResponseEntity.ok(ApiUtils.success(updatedCareworker));
}

Expand All @@ -65,4 +66,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
@@ -1,7 +1,7 @@
package dbdr.domain.careworker.controller;

import dbdr.domain.careworker.dto.request.CareworkerUpdateRequestDTO;
import dbdr.domain.careworker.dto.response.CareworkerMyPageResponseDTO;
import dbdr.domain.careworker.dto.request.CareworkerUpdateRequest;
import dbdr.domain.careworker.dto.response.CareworkerMyPageResponse;
import dbdr.domain.careworker.entity.Careworker;
import dbdr.domain.careworker.service.CareworkerService;
import dbdr.global.util.api.ApiUtils;
Expand Down Expand Up @@ -34,19 +34,19 @@ public class CareworkerController {

@Operation(summary = "요양보호사 본인의 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping
public ResponseEntity<ApiUtils.ApiResult<CareworkerMyPageResponseDTO>> showCareworkerInfo(
public ResponseEntity<ApiUtils.ApiResult<CareworkerMyPageResponse>> showCareworkerInfo(
@Parameter(hidden = true) @LoginCareworker Careworker careworker) {
log.info("Careworker Name: {}", careworker.getName());
CareworkerMyPageResponseDTO response = careworkerService.getMyPageInfo(careworker.getId());
CareworkerMyPageResponse response = careworkerService.getMyPageInfo(careworker.getId());
return ResponseEntity.ok(ApiUtils.success(response));
}

@Operation(summary = "요양보호사 본인의 근무일과 알림 시간 수정", security = @SecurityRequirement(name = "JWT"))
@PutMapping
public ResponseEntity<ApiUtils.ApiResult<CareworkerMyPageResponseDTO>> updateCareworkerInfo(
public ResponseEntity<ApiUtils.ApiResult<CareworkerMyPageResponse>> updateCareworkerInfo(
@Parameter(hidden = true) @LoginCareworker Careworker careworker,
@Valid @RequestBody CareworkerUpdateRequestDTO careworkerRequest) {
CareworkerMyPageResponseDTO updatedResponse = careworkerService.updateWorkingDaysAndAlertTime(careworker.getId(), careworkerRequest);
@Valid @RequestBody CareworkerUpdateRequest careworkerRequest) {
CareworkerMyPageResponse updatedResponse = careworkerService.updateWorkingDaysAndAlertTime(careworker.getId(), careworkerRequest);
return ResponseEntity.ok(ApiUtils.success(updatedResponse));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dbdr.domain.careworker.controller;

import dbdr.domain.careworker.dto.request.CareworkerRequestDTO;
import dbdr.domain.careworker.dto.response.CareworkerResponseDTO;
import dbdr.domain.careworker.dto.request.CareworkerRequest;
import dbdr.domain.careworker.dto.response.CareworkerResponse;
import dbdr.domain.careworker.service.CareworkerService;
import dbdr.domain.institution.entity.Institution;
import dbdr.global.util.api.ApiUtils;
Expand All @@ -27,40 +27,40 @@ public class CareworkerInstitutionController {

@Operation(summary = "특정 요양원아이디로 전체 요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping("/institution")
public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponseDTO>>> getAllCareworkers(
public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponse>>> getAllCareworkers(
@LoginInstitution Institution institution) {
List<CareworkerResponseDTO> institutions = careworkerService.getCareworkersByInstitution(institution.getId());
List<CareworkerResponse> institutions = careworkerService.getCareworkersByInstitution(institution.getId());
return ResponseEntity.ok(ApiUtils.success(institutions)) ;
}

@Operation(summary = "요양보호사 아이디로 요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> getCareworkerById(
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> getCareworkerById(
@PathVariable("careworkerId") Long careworkerId,
@LoginInstitution Institution institution) {
CareworkerResponseDTO careworker = careworkerService.getCareworkerByInstitution(careworkerId, institution.getId());
CareworkerResponse careworker = careworkerService.getCareworkerByInstitution(careworkerId, institution.getId());
return ResponseEntity.ok(ApiUtils.success(careworker)) ;
}


@Operation(summary = "요양보호사 추가", security = @SecurityRequirement(name = "JWT"))
@PostMapping
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> createCareworker(
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> createCareworker(
@LoginInstitution Institution institution,
@Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO newCareworker = careworkerService.createCareworker(careworkerDTO, institution.getId());
@Valid @RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse newCareworker = careworkerService.createCareworker(careworkerDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(ApiUtils.success(newCareworker));

}


@Operation(summary = "요양보호사 정보 수정", security = @SecurityRequirement(name = "JWT"))
@PutMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponseDTO>> updateCareworker(
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> updateCareworker(
@PathVariable Long careworkerId,
@LoginInstitution Institution institution,
@RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO updatedCareworker = careworkerService.updateCareworker(careworkerId, careworkerDTO, institution.getId());
@RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse updatedCareworker = careworkerService.updateCareworker(careworkerId, careworkerDTO);
return ResponseEntity.ok(ApiUtils.success(updatedCareworker));
}

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/dbdr/domain/careworker/dto/CareworkerMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dbdr.domain.careworker.dto;

import dbdr.domain.careworker.dto.request.CareworkerRequest;
import dbdr.domain.careworker.dto.response.CareworkerResponse;
import dbdr.domain.careworker.entity.Careworker;
import dbdr.domain.institution.entity.Institution;
import dbdr.domain.institution.service.InstitutionService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;

@Mapper(componentModel = "spring")
public abstract class CareworkerMapper {
@Autowired
PasswordEncoder passwordEncoder;
@Autowired
private InstitutionService institutionService;

@Mappings({
@Mapping(target = "institutionId", source = "institution.id"),
@Mapping(target = "id", source = "id")})
public abstract CareworkerResponse toResponse(Careworker careworker);

@Mappings({
@Mapping(target = "loginPassword", expression = "java(passwordEncoder.encode(request.getLoginPassword()))"),
@Mapping(target = "institution", source = "institutionId")})
public abstract Careworker toEntity(CareworkerRequest request);

protected Institution mapInstitution(Long institutionId) {
return institutionService.getInstitutionById(institutionId);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CareworkerRequestDTO {
public class CareworkerRequest {

@Schema(description = "요양기관아이디", example = "1")
@NotNull(message = "요양기관 아이디는 필수 항목입니다.")
Expand All @@ -31,4 +31,10 @@ public class CareworkerRequestDTO {
@NotBlank(message = "휴대폰 번호는 필수 항목입니다.")
@Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.")
private String phone;
}

@Schema(description = "요양보호사 비밀번호", example = "1234")
@NotBlank(message = "비밀번호는 필수 항목입니다.")
private String loginPassword;


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

@Getter
@AllArgsConstructor
public class CareworkerUpdateRequestDTO {
public class CareworkerUpdateRequest {

@NotNull(message = "근무일은 필수 항목입니다.")
private Set<DayOfWeek> workingDays;


@NotNull(message = "알림 시간은 필수 항목입니다.")
private LocalTime alertTime;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package dbdr.domain.careworker.dto.response;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CareworkerMyPageResponseDTO {
public class CareworkerMyPageResponse {

private String name;
private String phone;
private String institutionName;
private String loginId;
private Set<DayOfWeek> workingDays;
private LocalTime alertTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CareworkerResponseDTO {
public class CareworkerResponse {

private Long id;
private Long institutionId;
private String name;
private String email;
private String phone;
}
}
Loading

0 comments on commit 3f3d21f

Please sign in to comment.