Skip to content

Commit

Permalink
fix: some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
eschrewe authored and tom-rm-meyer-ISST committed Oct 9, 2023
1 parent 4c9e8a5 commit b7d23f2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("materials")
Expand All @@ -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()) {
Expand Down Expand Up @@ -121,7 +122,7 @@ public ResponseEntity<?> updateMaterial(@RequestBody MaterialEntityDto materialD
})
public ResponseEntity<MaterialEntityDto> 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));
Expand All @@ -133,10 +134,10 @@ public ResponseEntity<MaterialEntityDto> 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<List<MaterialEntityDto>> listMaterials() {
ArrayList<MaterialEntityDto> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("partners")
Expand All @@ -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."),
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -162,8 +163,8 @@ public ResponseEntity<?> addSite(
@ApiResponse(responseCode = "500", description = "Internal Server Error.")
})
public ResponseEntity<PartnerDto> 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));
Expand All @@ -180,9 +181,9 @@ public ResponseEntity<PartnerDto> getPartner(
@GetMapping("/all")
@Operation(description = "Returns a list of all Partners. ")
public ResponseEntity<List<PartnerDto>> listPartners() {
ArrayList<PartnerDto> 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));
}

}

0 comments on commit b7d23f2

Please sign in to comment.