PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/alex/zakupki/web/rest/UnfairSupplierResource.java

https://gitlab.com/bourd0n/zakupki
Java | 148 lines | 87 code | 16 blank | 45 comment | 4 complexity | cba9f39f91bc89eeb40af2767e2c441e MD5 | raw file
  1. package com.alex.zakupki.web.rest;
  2. import com.codahale.metrics.annotation.Timed;
  3. import com.alex.zakupki.domain.UnfairSupplier;
  4. import com.alex.zakupki.service.UnfairSupplierService;
  5. import com.alex.zakupki.web.rest.util.HeaderUtil;
  6. import com.alex.zakupki.web.rest.util.PaginationUtil;
  7. import io.swagger.annotations.ApiParam;
  8. import io.github.jhipster.web.util.ResponseUtil;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.data.domain.Page;
  12. import org.springframework.data.domain.Pageable;
  13. import org.springframework.http.HttpHeaders;
  14. import org.springframework.http.HttpStatus;
  15. import org.springframework.http.ResponseEntity;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.validation.Valid;
  18. import java.net.URI;
  19. import java.net.URISyntaxException;
  20. import java.util.List;
  21. import java.util.Optional;
  22. import java.util.stream.StreamSupport;
  23. import static org.elasticsearch.index.query.QueryBuilders.*;
  24. /**
  25. * REST controller for managing UnfairSupplier.
  26. */
  27. @RestController
  28. @RequestMapping("/api")
  29. public class UnfairSupplierResource {
  30. private final Logger log = LoggerFactory.getLogger(UnfairSupplierResource.class);
  31. private static final String ENTITY_NAME = "unfairSupplier";
  32. private final UnfairSupplierService unfairSupplierService;
  33. public UnfairSupplierResource(UnfairSupplierService unfairSupplierService) {
  34. this.unfairSupplierService = unfairSupplierService;
  35. }
  36. /**
  37. * POST /unfair-suppliers : Create a new unfairSupplier.
  38. *
  39. * @param unfairSupplier the unfairSupplier to create
  40. * @return the ResponseEntity with status 201 (Created) and with body the new unfairSupplier, or with status 400 (Bad Request) if the unfairSupplier has already an ID
  41. * @throws URISyntaxException if the Location URI syntax is incorrect
  42. */
  43. @PostMapping("/unfair-suppliers")
  44. @Timed
  45. public ResponseEntity<UnfairSupplier> createUnfairSupplier(@Valid @RequestBody UnfairSupplier unfairSupplier) throws URISyntaxException {
  46. log.debug("REST request to save UnfairSupplier : {}", unfairSupplier);
  47. if (unfairSupplier.getId() != null) {
  48. return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new unfairSupplier cannot already have an ID")).body(null);
  49. }
  50. UnfairSupplier result = unfairSupplierService.save(unfairSupplier);
  51. return ResponseEntity.created(new URI("/api/unfair-suppliers/" + result.getId()))
  52. .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
  53. .body(result);
  54. }
  55. /**
  56. * PUT /unfair-suppliers : Updates an existing unfairSupplier.
  57. *
  58. * @param unfairSupplier the unfairSupplier to update
  59. * @return the ResponseEntity with status 200 (OK) and with body the updated unfairSupplier,
  60. * or with status 400 (Bad Request) if the unfairSupplier is not valid,
  61. * or with status 500 (Internal Server Error) if the unfairSupplier couldn't be updated
  62. * @throws URISyntaxException if the Location URI syntax is incorrect
  63. */
  64. @PutMapping("/unfair-suppliers")
  65. @Timed
  66. public ResponseEntity<UnfairSupplier> updateUnfairSupplier(@Valid @RequestBody UnfairSupplier unfairSupplier) throws URISyntaxException {
  67. log.debug("REST request to update UnfairSupplier : {}", unfairSupplier);
  68. if (unfairSupplier.getId() == null) {
  69. return createUnfairSupplier(unfairSupplier);
  70. }
  71. UnfairSupplier result = unfairSupplierService.save(unfairSupplier);
  72. return ResponseEntity.ok()
  73. .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, unfairSupplier.getId().toString()))
  74. .body(result);
  75. }
  76. /**
  77. * GET /unfair-suppliers : get all the unfairSuppliers.
  78. *
  79. * @param pageable the pagination information
  80. * @return the ResponseEntity with status 200 (OK) and the list of unfairSuppliers in body
  81. */
  82. @GetMapping("/unfair-suppliers")
  83. @Timed
  84. public ResponseEntity<List<UnfairSupplier>> getAllUnfairSuppliers(@ApiParam Pageable pageable) {
  85. log.debug("REST request to get a page of UnfairSuppliers");
  86. Page<UnfairSupplier> page = unfairSupplierService.findAll(pageable);
  87. HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/unfair-suppliers");
  88. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  89. }
  90. /**
  91. * GET /unfair-suppliers/:id : get the "id" unfairSupplier.
  92. *
  93. * @param id the id of the unfairSupplier to retrieve
  94. * @return the ResponseEntity with status 200 (OK) and with body the unfairSupplier, or with status 404 (Not Found)
  95. */
  96. @GetMapping("/unfair-suppliers/{id}")
  97. @Timed
  98. public ResponseEntity<UnfairSupplier> getUnfairSupplier(@PathVariable Long id) {
  99. log.debug("REST request to get UnfairSupplier : {}", id);
  100. UnfairSupplier unfairSupplier = unfairSupplierService.findOne(id);
  101. return ResponseUtil.wrapOrNotFound(Optional.ofNullable(unfairSupplier));
  102. }
  103. /**
  104. * DELETE /unfair-suppliers/:id : delete the "id" unfairSupplier.
  105. *
  106. * @param id the id of the unfairSupplier to delete
  107. * @return the ResponseEntity with status 200 (OK)
  108. */
  109. @DeleteMapping("/unfair-suppliers/{id}")
  110. @Timed
  111. public ResponseEntity<Void> deleteUnfairSupplier(@PathVariable Long id) {
  112. log.debug("REST request to delete UnfairSupplier : {}", id);
  113. unfairSupplierService.delete(id);
  114. return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
  115. }
  116. /**
  117. * SEARCH /_search/unfair-suppliers?query=:query : search for the unfairSupplier corresponding
  118. * to the query.
  119. *
  120. * @param query the query of the unfairSupplier search
  121. * @param pageable the pagination information
  122. * @return the result of the search
  123. */
  124. @GetMapping("/_search/unfair-suppliers")
  125. @Timed
  126. public ResponseEntity<List<UnfairSupplier>> searchUnfairSuppliers(@RequestParam String query, @ApiParam Pageable pageable) {
  127. log.debug("REST request to search for a page of UnfairSuppliers for query {}", query);
  128. Page<UnfairSupplier> page = unfairSupplierService.search(query, pageable);
  129. HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/unfair-suppliers");
  130. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  131. }
  132. }