Skip to content

Commit

Permalink
Merge pull request #105 from PLADI-ALM/feat/PDS-86-updateOffice
Browse files Browse the repository at this point in the history
[PDS-86/feat] 관리자 회의실 수정 api 기능구현
  • Loading branch information
leeseunghakhello authored Oct 19, 2023
2 parents 3facbc1 + e393bba commit efb4ba1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<OfficeFacility,Long> {
void deleteAllByOffice(Office office);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CreateOfficeReq {
@NotBlank(message = "O0006")
private String location;

@Schema(type = "List<String>", description = "시설(큰 따움표 단어 양쪽에 있어야함)", example = "빔 프로젝터 , 대형 모니터 , 마이크")
@Schema(type = "List<String>", description = "시설(단어 사이에 큰 따움표 붙혀야함)", example = "[빔 프로젝터 , 대형 모니터 , 마이크]")
@NotEmpty(message = "O0007")
private List<String> facility;

Expand Down

0 comments on commit efb4ba1

Please sign in to comment.