2025-03-12 14:52:27 +07:00

208 lines
10 KiB
Java

package com.jasamedika.medifirst2000.controller;
import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.IpsrsPeminjamanAlatService;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.IpsrsPeminjamanAlatVO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;
import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE;
import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS;
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus;
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpStatus.*;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
@RestController
@RequestMapping("/ipsrs-peminjaman-alat")
public class IpsrsPeminjamanAlatController extends LocaleController<IpsrsPeminjamanAlatVO> {
private static final Logger LOGGER = getLogger(IpsrsPeminjamanAlatController.class);
@Autowired
private IpsrsPeminjamanAlatService service;
@RequestMapping(value = "/get-login-user/", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getLoginUser(HttpServletRequest request) {
try {
Map<String, Object> result = service.getUserLogin();
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getUserLogin", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemExceptions {} when getUserLogin", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/get-no-peminjaman-alat", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getNoOrder(HttpServletRequest request) {
try {
Map<String, Object> result = service.getNoPeminjamanAlatTable();
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getNoPeminjamanAlatTable", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when getNoPeminjamanAlatTable", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/get-ruangan-peminjaman-alat", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getRuanganPeminjamanAlat(HttpServletRequest request) {
try {
Map<String, Object> result = service.getRuanganPeminjamanAlat();
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getRuanganPeminjamanAlat", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when getRuanganPeminjamanAlat", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/get-aset-peminjaman-alat", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getAsetPeminjamanAlat(@RequestParam(value = "id") Integer id,
HttpServletRequest request) {
try {
Map<String, Object> result = service.getAsetPeminjamanAlat(id);
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getAsetPeminjamanAlat", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when getAsetPeminjamanAlat", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/get-petugas-peminjaman-alat", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getPetugasPeminjamanAlat(HttpServletRequest request) {
try {
Map<String, Object> result = service.getPetugasPeminjamanAlat();
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getPetugasPeminjamanAlat", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when getPetugasPeminjamanAlat", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/save-peminjaman-alat", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> savePemeliharaan(@Valid @RequestBody IpsrsPeminjamanAlatVO vo,
HttpServletRequest request) {
try {
Map<String, Object> result = service.savePeminjamanAlat(vo);
if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when savePeminjamanAlat", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when savePeminjamanAlat", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/get-all-peminjaman-alat", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> getAllPeminjamanAlat(@RequestParam(value = "status") String status,
HttpServletRequest request) {
try {
Map<String, Object> result = service.getAllPeminjamanAlat(status);
if (null != result) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, OK, mapHeaderMessage);
} else {
return getJsonResponse(null, NOT_FOUND, mapHeaderMessage);
}
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getAllPeminjamanAlat", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when getAllPeminjamanAlat", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/update-status-peminjaman", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> updateStatusPeminjaman(@Valid @RequestBody IpsrsPeminjamanAlatVO vo,
HttpServletRequest request) {
try {
Map<String, Object> result = service.updateStatusPeminjaman(vo);
if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when updateStatusPeminjaman", e.getMessage());
addHeaderMessage(ERROR_MESSAGE, e.getMessage());
return RestUtil.getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
} catch (JpaSystemException jse) {
LOGGER.error("Got JpaSystemException {} when updateStatusPeminjaman", jse.getMessage());
addHeaderMessage(ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttpStatus(CONFLICT, mapHeaderMessage);
}
}
}