|
| 1 | +package com.catalogservice.adapter.api; |
| 2 | + |
| 3 | +import com.catalogservice.adapter.api.model.CatalogDto; |
| 4 | +import com.catalogservice.adapter.api.model.SaveCatalogDto; |
| 5 | +import org.springframework.http.HttpStatus; |
| 6 | +import org.springframework.http.ResponseEntity; |
| 7 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 8 | +import org.springframework.web.bind.annotation.GetMapping; |
| 9 | +import org.springframework.web.bind.annotation.PathVariable; |
| 10 | +import org.springframework.web.bind.annotation.PostMapping; |
| 11 | +import org.springframework.web.bind.annotation.PutMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | +import org.springframework.web.bind.annotation.RestController; |
| 15 | + |
| 16 | +@RestController |
| 17 | +@RequestMapping(value = "/v1") |
| 18 | +public class CatalogController { |
| 19 | + |
| 20 | + private final UpdateCatalogAdaptor catalogUpdateAdaptor; |
| 21 | + private final FindCatalogAdapter findCatalogAdapter; |
| 22 | + |
| 23 | + public CatalogController(UpdateCatalogAdaptor catalogUpdateAdaptor, FindCatalogAdapter findCatalogAdapter) { |
| 24 | + this.catalogUpdateAdaptor = catalogUpdateAdaptor; |
| 25 | + this.findCatalogAdapter = findCatalogAdapter; |
| 26 | + } |
| 27 | + |
| 28 | + @PostMapping("/catalog") |
| 29 | + public ResponseEntity<CatalogDto> saveCatalog(@RequestBody SaveCatalogDto saveCatalogDto) { |
| 30 | + CatalogDto createdCatalog = catalogUpdateAdaptor.save(saveCatalogDto.catalogDto()); |
| 31 | + return ResponseEntity.status(HttpStatus.CREATED).body(createdCatalog); |
| 32 | + } |
| 33 | + |
| 34 | + @PutMapping("/catalog/{catalogId}") |
| 35 | + public ResponseEntity<CatalogDto> updateCatalog(@PathVariable Long catalogId, @RequestBody SaveCatalogDto catalogDto) { |
| 36 | + CatalogDto updateCatalog = catalogUpdateAdaptor.update(catalogId, catalogDto.catalogDto()); |
| 37 | + return ResponseEntity.status(HttpStatus.OK).body(updateCatalog); |
| 38 | + } |
| 39 | + |
| 40 | + @GetMapping("/catalog/{catalogId}") |
| 41 | + public ResponseEntity<CatalogDto> getCatalog(@PathVariable Long catalogId) { |
| 42 | + CatalogDto catalogDto = findCatalogAdapter.findById(catalogId); |
| 43 | + return ResponseEntity.status(HttpStatus.OK).body(catalogDto); |
| 44 | + } |
| 45 | + |
| 46 | + @DeleteMapping("/catalog/{catalogId}") |
| 47 | + public ResponseEntity<Void> deleteCatalog(@PathVariable Long catalogId) { |
| 48 | + return ResponseEntity.noContent().build(); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments