You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TBCodeDetailsResource.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package vn.azteam.tpf.web.rest;
  2. import com.codahale.metrics.annotation.Timed;
  3. import io.github.jhipster.web.util.ResponseUtil;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.http.ResponseEntity;
  8. import org.springframework.web.bind.annotation.*;
  9. import vn.azteam.tpf.domain.TBCodeStatusEnum;
  10. import vn.azteam.tpf.service.TBCodeDetailsService;
  11. import vn.azteam.tpf.service.UserService;
  12. import vn.azteam.tpf.service.dto.TBCodeDetailsAndActivityDTO;
  13. import vn.azteam.tpf.service.dto.TBCodeDetailsDTO;
  14. import vn.azteam.tpf.service.dto.UserDTO;
  15. import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
  16. import java.time.Instant;
  17. import java.util.Optional;
  18. @RestController
  19. @RequestMapping("/api")
  20. public class TBCodeDetailsResource {
  21. private static final String ENTITY_NAME = "tBCodeDetails";
  22. private final Logger log = LoggerFactory.getLogger(TBCodeDetailsResource.class);
  23. private final TBCodeDetailsService tBCodeDetailsService;
  24. private final UserService userService;
  25. public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, UserService userService) {
  26. this.tBCodeDetailsService = tBCodeDetailsService;
  27. this.userService = userService;
  28. }
  29. @GetMapping("/tb-code-details/scan/{code}")
  30. public ResponseEntity<TBCodeDetailsAndActivityDTO> getTBCodeDetailsScan(@PathVariable String code) {
  31. if (StringUtils.isBlank(code)) {
  32. return (ResponseEntity<TBCodeDetailsAndActivityDTO>) ResponseEntity.badRequest();
  33. }
  34. TBCodeDetailsAndActivityDTO tbCodeDetailsAndActivityDTO = tBCodeDetailsService.updateNumberScan(code);
  35. return ResponseEntity.ok().headers(null).body(tbCodeDetailsAndActivityDTO);
  36. }
  37. @PutMapping("/tb-code-details/update/{id}/status/{status}")
  38. @Timed
  39. public ResponseEntity<TBCodeDetailsDTO> updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String
  40. status) {
  41. log.debug("REST request to update tb codes : {}, status {} ", id, status);
  42. if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) {
  43. throw new BadRequestAlertException("1039", ENTITY_NAME, "1039");
  44. }
  45. try {
  46. TBCodeStatusEnum.valueOf(status);
  47. } catch (Exception exception) {
  48. throw new BadRequestAlertException("1039", ENTITY_NAME, "1039");
  49. }
  50. UserDTO currentUser = userService.getCurrentUserDTO().get();
  51. TBCodeDetailsDTO tbCodeDetailsDTO = new TBCodeDetailsDTO();
  52. tbCodeDetailsDTO.setId(id);
  53. tbCodeDetailsDTO.setModifiedDate(Instant.now());
  54. tbCodeDetailsDTO.setModifiedById(currentUser.getId());
  55. tbCodeDetailsDTO.setStatus(TBCodeStatusEnum.valueOf(status));
  56. Optional<TBCodeDetailsDTO> tBCodeUpdated =
  57. tBCodeDetailsService.updateStatusTBCodeDetails(tbCodeDetailsDTO);
  58. // if (null != tBCropDTO) {
  59. // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev);
  60. // }
  61. return ResponseUtil.wrapOrNotFound(tBCodeUpdated);
  62. }
  63. }