Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/4725 web api persistence #890

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added CorrelationId back in
  • Loading branch information
sdavis-amido committed Jul 21, 2022
commit e079a5edd3b3ff580908d75d7252143bf0083b66
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -44,9 +45,11 @@ public class CategoryController {
@CreateAPIResponses
ResponseEntity<ResourceCreatedResponse> createCategory(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Valid @RequestBody CreateCategoryRequest body) {
@Valid @RequestBody CreateCategoryRequest body,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(categoryService.create(menuId, body), HttpStatus.CREATED);
return new ResponseEntity<>(
categoryService.create(menuId, body, correlationId), HttpStatus.CREATED);
}

@PutMapping("/{categoryId}")
@@ -60,9 +63,11 @@ ResponseEntity<ResourceUpdatedResponse> updateCategory(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Parameter(description = "Category id", required = true) @PathVariable("categoryId")
UUID categoryId,
@Valid @RequestBody UpdateCategoryRequest body) {
@Valid @RequestBody UpdateCategoryRequest body,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(categoryService.update(menuId, categoryId, body), OK);
return new ResponseEntity<>(
categoryService.update(menuId, categoryId, body, correlationId), OK);
}

@DeleteMapping("/{categoryId}")
@@ -75,9 +80,10 @@ ResponseEntity<ResourceUpdatedResponse> updateCategory(
ResponseEntity<Void> deleteCategory(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Parameter(description = "Category id", required = true) @PathVariable("categoryId")
UUID categoryId) {
UUID categoryId,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

categoryService.delete(menuId, categoryId);
categoryService.delete(menuId, categoryId, correlationId);
return new ResponseEntity<>(OK);
}
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -46,9 +47,11 @@ ResponseEntity<ResourceCreatedResponse> createItem(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Parameter(description = "Category id", required = true) @PathVariable("categoryId")
UUID categoryId,
@Valid @RequestBody CreateItemRequest body) {
@Valid @RequestBody CreateItemRequest body,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(itemService.create(menuId, categoryId, body), HttpStatus.CREATED);
return new ResponseEntity<>(
itemService.create(menuId, categoryId, body, correlationId), HttpStatus.CREATED);
}

@PutMapping("/{itemId}")
@@ -63,10 +66,11 @@ ResponseEntity<ResourceUpdatedResponse> updateItem(
@Parameter(description = "Category id", required = true) @PathVariable("categoryId")
UUID categoryId,
@Parameter(description = "Item id", required = true) @PathVariable("itemId") UUID itemId,
@Valid @RequestBody UpdateItemRequest body) {
@Valid @RequestBody UpdateItemRequest body,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(
itemService.update(menuId, categoryId, itemId, body), HttpStatus.OK);
itemService.update(menuId, categoryId, itemId, body, correlationId), HttpStatus.OK);
}

@DeleteMapping("/{itemId}")
@@ -80,9 +84,10 @@ ResponseEntity<Void> deleteItem(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Parameter(description = "Category id", required = true) @PathVariable("categoryId")
UUID categoryId,
@Parameter(description = "Item id", required = true) @PathVariable("itemId") UUID itemId) {
@Parameter(description = "Item id", required = true) @PathVariable("itemId") UUID itemId,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

itemService.delete(menuId, categoryId, itemId);
itemService.delete(menuId, categoryId, itemId, correlationId);
return new ResponseEntity<>(OK);
}
}
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -45,9 +46,11 @@ public class MenuController {
description = "Adds a menu",
operationId = "CreateMenu")
@CreateAPIResponses
ResponseEntity<MenuDTO> createMenu(@Valid @RequestBody CreateMenuRequest dto) {
ResponseEntity<MenuDTO> createMenu(
@Valid @RequestBody CreateMenuRequest dto,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(menuService.create(dto), HttpStatus.CREATED);
return new ResponseEntity<>(menuService.create(dto, correlationId), HttpStatus.CREATED);
}

@GetMapping
@@ -68,10 +71,11 @@ ResponseEntity<SearchMenuResult> searchMenu(
@RequestParam(value = "searchTerm", required = false) String searchTerm,
@RequestParam(value = "restaurantId", required = false) UUID restaurantId,
@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
@RequestParam(value = "pageNumber", required = false, defaultValue = "1")
Integer pageNumber) {
@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return ResponseEntity.ok(menuService.search(searchTerm, restaurantId, pageSize, pageNumber));
return ResponseEntity.ok(
menuService.search(searchTerm, restaurantId, pageSize, pageNumber, correlationId));
}

@GetMapping(value = "/{id}")
@@ -88,9 +92,11 @@ ResponseEntity<SearchMenuResult> searchMenu(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = MenuDTO.class)))
@ReadAPIResponses
ResponseEntity<MenuDTO> getMenu(@PathVariable(name = "id") UUID id) {
ResponseEntity<MenuDTO> getMenu(
@PathVariable(name = "id") UUID id,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return ResponseEntity.ok(menuService.get(id));
return ResponseEntity.ok(menuService.get(id, correlationId));
}

@PutMapping(value = "/{id}")
@@ -101,9 +107,10 @@ ResponseEntity<MenuDTO> getMenu(@PathVariable(name = "id") UUID id) {
@UpdateAPIResponses
ResponseEntity<MenuDTO> updateMenu(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Valid @RequestBody UpdateMenuRequest body) {
@Valid @RequestBody UpdateMenuRequest body,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return new ResponseEntity<>(menuService.update(menuId, body), HttpStatus.OK);
return new ResponseEntity<>(menuService.update(menuId, body, correlationId), HttpStatus.OK);
}

@DeleteMapping(value = "/{id}")
@@ -114,9 +121,10 @@ ResponseEntity<MenuDTO> updateMenu(
operationId = "DeleteMenu")
@DeleteAPIResponses
ResponseEntity<Void> deleteMenu(
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId) {
@Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

menuService.delete(menuId);
menuService.delete(menuId, correlationId);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import com.amido.stacks.workloads.menu.api.v1.dto.response.MenuDTO;
import com.amido.stacks.workloads.menu.service.v2.MenuServiceV2;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -13,6 +14,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@@ -38,8 +40,10 @@ public class MenuControllerV2 {
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = MenuDTO.class)))
@ReadAPIResponses
ResponseEntity<MenuDTO> getMenu(@PathVariable(name = "id") UUID id) {
ResponseEntity<MenuDTO> getMenu(
@PathVariable(name = "id") UUID id,
@Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) {

return ResponseEntity.ok(menuServiceV2.get(id));
return ResponseEntity.ok(menuServiceV2.get(id, correlationId));
}
}
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@ public class CategoryService {

private final UpdateCategoryMapper updateCategoryMapper;

public ResourceCreatedResponse create(UUID menuId, @Valid CreateCategoryRequest body) {
public ResourceCreatedResponse create(
UUID menuId, @Valid CreateCategoryRequest body, String correlationId) {

Menu menu = getMenu(menuId);

@@ -53,7 +54,7 @@ public ResourceCreatedResponse create(UUID menuId, @Valid CreateCategoryRequest
}

public ResourceUpdatedResponse update(
UUID menuId, UUID categoryId, @Valid UpdateCategoryRequest body) {
UUID menuId, UUID categoryId, @Valid UpdateCategoryRequest body, String correlationId) {

Menu menu = getMenu(menuId);

@@ -73,7 +74,7 @@ public ResourceUpdatedResponse update(
return new ResourceUpdatedResponse(categoryId);
}

public void delete(UUID menuId, UUID categoryId) {
public void delete(UUID menuId, UUID categoryId, String correlationId) {

Menu menu = getMenu(menuId);

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public class ItemService {
private final ItemMapper itemMapper;

public ResourceCreatedResponse create(
UUID menuId, UUID categoryId, @Valid CreateItemRequest body) {
UUID menuId, UUID categoryId, @Valid CreateItemRequest body, String correlationId) {

Menu menu = getMenu(menuId);

@@ -55,7 +55,11 @@ public ResourceCreatedResponse create(
}

public ResourceUpdatedResponse update(
UUID menuId, UUID categoryId, UUID itemId, @Valid UpdateItemRequest body) {
UUID menuId,
UUID categoryId,
UUID itemId,
@Valid UpdateItemRequest body,
String correlationId) {

Menu menu = getMenu(menuId);

@@ -74,7 +78,7 @@ public ResourceUpdatedResponse update(
return new ResourceUpdatedResponse(itemId);
}

public void delete(UUID menuId, UUID categoryId, UUID itemId) {
public void delete(UUID menuId, UUID categoryId, UUID itemId, String correlationId) {

Menu menu = getMenu(menuId);

Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public class MenuService {

private final SearchMenuResultItemMapper searchMenuResultItemMapper;

public MenuDTO create(@Valid CreateMenuRequest dto) {
public MenuDTO create(@Valid CreateMenuRequest dto, String correlationId) {

verifyMenuNotAlreadyExisting(dto.getTenantId(), dto.getName());

@@ -55,7 +55,11 @@ public MenuDTO create(@Valid CreateMenuRequest dto) {
}

public SearchMenuResult search(
String searchTerm, UUID restaurantId, Integer pageSize, Integer pageNumber) {
String searchTerm,
UUID restaurantId,
Integer pageSize,
Integer pageNumber,
String correlationId) {

List<Menu> menuList;

@@ -77,7 +81,7 @@ public SearchMenuResult search(
menuList.stream().map(searchMenuResultItemMapper::toDto).collect(Collectors.toList()));
}

public MenuDTO get(UUID menuId) {
public MenuDTO get(UUID menuId, String correlationId) {

Optional<Menu> optMenu = menuQueryService.findById(menuId);

@@ -88,7 +92,7 @@ public MenuDTO get(UUID menuId) {
throw new MenuNotFoundException(menuId);
}

public MenuDTO update(UUID menuId, @Valid UpdateMenuRequest dto) {
public MenuDTO update(UUID menuId, @Valid UpdateMenuRequest dto, String correlationId) {

Optional<Menu> optMenu = menuQueryService.findById(menuId);

@@ -100,7 +104,7 @@ public MenuDTO update(UUID menuId, @Valid UpdateMenuRequest dto) {

menuRepository.save(menuMapper.fromDto(menuDTO));

return get(menuId);
return get(menuId, correlationId);
}

throw new MenuNotFoundException(menuId);
@@ -117,7 +121,7 @@ public void verifyMenuNotAlreadyExisting(UUID restaurantId, String name) {
}
}

public void delete(UUID menuId) {
public void delete(UUID menuId, String correlationId) {

Optional<Menu> optMenu = menuQueryService.findById(menuId);

Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ public MenuServiceV2(
}

@Override
public MenuDTO get(UUID id) {
public MenuDTO get(UUID id, String correlationId) {

return super.get(id);
return super.get(id, correlationId);
}
}