52 lines
1.8 KiB
Java
52 lines
1.8 KiB
Java
package com.zioinfo.mro.material;
|
|
|
|
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;
|
|
|
|
/**
|
|
* MRO 자재 마스터 API. 조회 Viewer+, 생성/수정/삭제 Manager+(기준정보 가드).
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/mro/materials")
|
|
@RequiredArgsConstructor
|
|
public class MaterialController {
|
|
|
|
private final MaterialService service;
|
|
|
|
@GetMapping
|
|
public ApiResponse<List<MroMaterial>> list(@RequestParam(required = false) String materialType,
|
|
@RequestParam(required = false) String status,
|
|
@RequestParam(required = false) String keyword) {
|
|
return ApiResponse.ok(service.list(materialType, status, keyword));
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public ApiResponse<MroMaterial> get(@PathVariable Long id) {
|
|
return ApiResponse.ok(service.get(id));
|
|
}
|
|
|
|
@PostMapping
|
|
public ApiResponse<MroMaterial> create(@RequestBody MroMaterial m, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
return ApiResponse.ok(service.create(m, AuthSupport.actor(auth)));
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ApiResponse<MroMaterial> update(@PathVariable Long id, @RequestBody MroMaterial m, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
return ApiResponse.ok(service.update(id, m, AuthSupport.actor(auth)));
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ApiResponse<Void> delete(@PathVariable Long id, Authentication auth) {
|
|
AuthSupport.requireManager(auth);
|
|
service.delete(id);
|
|
return ApiResponse.ok(null);
|
|
}
|
|
}
|