Add service master produk paket
Pembuatan fungsi simpan master produk sebagai kepala paket
This commit is contained in:
parent
20b8685d75
commit
1c1ae2d23e
@ -0,0 +1,17 @@
|
|||||||
|
package com.jasamedika.medifirst2000.dao;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.entities.ProdukPaket;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 14/11/2024
|
||||||
|
*/
|
||||||
|
public interface ProdukPaketDao extends JpaRepository<ProdukPaket, Integer> {
|
||||||
|
|
||||||
|
Optional<ProdukPaket> findById(Integer id);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.jasamedika.medifirst2000.service;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.dto.ProdukPaketDto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 14/11/2024
|
||||||
|
*/
|
||||||
|
public interface ProdukPaketService {
|
||||||
|
|
||||||
|
void save(ProdukPaketDto dto);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.jasamedika.medifirst2000.service.impl;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.dao.ProdukDao;
|
||||||
|
import com.jasamedika.medifirst2000.dao.ProdukPaketDao;
|
||||||
|
import com.jasamedika.medifirst2000.dto.ProdukPaketDto;
|
||||||
|
import com.jasamedika.medifirst2000.entities.Produk;
|
||||||
|
import com.jasamedika.medifirst2000.entities.ProdukPaket;
|
||||||
|
import com.jasamedika.medifirst2000.service.ProdukPaketService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 14/11/2024
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class ProdukPaketServiceImpl implements ProdukPaketService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProdukPaketDao produkPaketDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProdukDao produkDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(ProdukPaketDto dto) {
|
||||||
|
Produk paket = produkDao.findByIdProduk(dto.getProduk().getId());
|
||||||
|
ProdukPaket produkPaket = ProdukPaket.builder().produk(paket).tipePaket(dto.getTipePaket()).build();
|
||||||
|
produkPaket.setStatusEnabled(true);
|
||||||
|
produkPaket.setKdProfile((short) 0);
|
||||||
|
produkPaketDao.save(produkPaket);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.jasamedika.medifirst2000.dto;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.entities.ProdukDto;
|
||||||
|
import com.jasamedika.medifirst2000.entities.constant.TipePaket;
|
||||||
|
import com.jasamedika.medifirst2000.helper.Caption;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 14/11/2024
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ProdukPaketDto {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Caption(value = "Produk")
|
||||||
|
private ProdukDto produk;
|
||||||
|
|
||||||
|
@Caption("Tipe paket")
|
||||||
|
private TipePaket tipePaket;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package com.jasamedika.medifirst2000.entities;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.base.BaseActive;
|
||||||
|
import com.jasamedika.medifirst2000.entities.constant.TipePaket;
|
||||||
|
import com.jasamedika.medifirst2000.helper.Caption;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import static javax.persistence.EnumType.STRING;
|
||||||
|
import static javax.persistence.GenerationType.SEQUENCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 13/11/2024
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "produkpaket_m")
|
||||||
|
public class ProdukPaket extends BaseActive implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = SEQUENCE)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@MapsId
|
||||||
|
@JoinColumn(name = "id")
|
||||||
|
@NotNull(message = "Produk tidak boleh kosong")
|
||||||
|
@Caption(value = "Produk")
|
||||||
|
private Produk produk;
|
||||||
|
|
||||||
|
@Column(length = 30)
|
||||||
|
@Enumerated(STRING)
|
||||||
|
@Caption("Tipe paket")
|
||||||
|
private TipePaket tipePaket;
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,7 +7,7 @@ import lombok.Getter;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 13/11/2024
|
* @since 13/11/2024
|
||||||
*/
|
*/
|
||||||
public enum JenisPaket {
|
public enum TipePaket {
|
||||||
|
|
||||||
PERSALINAN(1, "Persalinan");
|
PERSALINAN(1, "Persalinan");
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ public enum JenisPaket {
|
|||||||
@Getter
|
@Getter
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
JenisPaket(long id, String name) {
|
TipePaket(long id, String name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@ -30,10 +30,10 @@ public enum JenisPaket {
|
|||||||
return Long.toString(id);
|
return Long.toString(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JenisPaket valueOf(long id) {
|
public static TipePaket valueOf(long id) {
|
||||||
for (JenisPaket jenisPaket : values()) {
|
for (TipePaket tipePaket : values()) {
|
||||||
if (jenisPaket.id == id) {
|
if (tipePaket.id == id) {
|
||||||
return jenisPaket;
|
return tipePaket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("No matching constant for [" + id + "]");
|
throw new IllegalArgumentException("No matching constant for [" + id + "]");
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.jasamedika.medifirst2000.controller;
|
||||||
|
|
||||||
|
import com.jasamedika.medifirst2000.constants.Constants;
|
||||||
|
import com.jasamedika.medifirst2000.constants.MessageResource;
|
||||||
|
import com.jasamedika.medifirst2000.controller.base.LocaleController;
|
||||||
|
import com.jasamedika.medifirst2000.dto.ProdukPaketDto;
|
||||||
|
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||||
|
import com.jasamedika.medifirst2000.service.ProdukPaketService;
|
||||||
|
import com.jasamedika.medifirst2000.vo.ProdukVO;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
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.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS;
|
||||||
|
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttptatus;
|
||||||
|
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse;
|
||||||
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||||
|
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 14/11/2024
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/produk")
|
||||||
|
public class ProdukController extends LocaleController<ProdukVO> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProdukController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProdukPaketService produkPaketService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/paket", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
|
||||||
|
public ResponseEntity<Object> simpanDiskonTagihan(HttpServletRequest request, @RequestBody ProdukPaketDto dto) {
|
||||||
|
try {
|
||||||
|
produkPaketService.save(dto);
|
||||||
|
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||||
|
return getJsonResponse(dto, CREATED, mapHeaderMessage);
|
||||||
|
} catch (ServiceVOException e) {
|
||||||
|
LOGGER.error("Got ServiceVOException {} when simpan produk paket", e.getMessage());
|
||||||
|
Map<String, String> error = new HashMap<>();
|
||||||
|
error.put("bad_request", e.getMessage());
|
||||||
|
return getJsonResponse(null, HttpStatus.BAD_REQUEST, error);
|
||||||
|
} catch (JpaSystemException jse) {
|
||||||
|
LOGGER.error("Got JpaSystemException {} when simpan produk paket", jse.getMessage());
|
||||||
|
addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
|
||||||
|
return getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user