package vn.azteam.tpf.web.rest; import com.codahale.metrics.annotation.Timed; import io.github.jhipster.web.util.ResponseUtil; import io.searchbox.strings.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import vn.azteam.tpf.domain.TBCodeStatusEnum; import vn.azteam.tpf.service.TBCodeDetailsQueryService; import vn.azteam.tpf.service.TBCodeDetailsService; import vn.azteam.tpf.service.UserService; import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; import vn.azteam.tpf.service.dto.TBCropDetailDTOV2; import vn.azteam.tpf.service.dto.UserDTO; import vn.azteam.tpf.service.util.PageableUtil; import vn.azteam.tpf.service.util.UserRoleUtil; import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; import java.time.Instant; import java.util.Optional; @RestController @RequestMapping("/api") public class TBCodeDetailsResource { private static final String ENTITY_NAME = "tBCodeDetails"; private final Logger log = LoggerFactory.getLogger(TBCodeDetailsResource.class); private final TBCodeDetailsService tBCodeDetailsService; private final UserService userService; public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, UserService userService) { this.tBCodeDetailsService = tBCodeDetailsService; this.userService = userService; } @GetMapping("/tb-code-details/scan/{code}") public ResponseEntity getTBCodeDetailsScan(@PathVariable String code) { if (StringUtils.isBlank(code)) { return (ResponseEntity) ResponseEntity.badRequest(); } TBCropDetailDTOV2 tbCropDetailDTOV2ResponseEntity = tBCodeDetailsService.updateNumberScan(code); return ResponseEntity.ok().headers(null).body(tbCropDetailDTOV2ResponseEntity); } @PutMapping("/tb-code-details/update/{id}/status/{status}") @Timed public ResponseEntity updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String status) { log.debug("REST request to update tb codes : {}, status {} ", id, status); if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) { throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); } try { TBCodeStatusEnum.valueOf(status); } catch (Exception exception) { throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); } UserDTO currentUser = userService.getCurrentUserDTO().get(); TBCodeDetailsDTO tbCodeDetailsDTO = new TBCodeDetailsDTO(); tbCodeDetailsDTO.setId(id); tbCodeDetailsDTO.setModifiedDate(Instant.now()); tbCodeDetailsDTO.setModifiedById(currentUser.getId()); tbCodeDetailsDTO.setStatus(TBCodeStatusEnum.valueOf(status)); Optional tBCodeUpdated = tBCodeDetailsService.updateStatusTBCodeDetails(tbCodeDetailsDTO); // if (null != tBCropDTO) { // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev); // } return ResponseUtil.wrapOrNotFound(tBCodeUpdated); } }