PickSlipService.java 1.73 KB
Newer Older
akbar fauzi's avatar
akbar fauzi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package com.eksad.masterdata.service;

import com.eksad.ddms.common.util.response.ResponseDTO;
import com.eksad.masterdata.common.dto.responseDto.ResponsePickSlipGetDTO;
import com.eksad.masterdata.domain.PickSlip;
import com.eksad.masterdata.domain.assembler.PickSlipAssembler;
import com.eksad.masterdata.repository.PickSlipRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@PropertySource("classpath:error-message.properties")
public class PickSlipService {

    @Autowired
    private PickSlipRepository pickSlipRepository;

    public ResponseEntity<ResponsePickSlipGetDTO> getPickSlipBySalesOrderID(String salesOrderID, String ahassID) {
        PickSlip data;
        try {
            data = pickSlipRepository.findOneBySalesOrderIDAndAhassID(salesOrderID, ahassID);
            if (data == null) {
                return ResponseEntity.status(HttpStatus.FOUND).body(
                        new ResponsePickSlipGetDTO(new ResponseDTO().noDataFoundResponse(), null));
            }
            return ResponseEntity.status(HttpStatus.FOUND).body(
                    new ResponsePickSlipGetDTO(new ResponseDTO().defaultResponse(), new PickSlipAssembler().toDTO(data)));
        } catch (Exception e) {
//            logger.info("This is info from pickslip services: " + e.getMessage());
            return ResponseEntity.status(HttpStatus.FOUND).body(
                    new ResponsePickSlipGetDTO(new ResponseDTO().failedRespose(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()), e.getMessage()), null));
        }
    }
}