|
| 1 | +package com.epam.reportportal.core.tms.controller; |
| 2 | + |
| 3 | +import com.epam.reportportal.infrastructure.persistence.commons.EntityUtils; |
| 4 | +import com.epam.reportportal.infrastructure.persistence.commons.ReportPortalUser; |
| 5 | +import com.epam.reportportal.core.tms.dto.ProductVersionRQ; |
| 6 | +import com.epam.reportportal.core.tms.dto.TmsProductVersionRS; |
| 7 | +import com.epam.reportportal.core.tms.service.ProductVersionService; |
| 8 | +import com.epam.reportportal.util.ProjectExtractor; |
| 9 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 10 | +import lombok.RequiredArgsConstructor; |
| 11 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 12 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 13 | +import org.springframework.web.bind.annotation.GetMapping; |
| 14 | +import org.springframework.web.bind.annotation.PathVariable; |
| 15 | +import org.springframework.web.bind.annotation.PostMapping; |
| 16 | +import org.springframework.web.bind.annotation.PutMapping; |
| 17 | +import org.springframework.web.bind.annotation.RequestBody; |
| 18 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 19 | +import org.springframework.web.bind.annotation.RestController; |
| 20 | + |
| 21 | +/** |
| 22 | + * Controller for managing product versions within a project. Each endpoint |
| 23 | + * in this controller is secured and requires the user to have administrator |
| 24 | + * privileges. Operations supported include creating, retrieving, updating, |
| 25 | + * and deleting product versions associated with a specific project. |
| 26 | + */ |
| 27 | +@RestController |
| 28 | +@RequestMapping("/v1/project/{projectKey}/tms/productversion") |
| 29 | +@Tag(name = "Product Version", description = "Product Version API collection") |
| 30 | +@RequiredArgsConstructor |
| 31 | +public class ProductVersionController { |
| 32 | + |
| 33 | + private final ProductVersionService productVersionService; |
| 34 | + private final ProjectExtractor projectExtractor; |
| 35 | + |
| 36 | + /** |
| 37 | + * Retrieves a specific product version by its ID within a project. |
| 38 | + * |
| 39 | + * @param projectKey The key of the project to which the product version belongs. |
| 40 | + * @param productVersionId The ID of the product version to retrieve. |
| 41 | + * @return A data transfer object ({@link TmsProductVersionRS}) containing details of the product version. |
| 42 | + */ |
| 43 | + @GetMapping("/{productVersionId}") |
| 44 | + TmsProductVersionRS getById(@PathVariable("projectKey") String projectKey, |
| 45 | + @PathVariable("productVersionId") final long productVersionId, |
| 46 | + @AuthenticationPrincipal ReportPortalUser user) { |
| 47 | + return productVersionService.getById( |
| 48 | + projectExtractor |
| 49 | + .extractMembershipDetails(user, EntityUtils.normalizeId(projectKey)) |
| 50 | + .getProjectId(), |
| 51 | + productVersionId); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Creates a new product version in the specified project. |
| 56 | + * |
| 57 | + * @param projectKey The key of the project to which the new product version will be added. |
| 58 | + * @param inputDto A request payload ({@link ProductVersionRQ}) containing information |
| 59 | + * about the product version to create. |
| 60 | + * @return A data transfer object ({@link TmsProductVersionRS}) with details of the created product version. |
| 61 | + */ |
| 62 | + @PostMapping |
| 63 | + TmsProductVersionRS createVersion(@PathVariable("projectKey") String projectKey, |
| 64 | + @RequestBody final ProductVersionRQ inputDto, |
| 65 | + @AuthenticationPrincipal ReportPortalUser user) { |
| 66 | + return productVersionService.create( |
| 67 | + projectExtractor |
| 68 | + .extractMembershipDetails(user, EntityUtils.normalizeId(projectKey)) |
| 69 | + .getProjectId(), |
| 70 | + inputDto); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Updates the details of an existing product version in a project. |
| 75 | + * |
| 76 | + * @param projectKey The key of the project to which the product version belongs. |
| 77 | + * @param productVersionId The ID of the product version to update. |
| 78 | + * @param inputDto A request payload ({@link ProductVersionRQ}) containing updated information |
| 79 | + * for the product version. |
| 80 | + * @return A data transfer object ({@link TmsProductVersionRS}) with updated details of the product version. |
| 81 | + */ |
| 82 | + @PutMapping("/{productVersionId}") |
| 83 | + TmsProductVersionRS updateVersion(@PathVariable("projectKey") String projectKey, |
| 84 | + @PathVariable("productVersionId") final long productVersionId, |
| 85 | + @RequestBody final ProductVersionRQ inputDto, |
| 86 | + @AuthenticationPrincipal ReportPortalUser user) { |
| 87 | + return productVersionService.update( |
| 88 | + projectExtractor |
| 89 | + .extractMembershipDetails(user, EntityUtils.normalizeId(projectKey)) |
| 90 | + .getProjectId(), |
| 91 | + productVersionId, |
| 92 | + inputDto); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Deletes a specific product version from a project. |
| 97 | + * |
| 98 | + * @param projectKey The key of the project to which the product version belongs. |
| 99 | + * @param productVersionId The ID of the product version to delete. |
| 100 | + */ |
| 101 | + @DeleteMapping("/{productVersionId}") |
| 102 | + void deleteVersion(@PathVariable("projectKey") String projectKey, |
| 103 | + @PathVariable("productVersionId") final long productVersionId, |
| 104 | + @AuthenticationPrincipal ReportPortalUser user) { |
| 105 | + productVersionService.delete( |
| 106 | + projectExtractor |
| 107 | + .extractMembershipDetails(user, EntityUtils.normalizeId(projectKey)) |
| 108 | + .getProjectId(), |
| 109 | + productVersionId); |
| 110 | + } |
| 111 | +} |
0 commit comments