60 lines
2.2 KiB
Java
60 lines
2.2 KiB
Java
package com.zioinfo.mro.equipment;
|
|
|
|
import com.zioinfo.mro.common.ApiResponse;
|
|
import com.zioinfo.mro.common.AuthSupport;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 설비 마스터 API. 조회 Viewer+, 생성/수정/삭제 Manager+(기준정보 가드), 가동상태 전이 Worker+.
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/mro/equipment")
|
|
@RequiredArgsConstructor
|
|
public class EquipmentController {
|
|
|
|
private final EquipmentService service;
|
|
|
|
@GetMapping
|
|
public ApiResponse<List<MroEquipment>> list(@RequestParam(required = false) String category,
|
|
@RequestParam(required = false) String runStatus,
|
|
@RequestParam(required = false) String keyword) {
|
|
return ApiResponse.ok(service.list(category, runStatus, keyword));
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public ApiResponse<MroEquipment> get(@PathVariable Long id) {
|
|
return ApiResponse.ok(service.get(id));
|
|
}
|
|
|
|
@PostMapping
|
|
public ApiResponse<MroEquipment> create(@RequestBody MroEquipment e, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
return ApiResponse.ok(service.create(e, AuthSupport.actor(auth)));
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ApiResponse<MroEquipment> update(@PathVariable Long id, @RequestBody MroEquipment e, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
return ApiResponse.ok(service.update(id, e, AuthSupport.actor(auth)));
|
|
}
|
|
|
|
/** 가동상태 전이 — Worker+ (기준정보 가드 없음). */
|
|
@PatchMapping("/{id}/run-status")
|
|
public ApiResponse<MroEquipment> changeRunStatus(@PathVariable Long id, @RequestBody Map<String, String> body,
|
|
Authentication auth) {
|
|
return ApiResponse.ok(service.changeRunStatus(id, body.get("runStatus"), AuthSupport.actor(auth)));
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ApiResponse<Void> delete(@PathVariable Long id, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
service.delete(id);
|
|
return ApiResponse.ok(null);
|
|
}
|
|
}
|