PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/bourd0n/zakupki
Java | 148 lines | 87 code | 16 blank | 45 comment | 4 complexity | 9674a9a06cd7e9b5104c7f3500455c7d MD5 | raw file
  1. package com.alex.zakupki.web.rest;
  2. import com.codahale.metrics.annotation.Timed;
  3. import com.alex.zakupki.domain.RegistrationKo;
  4. import com.alex.zakupki.service.RegistrationKoService;
  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 RegistrationKo.
  26. */
  27. @RestController
  28. @RequestMapping("/api")
  29. public class RegistrationKoResource {
  30. private final Logger log = LoggerFactory.getLogger(RegistrationKoResource.class);
  31. private static final String ENTITY_NAME = "registrationKo";
  32. private final RegistrationKoService registrationKoService;
  33. public RegistrationKoResource(RegistrationKoService registrationKoService) {
  34. this.registrationKoService = registrationKoService;
  35. }
  36. /**
  37. * POST /registration-kos : Create a new registrationKo.
  38. *
  39. * @param registrationKo the registrationKo to create
  40. * @return the ResponseEntity with status 201 (Created) and with body the new registrationKo, or with status 400 (Bad Request) if the registrationKo has already an ID
  41. * @throws URISyntaxException if the Location URI syntax is incorrect
  42. */
  43. @PostMapping("/registration-kos")
  44. @Timed
  45. public ResponseEntity<RegistrationKo> createRegistrationKo(@Valid @RequestBody RegistrationKo registrationKo) throws URISyntaxException {
  46. log.debug("REST request to save RegistrationKo : {}", registrationKo);
  47. if (registrationKo.getId() != null) {
  48. return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new registrationKo cannot already have an ID")).body(null);
  49. }
  50. RegistrationKo result = registrationKoService.save(registrationKo);
  51. return ResponseEntity.created(new URI("/api/registration-kos/" + result.getId()))
  52. .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
  53. .body(result);
  54. }
  55. /**
  56. * PUT /registration-kos : Updates an existing registrationKo.
  57. *
  58. * @param registrationKo the registrationKo to update
  59. * @return the ResponseEntity with status 200 (OK) and with body the updated registrationKo,
  60. * or with status 400 (Bad Request) if the registrationKo is not valid,
  61. * or with status 500 (Internal Server Error) if the registrationKo couldn't be updated
  62. * @throws URISyntaxException if the Location URI syntax is incorrect
  63. */
  64. @PutMapping("/registration-kos")
  65. @Timed
  66. public ResponseEntity<RegistrationKo> updateRegistrationKo(@Valid @RequestBody RegistrationKo registrationKo) throws URISyntaxException {
  67. log.debug("REST request to update RegistrationKo : {}", registrationKo);
  68. if (registrationKo.getId() == null) {
  69. return createRegistrationKo(registrationKo);
  70. }
  71. RegistrationKo result = registrationKoService.save(registrationKo);
  72. return ResponseEntity.ok()
  73. .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, registrationKo.getId().toString()))
  74. .body(result);
  75. }
  76. /**
  77. * GET /registration-kos : get all the registrationKos.
  78. *
  79. * @param pageable the pagination information
  80. * @return the ResponseEntity with status 200 (OK) and the list of registrationKos in body
  81. */
  82. @GetMapping("/registration-kos")
  83. @Timed
  84. public ResponseEntity<List<RegistrationKo>> getAllRegistrationKos(@ApiParam Pageable pageable) {
  85. log.debug("REST request to get a page of RegistrationKos");
  86. Page<RegistrationKo> page = registrationKoService.findAll(pageable);
  87. HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/registration-kos");
  88. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  89. }
  90. /**
  91. * GET /registration-kos/:id : get the "id" registrationKo.
  92. *
  93. * @param id the id of the registrationKo to retrieve
  94. * @return the ResponseEntity with status 200 (OK) and with body the registrationKo, or with status 404 (Not Found)
  95. */
  96. @GetMapping("/registration-kos/{id}")
  97. @Timed
  98. public ResponseEntity<RegistrationKo> getRegistrationKo(@PathVariable Long id) {
  99. log.debug("REST request to get RegistrationKo : {}", id);
  100. RegistrationKo registrationKo = registrationKoService.findOne(id);
  101. return ResponseUtil.wrapOrNotFound(Optional.ofNullable(registrationKo));
  102. }
  103. /**
  104. * DELETE /registration-kos/:id : delete the "id" registrationKo.
  105. *
  106. * @param id the id of the registrationKo to delete
  107. * @return the ResponseEntity with status 200 (OK)
  108. */
  109. @DeleteMapping("/registration-kos/{id}")
  110. @Timed
  111. public ResponseEntity<Void> deleteRegistrationKo(@PathVariable Long id) {
  112. log.debug("REST request to delete RegistrationKo : {}", id);
  113. registrationKoService.delete(id);
  114. return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
  115. }
  116. /**
  117. * SEARCH /_search/registration-kos?query=:query : search for the registrationKo corresponding
  118. * to the query.
  119. *
  120. * @param query the query of the registrationKo search
  121. * @param pageable the pagination information
  122. * @return the result of the search
  123. */
  124. @GetMapping("/_search/registration-kos")
  125. @Timed
  126. public ResponseEntity<List<RegistrationKo>> searchRegistrationKos(@RequestParam String query, @ApiParam Pageable pageable) {
  127. log.debug("REST request to search for a page of RegistrationKos for query {}", query);
  128. Page<RegistrationKo> page = registrationKoService.search(query, pageable);
  129. HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/registration-kos");
  130. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  131. }
  132. }