diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialController.java index 8bced97e..af809c92 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialController.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("materials") @@ -51,9 +52,9 @@ public class MaterialController { "it must contain a new, unique ownMaterialNumber.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successfully created a new Material entity."), - @ApiResponse(responseCode = "400", description = "Malformed request body"), + @ApiResponse(responseCode = "400", description = "Malformed request body."), @ApiResponse(responseCode = "409", description = "Material with the given ownMaterialNumber already exists."), - @ApiResponse(responseCode = "500", description = "Internal Server error") + @ApiResponse(responseCode = "500", description = "Internal Server error.") }) public ResponseEntity createMaterial(@RequestBody MaterialEntityDto materialDto) { if (materialDto.getOwnMaterialNumber() == null || materialDto.getOwnMaterialNumber().isEmpty()) { @@ -121,7 +122,7 @@ public ResponseEntity updateMaterial(@RequestBody MaterialEntityDto materialD }) public ResponseEntity getMaterial(@Parameter(name = "ownMaterialNumber", description = "The Material Number that is used in your own company to identify the Material.", - example = "MNR-7307-AU340474.002", required = true) @RequestParam String ownMaterialNumber) { + example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber) { Material foundMaterial = materialService.findByOwnMaterialNumber(ownMaterialNumber); if (foundMaterial == null) { return new ResponseEntity<>(HttpStatusCode.valueOf(404)); @@ -133,10 +134,10 @@ public ResponseEntity getMaterial(@Parameter(name = "ownMater @CrossOrigin @GetMapping("/all") - @Operation(description = "Returns a list of all Materials and Products. ") + @Operation(description = "Returns a list of all Materials and Products.") public ResponseEntity> listMaterials() { - ArrayList outputList = new ArrayList<>(); - materialService.findAll().stream().forEach(mat -> outputList.add(modelMapper.map(mat, MaterialEntityDto.class))); - return new ResponseEntity<>(outputList, HttpStatusCode.valueOf(200)); + return new ResponseEntity<>(materialService.findAll(). + stream().map(x -> modelMapper.map(x, MaterialEntityDto.class)).collect(Collectors.toList()), + HttpStatusCode.valueOf(200)); } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialPartnerRelationsController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialPartnerRelationsController.java index 6680a862..9b3c19db 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialPartnerRelationsController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialPartnerRelationsController.java @@ -61,18 +61,18 @@ public class MaterialPartnerRelationsController { @ApiResponse(responseCode = "200", description = "Successfully created a new MaterialPartnerRelationEntity."), @ApiResponse(responseCode = "400", description = "Material and/or Partner do not exist."), @ApiResponse(responseCode = "409", description = "Relation for given Material and Partner does already exist."), - @ApiResponse(responseCode = "500", description = "Internal Server Error") + @ApiResponse(responseCode = "500", description = "Internal Server Error.") }) public ResponseEntity createMaterialPartnerRelation( - @Parameter(name = "ownMaterialNumber", description = "The Material Number that is used in your own company to identify the Material.", - example = "MNR-7307-AU340474.002", required = true) @RequestParam String ownMaterialNumber, - @Parameter(name = "partnerBpnl", description = "The unique BPNL that was assigned to that Partner.", - example = "BPNL2222222222RR", required = true) @RequestParam() String partnerBpnl, - @Parameter(name = "partnerMaterialNumber", description = "The Material Number that this Partner is using in his own company to identify the Material.", + @Parameter(description = "The Material Number that is used in your own company to identify the Material.", + example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber, + @Parameter(description = "The unique BPNL that was assigned to that Partner.", + example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, + @Parameter(description = "The Material Number that this Partner is using in his own company to identify the Material.", example = "MNR-8101-ID146955.001") @RequestParam String partnerMaterialNumber, - @Parameter(name = "partnerSupplies", description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", + @Parameter(description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", example = "true") @RequestParam boolean partnerSupplies, - @Parameter(name = "partnerBuys", description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", + @Parameter(description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", example = "true") @RequestParam boolean partnerBuys) { Material material = materialService.findByOwnMaterialNumber(ownMaterialNumber); if (material == null || partnerBpnl == null) { @@ -105,19 +105,19 @@ public ResponseEntity createMaterialPartnerRelation( "the partnerBpnl. The other three parameters are genuinely optional. Provide them only if you want to change their values. ") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Update was accepted."), - @ApiResponse(responseCode = "404", description = "No existing entity was found. "), - @ApiResponse(responseCode = "500", description = "Internal Server Error") + @ApiResponse(responseCode = "404", description = "No existing entity was found."), + @ApiResponse(responseCode = "500", description = "Internal Server Error.") }) public ResponseEntity updateMaterialPartnerRelation( - @Parameter(name = "ownMaterialNumber", description = "The Material Number that is used in your own company to identify the Material.", - example = "MNR-7307-AU340474.002", required = true) @RequestParam String ownMaterialNumber, - @Parameter(name = "partnerBpnl", description = "The unique BPNL that was assigned to that Partner.", - example = "BPNL2222222222RR", required = true) @RequestParam() String partnerBpnl, - @Parameter(name = "partnerMaterialNumber", description = "The Material Number that this Partner is using in his own company to identify the Material.", + @Parameter(description = "The Material Number that is used in your own company to identify the Material.", + example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber, + @Parameter(description = "The unique BPNL that was assigned to that Partner.", + example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, + @Parameter(description = "The Material Number that this Partner is using in his own company to identify the Material.", example = "MNR-8101-ID146955.001") @RequestParam(required = false) String partnerMaterialNumber, - @Parameter(name = "partnerSupplies", description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", + @Parameter(description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", example = "true") @RequestParam(required = false) Boolean partnerSupplies, - @Parameter(name = "partnerBuys", description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", + @Parameter(description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", example = "true") @RequestParam(required = false) Boolean partnerBuys) { MaterialPartnerRelation existingRelation = null; Partner partner = partnerService.findByBpnl(partnerBpnl); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/PartnerController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/PartnerController.java index 4faa3c4b..a00989a7 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/PartnerController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/PartnerController.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.*; import java.util.*; +import java.util.stream.Collectors; @RestController @RequestMapping("partners") @@ -45,7 +46,7 @@ public class PartnerController { @CrossOrigin @PostMapping - @Operation(description = "Creates a new Partner entity with the data given in the request body. Please not that no " + + @Operation(description = "Creates a new Partner entity with the data given in the request body. Please note that no " + "UUID can be assigned to a Partner that wasn't created before. So the request body must not contain a UUID.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Partner created successfully."), @@ -83,17 +84,17 @@ public ResponseEntity createPartner(@RequestBody PartnerDto partnerDto) { @PutMapping("putAddress") @CrossOrigin - @Operation(description = "Updates an existing Partner by adding a new Address. If that this Partner already has " + + @Operation(description = "Updates an existing Partner by adding a new Address. If that Partner already has " + "an Address with the BPNA given in the request body, that existing Address will be overwritten. ") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Update accepted"), - @ApiResponse(responseCode = "400", description = "Invalid Address data"), - @ApiResponse(responseCode = "404", description = "Partner not found"), - @ApiResponse(responseCode = "500", description = "") + @ApiResponse(responseCode = "200", description = "Update accepted."), + @ApiResponse(responseCode = "400", description = "Invalid Address data."), + @ApiResponse(responseCode = "404", description = "Partner not found."), + @ApiResponse(responseCode = "500", description = "Internal Server Error.") }) public ResponseEntity addAddress( - @Parameter(name = "partnerBpnl", description = "The unique BPNL that was assigned to that Partner.", - example = "BPNL2222222222RR", required = true) @RequestParam() String partnerBpnl, + @Parameter(description = "The unique BPNL that was assigned to that Partner.", + example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, @RequestBody AddressDto address) { Partner existingPartner = partnerService.findByBpnl(partnerBpnl); if (existingPartner == null) { @@ -118,17 +119,17 @@ public ResponseEntity addAddress( @PutMapping("putSite") @CrossOrigin - @Operation(description = "Updates an existing Partner by adding a new Site. If that this Partner already has " + + @Operation(description = "Updates an existing Partner by adding a new Site. If that Partner already has " + "a Site with the BPNS given in the request body, that existing Site will be overwritten. ") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Update accepted"), - @ApiResponse(responseCode = "400", description = "Invalid Address data"), - @ApiResponse(responseCode = "404", description = "Partner not found"), - @ApiResponse(responseCode = "500", description = "") + @ApiResponse(responseCode = "200", description = "Update accepted."), + @ApiResponse(responseCode = "400", description = "Invalid Address data."), + @ApiResponse(responseCode = "404", description = "Partner not found."), + @ApiResponse(responseCode = "500", description = "Internal Server Error.") }) public ResponseEntity addSite( - @Parameter(name = "partnerBpnl", description = "The unique BPNL that was assigned to that Partner.", - example = "BPNL2222222222RR", required = true) @RequestParam() String partnerBpnl, + @Parameter(description = "The unique BPNL that was assigned to that Partner.", + example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, @RequestBody SiteDto site) { Partner existingPartner = partnerService.findByBpnl(partnerBpnl); if (existingPartner == null) { @@ -162,8 +163,8 @@ public ResponseEntity addSite( @ApiResponse(responseCode = "500", description = "Internal Server Error.") }) public ResponseEntity getPartner( - @Parameter(name = "partnerBpnl", description = "The unique BPNL that was assigned to that Partner.", - example = "BPNL2222222222RR", required = true) @RequestParam() String partnerBpnl) { + @Parameter(description = "The unique BPNL that was assigned to that Partner.", + example = "BPNL2222222222RR") @RequestParam() String partnerBpnl) { Partner partner = partnerService.findByBpnl(partnerBpnl); if (partner == null) { return new ResponseEntity<>(HttpStatusCode.valueOf(404)); @@ -180,9 +181,9 @@ public ResponseEntity getPartner( @GetMapping("/all") @Operation(description = "Returns a list of all Partners. ") public ResponseEntity> listPartners() { - ArrayList outputList = new ArrayList<>(); - partnerService.findAll().stream().forEach(partner -> outputList.add(modelMapper.map(partner, PartnerDto.class))); - return new ResponseEntity<>(outputList, HttpStatusCode.valueOf(200)); + return new ResponseEntity<>(partnerService.findAll(). + stream().map(partner -> modelMapper.map(partner, PartnerDto.class)).collect(Collectors.toList()), + HttpStatusCode.valueOf(200)); } }