Create APIs jenis log
This commit is contained in:
parent
213806d581
commit
28e45f1f65
@ -1,4 +1,4 @@
|
||||
package com.jasamedika.medifirst2000.logging.dao;
|
||||
package com.jasamedika.medifirst2000.dao;
|
||||
|
||||
import com.jasamedika.medifirst2000.entities.JenisLog;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@ -9,6 +9,4 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
* @since 31/01/2024
|
||||
*/
|
||||
public interface JenisLogDao extends JpaRepository<JenisLog, Long> {
|
||||
|
||||
boolean existsByJenisLog(String jenisLog);
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.jasamedika.medifirst2000.service;
|
||||
|
||||
import com.jasamedika.medifirst2000.vo.JenisLogVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Salman
|
||||
* @version 1.0.0
|
||||
* @since 02/02/2024
|
||||
*/
|
||||
public interface JenisLogService {
|
||||
|
||||
void save(List<JenisLogVO> vos);
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.jasamedika.medifirst2000.service.impl;
|
||||
|
||||
import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
|
||||
import com.jasamedika.medifirst2000.entities.JenisLog;
|
||||
import com.jasamedika.medifirst2000.dao.JenisLogDao;
|
||||
import com.jasamedika.medifirst2000.service.JenisLogService;
|
||||
import com.jasamedika.medifirst2000.vo.JenisLogVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Salman
|
||||
* @version 1.0.0
|
||||
* @since 02/02/2024
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class JenisLogServiceImpl implements JenisLogService {
|
||||
|
||||
@Autowired
|
||||
private BaseVoConverter<JenisLogVO, JenisLog> jenisLogVoConverter;
|
||||
|
||||
@Autowired
|
||||
private JenisLogDao jenisLogDao;
|
||||
|
||||
@Override
|
||||
public void save(List<JenisLogVO> vos) {
|
||||
List<JenisLog> entities = new ArrayList<>();
|
||||
vos.forEach(vo -> {
|
||||
JenisLog entity = jenisLogVoConverter.transferVOToModel(vo, new JenisLog());
|
||||
entities.add(entity);
|
||||
});
|
||||
jenisLogDao.save(entities);
|
||||
}
|
||||
}
|
||||
@ -6,12 +6,12 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
import static javax.persistence.GenerationType.SEQUENCE;
|
||||
|
||||
/**
|
||||
* @author Salman
|
||||
* @version 1.0.0
|
||||
@ -25,10 +25,13 @@ public class JenisLog extends BaseActive implements Serializable {
|
||||
private static final long serialVersionUID = -5796583173860610757L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id", columnDefinition = "bigserial")
|
||||
@GeneratedValue(strategy = SEQUENCE, generator = "sg_jenis_log_m")
|
||||
@SequenceGenerator(name = "sg_jenis_log_m", sequenceName = "rm_jenis_log_m_seq", allocationSize = 1)
|
||||
@Column(name = "id")
|
||||
protected Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(length = 150, nullable = false)
|
||||
@Size(max = 150)
|
||||
@NotBlank
|
||||
@Caption("Jenis Log")
|
||||
private String jenisLog;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.jasamedika.medifirst2000.vo;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.BaseActiveVO;
|
||||
import com.jasamedika.medifirst2000.helper.Caption;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -12,7 +13,7 @@ import org.hibernate.validator.constraints.NotBlank;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class JenisLogVO {
|
||||
public class JenisLogVO extends BaseActiveVO {
|
||||
protected Long id;
|
||||
|
||||
@NotBlank
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
package com.jasamedika.medifirst2000.controller;
|
||||
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
import com.jasamedika.medifirst2000.service.JenisLogService;
|
||||
import com.jasamedika.medifirst2000.util.rest.RestUtil;
|
||||
import com.jasamedika.medifirst2000.vo.JenisLogVO;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||
|
||||
/**
|
||||
* @author Salman
|
||||
* @version 1.0.0
|
||||
* @since 02/02/2024
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/log/jenis")
|
||||
public class JenisLogController {
|
||||
private static final Logger LOGGER = getLogger(JenisLogController.class);
|
||||
|
||||
@Autowired
|
||||
private JenisLogService jenisLogService;
|
||||
|
||||
@RequestMapping(method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<String> addVO(@Valid @RequestBody List<JenisLogVO> vos, HttpServletRequest request) {
|
||||
try {
|
||||
jenisLogService.save(vos);
|
||||
return RestUtil.getJsonResponse(CREATED.getReasonPhrase(), CREATED);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got exception {} when add Agama", e.getMessage());
|
||||
return RestUtil.getJsonHttptatus(INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user