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.

TBCityResource.java 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package vn.azteam.tpf.web.rest;
  2. import com.codahale.metrics.annotation.Timed;
  3. import io.github.jhipster.service.filter.LongFilter;
  4. import org.springframework.data.jpa.domain.Specification;
  5. import vn.azteam.tpf.domain.TBSupplies;
  6. import vn.azteam.tpf.service.TBCityService;
  7. import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
  8. import vn.azteam.tpf.web.rest.util.HeaderUtil;
  9. import vn.azteam.tpf.web.rest.util.PaginationUtil;
  10. import vn.azteam.tpf.service.dto.TBCityDTO;
  11. import vn.azteam.tpf.service.dto.TBCityCriteria;
  12. import vn.azteam.tpf.service.TBCityQueryService;
  13. import io.github.jhipster.web.util.ResponseUtil;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.data.domain.Page;
  17. import org.springframework.data.domain.Pageable;
  18. import org.springframework.http.HttpHeaders;
  19. import org.springframework.http.HttpStatus;
  20. import org.springframework.http.ResponseEntity;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.net.URI;
  23. import java.net.URISyntaxException;
  24. import java.util.List;
  25. import java.util.Optional;
  26. /**
  27. * REST controller for managing TBCity.
  28. */
  29. @RestController
  30. @RequestMapping("/api")
  31. public class TBCityResource {
  32. private final Logger log = LoggerFactory.getLogger(TBCityResource.class);
  33. private static final String ENTITY_NAME = "tBCity";
  34. private final TBCityService tBCityService;
  35. private final TBCityQueryService tBCityQueryService;
  36. public TBCityResource(TBCityService tBCityService, TBCityQueryService tBCityQueryService) {
  37. this.tBCityService = tBCityService;
  38. this.tBCityQueryService = tBCityQueryService;
  39. }
  40. /**
  41. * POST /tb-cities : Create a new tBCity.
  42. *
  43. * @param tBCityDTO the tBCityDTO to create
  44. * @return the ResponseEntity with status 201 (Created) and with body the new tBCityDTO, or with status 400 (Bad Request) if the tBCity has already an ID
  45. * @throws URISyntaxException if the Location URI syntax is incorrect
  46. */
  47. @PostMapping("/tb-cities")
  48. @Timed
  49. public ResponseEntity<TBCityDTO> createTBCity(@RequestBody TBCityDTO tBCityDTO) throws URISyntaxException {
  50. log.debug("REST request to save TBCity : {}", tBCityDTO);
  51. if (tBCityDTO.getId() != null) {
  52. throw new BadRequestAlertException("A new tBCity cannot already have an ID", ENTITY_NAME, "idexists");
  53. }
  54. TBCityDTO result = tBCityService.save(tBCityDTO);
  55. return ResponseEntity.created(new URI("/api/tb-cities/" + result.getId()))
  56. .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
  57. .body(result);
  58. }
  59. /**
  60. * PUT /tb-cities : Updates an existing tBCity.
  61. *
  62. * @param tBCityDTO the tBCityDTO to update
  63. * @return the ResponseEntity with status 200 (OK) and with body the updated tBCityDTO,
  64. * or with status 400 (Bad Request) if the tBCityDTO is not valid,
  65. * or with status 500 (Internal Server Error) if the tBCityDTO couldn't be updated
  66. * @throws URISyntaxException if the Location URI syntax is incorrect
  67. */
  68. @PutMapping("/tb-cities")
  69. @Timed
  70. public ResponseEntity<TBCityDTO> updateTBCity(@RequestBody TBCityDTO tBCityDTO) throws URISyntaxException {
  71. log.debug("REST request to update TBCity : {}", tBCityDTO);
  72. if (tBCityDTO.getId() == null) {
  73. throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
  74. }
  75. TBCityDTO result = tBCityService.save(tBCityDTO);
  76. return ResponseEntity.ok()
  77. .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tBCityDTO.getId().toString()))
  78. .body(result);
  79. }
  80. /**
  81. * GET /tb-cities : get all the tBCities.
  82. *
  83. * @param pageable the pagination information
  84. * @param criteria the criterias which the requested entities should match
  85. * @return the ResponseEntity with status 200 (OK) and the list of tBCities in body
  86. */
  87. @GetMapping("/tb-cities")
  88. @Timed
  89. public ResponseEntity<List<TBCityDTO>> getAllTBCities(TBCityCriteria criteria, Pageable pageable) {
  90. log.debug("REST request to get TBCities by criteria: {}", criteria);
  91. Page<TBCityDTO> page = tBCityQueryService.findByCriteria(criteria, pageable);
  92. HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/tb-cities");
  93. return ResponseEntity.ok().headers(headers).body(page.getContent());
  94. }
  95. /**
  96. * GET /tb-cities-by-country/{countryId} : get all the tBCities by country.
  97. *
  98. * @param countryId the country id
  99. * @param pageable the pagination information
  100. * @param criteria the criterias which the requested entities should match
  101. * @return the ResponseEntity with status 200 (OK) and the list of tBCities in body
  102. */
  103. @GetMapping("/tb-cities-by-country/{countryId}")
  104. @Timed
  105. public ResponseEntity<List<TBCityDTO>> getCitiesByCountry(@PathVariable("countryId") Long countryId, TBCityCriteria criteria, Pageable pageable,
  106. @RequestParam(value = "query", required=false) String query) {
  107. log.debug("REST request to get cities by country by criteria: {}", criteria);
  108. //
  109. // LongFilter countryFilter = new LongFilter();
  110. // countryFilter.setEquals(countryId);
  111. // criteria.setTbCountryId(countryFilter);
  112. // Page<TBCityDTO> page = tBCityQueryService.findByCriteria(criteria, pageable);
  113. // List<Long> ids = tBCityQueryService.getIdsTbCityByCountry(countryId, query);
  114. // LongFilter suppliesIdFilter = new LongFilter();
  115. // suppliesIdFilter.setIn(listSuppliesId);
  116. // criteria.setId(suppliesIdFilter);
  117. //
  118. // final Specification<TBSupplies> specification = createSpecification(criteria);
  119. Page<TBCityDTO> page = tBCityQueryService.getTbCityByCountry(countryId, query, criteria, pageable);
  120. HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/tb-cities-by-country");
  121. return ResponseEntity.ok().headers(headers).body(page.getContent());
  122. }
  123. /**
  124. * GET /tb-cities/count : count all the tBCities.
  125. *
  126. * @param criteria the criterias which the requested entities should match
  127. * @return the ResponseEntity with status 200 (OK) and the count in body
  128. */
  129. @GetMapping("/tb-cities/count")
  130. @Timed
  131. public ResponseEntity<Long> countTBCities(TBCityCriteria criteria) {
  132. log.debug("REST request to count TBCities by criteria: {}", criteria);
  133. return ResponseEntity.ok().body(tBCityQueryService.countByCriteria(criteria));
  134. }
  135. /**
  136. * GET /tb-cities/:id : get the "id" tBCity.
  137. *
  138. * @param id the id of the tBCityDTO to retrieve
  139. * @return the ResponseEntity with status 200 (OK) and with body the tBCityDTO, or with status 404 (Not Found)
  140. */
  141. @GetMapping("/tb-cities/{id}")
  142. @Timed
  143. public ResponseEntity<TBCityDTO> getTBCity(@PathVariable Long id) {
  144. log.debug("REST request to get TBCity : {}", id);
  145. Optional<TBCityDTO> tBCityDTO = tBCityService.findOne(id);
  146. return ResponseUtil.wrapOrNotFound(tBCityDTO);
  147. }
  148. /**
  149. * DELETE /tb-cities/:id : delete the "id" tBCity.
  150. *
  151. * @param id the id of the tBCityDTO to delete
  152. * @return the ResponseEntity with status 200 (OK)
  153. */
  154. @DeleteMapping("/tb-cities/{id}")
  155. @Timed
  156. public ResponseEntity<Void> deleteTBCity(@PathVariable Long id) {
  157. log.debug("REST request to delete TBCity : {}", id);
  158. tBCityService.delete(id);
  159. return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
  160. }
  161. /**
  162. * SEARCH /_search/tb-cities?query=:query : search for the tBCity corresponding
  163. * to the query.
  164. *
  165. * @param query the query of the tBCity search
  166. * @param pageable the pagination information
  167. * @return the result of the search
  168. */
  169. @GetMapping("/_search/tb-cities")
  170. @Timed
  171. public ResponseEntity<List<TBCityDTO>> searchTBCities(@RequestParam String query, Pageable pageable) {
  172. log.debug("REST request to search for a page of TBCities for query {}", query);
  173. Page<TBCityDTO> page = tBCityService.search(query, pageable);
  174. HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/tb-cities");
  175. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  176. }
  177. }