salmanoe c26b23a85a Update SlipGajiService
Penerapan komponen gaji pada service simpan dan get slip gaji per bulan per pegawai
2023-01-31 07:53:29 +07:00

63 lines
2.5 KiB
Java

package com.jasamedika.medifirst2000.controller;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.jasamedika.medifirst2000.dto.SlipGajiDto;
import com.jasamedika.medifirst2000.service.SlipGajiService;
@RestController
@RequestMapping("/slip-gaji")
public class SlipGajiController {
@Autowired
private SlipGajiService slipGajiService;
@RequestMapping(value = "/init", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> init() {
try {
slipGajiService.init();
return new ResponseEntity<>(true, HttpStatus.CREATED);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> save(@RequestBody @Valid SlipGajiDto dto) {
try {
slipGajiService.save(dto);
return new ResponseEntity<>(true, HttpStatus.CREATED);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(value = "/detail/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> updateDetail(@RequestBody @Valid SlipGajiDto dto) {
try {
slipGajiService.updateDetail(dto);
return new ResponseEntity<>(true, HttpStatus.CREATED);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(value = "/get/{pegawaiId}/{bulan}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> get(@PathVariable Integer pegawaiId, @PathVariable Long bulan) {
SlipGajiDto entity = slipGajiService.get(pegawaiId, bulan);
return new ResponseEntity<>(entity, HttpStatus.OK);
}
}