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,65 @@
package com.iconplus.smartproc.controller;
import com.iconplus.smartproc.model.entity.JenisPengadaan;
import com.iconplus.smartproc.exception.ResourceNotFoundException;
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
@RestController
@RequestMapping("/api/jenispengadaan")
public class JenisPengadaanController {
@Autowired
private JenisPengadaanRepository jenispengadaanRepository;
//get all data
@GetMapping
public List<JenisPengadaan> getAllJenispengadaans(){
return jenispengadaanRepository.findAll();
}
// create
@PostMapping
public JenisPengadaan createJenispengadaan(@RequestBody JenisPengadaan jenispengadaan) {
return jenispengadaanRepository.save(jenispengadaan);
}
// get jenispengadaan by id rest api
@GetMapping("/{id}")
public ResponseEntity<JenisPengadaan> getJenispengadaanById(@PathVariable Long id) {
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
return ResponseEntity.ok(jenispengadaan);
}
// update jenispengadaan rest api
@PutMapping("/{id}")
public ResponseEntity<JenisPengadaan> updateJenispengadaan(@PathVariable Long id, @RequestBody JenisPengadaan jenisPengadaanDetails){
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
jenispengadaan.setJenisPengadaan(jenisPengadaanDetails.getJenisPengadaan());
jenispengadaan.setKeterangan(jenisPengadaanDetails.getKeterangan());
JenisPengadaan updatedJenisPengadaan = jenispengadaanRepository.save(jenispengadaan);
return ResponseEntity.ok(updatedJenisPengadaan);
}
// delete jenispengadaan rest api
@DeleteMapping("/{id}")
public ResponseEntity<Map<String, Boolean>> deleteJenispengadaan(@PathVariable Long id){
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Supposmatrix not exist with id :" + id));
jenispengadaanRepository.delete(jenispengadaan);
Map<String, Boolean> response = new HashMap<>();
response.put("deleted", Boolean.TRUE);
return ResponseEntity.ok(response);
}
}