diff --git a/src/main/java/com/example/pladialmserver/office/controller/OfficeAdminController.java b/src/main/java/com/example/pladialmserver/office/controller/OfficeAdminController.java index 1f2fc324..21c79a62 100644 --- a/src/main/java/com/example/pladialmserver/office/controller/OfficeAdminController.java +++ b/src/main/java/com/example/pladialmserver/office/controller/OfficeAdminController.java @@ -9,6 +9,7 @@ import com.example.pladialmserver.user.entity.User; import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -17,10 +18,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.validation.Valid; @@ -48,4 +46,25 @@ public ResponseCustom createOffice( officeService.createOfficeByAdmin(user, request); return ResponseCustom.OK(); } + + /** + * 관리자 회의실 수정 + */ + @Operation(summary = "관리자 회의실 수정 (이승학)", description = "관리자가 회의실을 수정한다. (요청 값 모두 필요)") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."), + @ApiResponse(responseCode = "400", description = "(O0003)회의실명을 입력해주세요. (O0004)설명은 255자 이하로 작성해주세요. (O0005)50자 이하로 작성해주세요. (O0006)회의실 위치를 입력해주세요. (O0007)회의실 시설을 입력해주세요. (O0008)수용인원을 입력해주세요. (O0009)회의실 설명을 입력해주세요.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))), + @ApiResponse(responseCode = "403", description = "(G0002)접근권한이 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))), + @ApiResponse(responseCode = "404", description = "(U0001)사용자를 찾을 수 없습니다. (O0002)시설을 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))), + }) + @PatchMapping("/{officeId}") + public ResponseCustom updateOffice( + @Account User user, + @Parameter(description = "(Long) 회의실 Id", example = "1") @PathVariable(name="officeId") Long officeId, + @RequestBody @Valid CreateOfficeReq request) { + officeService.updateOffice(user, officeId, request); + return ResponseCustom.OK(); + } + + } diff --git a/src/main/java/com/example/pladialmserver/office/entity/Office.java b/src/main/java/com/example/pladialmserver/office/entity/Office.java index 16b95553..dcae2d7c 100644 --- a/src/main/java/com/example/pladialmserver/office/entity/Office.java +++ b/src/main/java/com/example/pladialmserver/office/entity/Office.java @@ -60,4 +60,11 @@ public static Office toDto(CreateOfficeReq req){ .build(); } + public void updateOffice(CreateOfficeReq request) { + if(!request.getName().equals(name)) name=request.getName(); + if(!request.getLocation().equals(location)) name=request.getLocation(); + if(!request.getCapacity().equals(capacity)) capacity=request.getCapacity(); + if(!request.getDescription().equals(description)) description=request.getDescription(); + if(!request.getImgUrl().equals(imgKey)) imgKey=request.getImgUrl(); + } } diff --git a/src/main/java/com/example/pladialmserver/office/repository/OfficeFacilityRepository.java b/src/main/java/com/example/pladialmserver/office/repository/OfficeFacilityRepository.java index e6acbfed..d2fdf73a 100644 --- a/src/main/java/com/example/pladialmserver/office/repository/OfficeFacilityRepository.java +++ b/src/main/java/com/example/pladialmserver/office/repository/OfficeFacilityRepository.java @@ -1,7 +1,9 @@ package com.example.pladialmserver.office.repository; +import com.example.pladialmserver.office.entity.Office; import com.example.pladialmserver.office.entity.OfficeFacility; import org.springframework.data.jpa.repository.JpaRepository; public interface OfficeFacilityRepository extends JpaRepository { + void deleteAllByOffice(Office office); } diff --git a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java index f495a73b..ae2d97e9 100644 --- a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java +++ b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java @@ -149,4 +149,27 @@ public void createOfficeByAdmin(User user, CreateOfficeReq request) { private void checkAdminRole(User user) { if(!user.checkRole(Role.ADMIN)) throw new BaseException(BaseResponseCode.NO_AUTHENTICATION); } + + /** + * 관리자 회의실 수정 + */ + @Transactional + public void updateOffice(User user, Long officeId, CreateOfficeReq request) { + checkAdminRole(user); + + Office office = officeRepository.findById(officeId) + .orElseThrow(() -> new BaseException(BaseResponseCode.OFFICE_NOT_FOUND)); + + office.updateOffice(request); + + officeFacilityRepository.deleteAllByOffice(office); + + for (String facilityName : request.getFacility()) { + Facility facility = facilityRepository.findByName(facilityName) + .orElseThrow(() -> new BaseException(BaseResponseCode.OFFICE_FACILITY_NOT_FOUND)); + + OfficeFacility officeFacility = OfficeFacility.toDto(office, facility); + officeFacilityRepository.save(officeFacility); + } + } } diff --git a/src/main/java/com/example/pladialmserver/resource/dto/request/CreateOfficeReq.java b/src/main/java/com/example/pladialmserver/resource/dto/request/CreateOfficeReq.java index c8feef34..761dea32 100644 --- a/src/main/java/com/example/pladialmserver/resource/dto/request/CreateOfficeReq.java +++ b/src/main/java/com/example/pladialmserver/resource/dto/request/CreateOfficeReq.java @@ -22,7 +22,7 @@ public class CreateOfficeReq { @NotBlank(message = "O0006") private String location; - @Schema(type = "List", description = "시설(큰 따움표 단어 양쪽에 있어야함)", example = "빔 프로젝터 , 대형 모니터 , 마이크") + @Schema(type = "List", description = "시설(단어 사이에 큰 따움표 붙혀야함)", example = "[빔 프로젝터 , 대형 모니터 , 마이크]") @NotEmpty(message = "O0007") private List facility;