refactor base smartproc

This commit is contained in:
dirgantarasiahaan
2023-05-23 11:26:15 +07:00
parent 329d515577
commit beff4babe0
85 changed files with 1642 additions and 839 deletions

View File

@@ -0,0 +1,74 @@
package com.iconplus.smartproc.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iconplus.smartproc.exception.ResourceNotFoundException;
import com.iconplus.smartproc.model.entity.SupplyPositioningMatrix;
import com.iconplus.smartproc.repository.SupplyPositioningMatrixRepository;
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
@RestController
@RequestMapping("/api/supplypositioningmatrix")
public class SupplyPositioningMatrixController {
@Autowired
private SupplyPositioningMatrixRepository supplypositioningmatrixRepository;
//get all data
@GetMapping
public List<SupplyPositioningMatrix> getAllSupplypositioningmatrix(){
return supplypositioningmatrixRepository.findAll();
}
// create
@PostMapping
public SupplyPositioningMatrix createSupplypositioningmatrix(@RequestBody SupplyPositioningMatrix supplypositioningmatrix) {
return supplypositioningmatrixRepository.save(supplypositioningmatrix);
}
// get supplypositioningmatrix by id rest api
@GetMapping("/{id}")
public ResponseEntity<SupplyPositioningMatrix> getSupplypositioningmatrixById(@PathVariable Long id) {
SupplyPositioningMatrix supplypositioningmatrix = supplypositioningmatrixRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Supplypositioningmatrix not exist with id :" + id));
return ResponseEntity.ok(supplypositioningmatrix);
}
// update jenispengadaan rest api
@PutMapping("/{id}")
public ResponseEntity<SupplyPositioningMatrix> updateSupplypositioningmatrix(@PathVariable Long id, @RequestBody SupplyPositioningMatrix supplyPositioningMatrixDetails){
SupplyPositioningMatrix supplypositioningmatrix = supplypositioningmatrixRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Supplypositioningmatrix not exist with id :" + id));
supplypositioningmatrix.setSupplypositioningmatrix(supplyPositioningMatrixDetails.getSupplypositioningmatrix());
supplypositioningmatrix.setKeterangan(supplyPositioningMatrixDetails.getKeterangan());
SupplyPositioningMatrix updatedSupplyPositioningMatrix = supplypositioningmatrixRepository.save(supplypositioningmatrix);
return ResponseEntity.ok(updatedSupplyPositioningMatrix);
}
// delete jenispengadaan rest api
@DeleteMapping("/{id}")
public ResponseEntity<Map<String, Boolean>> deleteSupplypositioningmatrix(@PathVariable Long id){
SupplyPositioningMatrix supplypositioningmatrix = supplypositioningmatrixRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Unit inisiator not exist with id :" + id));
supplypositioningmatrixRepository.delete(supplypositioningmatrix);
Map<String, Boolean> response = new HashMap<>();
response.put("deleted", Boolean.TRUE);
return ResponseEntity.ok(response);
}
}