Browse Source

feat: implements new params to ReadInstalledItems

Matheus Marques Polillo 9 months ago
parent
commit
d74b7c9537

+ 62 - 3
src/presentation/cli/controller/marketplace.go

@@ -31,8 +31,7 @@ func (controller *MarketplaceController) ReadCatalog() *cobra.Command {
 	var catalogItemSlugStr, catalogItemNameStr, catalogItemTypeStr string
 	var paginationPageNumberUint32 uint32
 	var paginationItemsPerPageUint16 uint16
-	var paginationSortByStr, paginationSortDirectionStr string
-	var paginationLastSeenIdStr string
+	var paginationSortByStr, paginationSortDirectionStr, paginationLastSeenIdStr string
 
 	cmd := &cobra.Command{
 		Use:   "list-catalog",
@@ -203,16 +202,76 @@ func (controller *MarketplaceController) InstallCatalogItem() *cobra.Command {
 }
 
 func (controller *MarketplaceController) ReadInstalledItems() *cobra.Command {
+	var installedItemIdUint uint64
+	var installedItemTypeStr string
+	var paginationPageNumberUint32 uint32
+	var paginationItemsPerPageUint16 uint16
+	var paginationSortByStr, paginationSortDirectionStr, paginationLastSeenIdStr string
+
 	cmd := &cobra.Command{
 		Use:   "list",
 		Short: "ReadInstalledItems",
 		Run: func(cmd *cobra.Command, args []string) {
+			requestBody := map[string]interface{}{}
+
+			if installedItemIdUint != 0 {
+				requestBody["id"] = installedItemIdUint
+			}
+
+			if installedItemTypeStr != "" {
+				requestBody["type"] = installedItemTypeStr
+			}
+
+			if paginationPageNumberUint32 != 0 {
+				requestBody["pageNumber"] = paginationPageNumberUint32
+			}
+
+			if paginationItemsPerPageUint16 != 0 {
+				requestBody["itemsPerPage"] = paginationItemsPerPageUint16
+			}
+
+			if paginationSortByStr != "" {
+				requestBody["sortBy"] = paginationSortByStr
+			}
+
+			if paginationSortDirectionStr != "" {
+				requestBody["sortDirection"] = paginationSortDirectionStr
+			}
+
+			if paginationLastSeenIdStr != "" {
+				requestBody["lastSeenId"] = paginationLastSeenIdStr
+			}
+
 			cliHelper.ServiceResponseWrapper(
-				controller.marketplaceService.ReadInstalledItems(),
+				controller.marketplaceService.ReadInstalledItems(requestBody),
 			)
 		},
 	}
 
+	cmd.Flags().Uint64VarP(
+		&installedItemIdUint, "installed-item-id", "i", 0, "InstalledItemId",
+	)
+	cmd.Flags().StringVarP(
+		&installedItemTypeStr, "installed-item-type", "t", "", "InstalledItemType",
+	)
+	cmd.Flags().Uint32VarP(
+		&paginationPageNumberUint32, "page-number", "p", 0, "PageNumber (Pagination)",
+	)
+	cmd.Flags().Uint16VarP(
+		&paginationItemsPerPageUint16, "items-per-page", "m", 0,
+		"ItemsPerPage (Pagination)",
+	)
+	cmd.Flags().StringVarP(
+		&paginationSortByStr, "sort-by", "y", "", "SortBy (Pagination)",
+	)
+	cmd.Flags().StringVarP(
+		&paginationSortDirectionStr, "sort-direction", "r", "",
+		"SortDirection (Pagination)",
+	)
+	cmd.Flags().StringVarP(
+		&paginationLastSeenIdStr, "last-seen-id", "l", "", "LastSeenId (Pagination)",
+	)
+
 	return cmd
 }
 

+ 94 - 11
src/presentation/service/marketplace.go

@@ -96,7 +96,9 @@ func (service *MarketplaceService) ReadCatalog(
 	}
 
 	if input["sortDirection"] != nil {
-		sortDirection, err := valueObject.NewPaginationSortDirection(input["sortDirection"])
+		sortDirection, err := valueObject.NewPaginationSortDirection(
+			input["sortDirection"],
+		)
 		if err != nil {
 			return NewServiceOutput(UserError, err)
 		}
@@ -119,8 +121,10 @@ func (service *MarketplaceService) ReadCatalog(
 		ItemType:   typePtr,
 	}
 
-	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(service.persistentDbSvc)
-	itemsList, err := useCase.ReadMarketplaceCatalog(marketplaceQueryRepo, readDto)
+	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(
+		service.persistentDbSvc,
+	)
+	itemsList, err := useCase.ReadMarketplaceCatalogItems(marketplaceQueryRepo, readDto)
 	if err != nil {
 		return NewServiceOutput(InfraError, err.Error())
 	}
@@ -195,12 +199,12 @@ func (service *MarketplaceService) InstallCatalogItem(
 		}
 
 		if urlPathPtr != nil {
-			installParams = append(installParams, "--urlPath", urlPathPtr.String())
+			installParams = append(installParams, "--url-path", urlPathPtr.String())
 		}
 
 		for _, dataField := range dataFields {
 			escapedField := shellescape.Quote(dataField.String())
-			installParams = append(installParams, "--dataFields", escapedField)
+			installParams = append(installParams, "--data-fields", escapedField)
 		}
 
 		cliCmd += " " + strings.Join(installParams, " ")
@@ -243,9 +247,82 @@ func (service *MarketplaceService) InstallCatalogItem(
 	return NewServiceOutput(Created, "MarketplaceCatalogItemInstalled")
 }
 
-func (service *MarketplaceService) ReadInstalledItems() ServiceOutput {
-	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(service.persistentDbSvc)
-	itemsList, err := useCase.ReadMarketplaceInstalledItems(marketplaceQueryRepo)
+func (service *MarketplaceService) ReadInstalledItems(
+	input map[string]interface{},
+) ServiceOutput {
+	var idPtr *valueObject.MarketplaceItemId
+	if input["id"] != nil {
+		id, err := valueObject.NewMarketplaceItemId(input["id"])
+		if err != nil {
+			return NewServiceOutput(UserError, err)
+		}
+		idPtr = &id
+	}
+
+	var typePtr *valueObject.MarketplaceItemType
+	if input["type"] != nil {
+		itemType, err := valueObject.NewMarketplaceItemType(input["type"])
+		if err != nil {
+			return NewServiceOutput(UserError, err)
+		}
+		typePtr = &itemType
+	}
+
+	paginationDto := useCase.MarketplaceDefaultPagination
+	if input["pageNumber"] != nil {
+		pageNumber, err := voHelper.InterfaceToUint32(input["pageNumber"])
+		if err != nil {
+			return NewServiceOutput(UserError, errors.New("InvalidPageNumber"))
+		}
+		paginationDto.PageNumber = pageNumber
+	}
+
+	if input["itemsPerPage"] != nil {
+		itemsPerPage, err := voHelper.InterfaceToUint16(input["itemsPerPage"])
+		if err != nil {
+			return NewServiceOutput(UserError, errors.New("InvalidItemsPerPage"))
+		}
+		paginationDto.ItemsPerPage = itemsPerPage
+	}
+
+	if input["sortBy"] != nil {
+		sortBy, err := valueObject.NewPaginationSortBy(input["sortBy"])
+		if err != nil {
+			return NewServiceOutput(UserError, err)
+		}
+		paginationDto.SortBy = &sortBy
+	}
+
+	if input["sortDirection"] != nil {
+		sortDirection, err := valueObject.NewPaginationSortDirection(
+			input["sortDirection"],
+		)
+		if err != nil {
+			return NewServiceOutput(UserError, err)
+		}
+		paginationDto.SortDirection = &sortDirection
+	}
+
+	if input["lastSeenId"] != nil {
+		lastSeenId, err := valueObject.NewPaginationLastSeenId(input["lastSeenId"])
+		if err != nil {
+			return NewServiceOutput(UserError, err)
+		}
+		paginationDto.LastSeenId = &lastSeenId
+	}
+
+	readDto := dto.ReadMarketplaceInstalledItemsRequest{
+		Pagination: paginationDto,
+		ItemId:     idPtr,
+		ItemType:   typePtr,
+	}
+
+	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(
+		service.persistentDbSvc,
+	)
+	itemsList, err := useCase.ReadMarketplaceInstalledItems(
+		marketplaceQueryRepo, readDto,
+	)
 	if err != nil {
 		return NewServiceOutput(InfraError, err.Error())
 	}
@@ -288,7 +365,9 @@ func (service *MarketplaceService) DeleteInstalledItem(
 
 		cliCmd += " " + strings.Join(installParams, " ")
 
-		scheduledTaskCmdRepo := scheduledTaskInfra.NewScheduledTaskCmdRepo(service.persistentDbSvc)
+		scheduledTaskCmdRepo := scheduledTaskInfra.NewScheduledTaskCmdRepo(
+			service.persistentDbSvc,
+		)
 		taskName, _ := valueObject.NewScheduledTaskName("DeleteMarketplaceCatalogItem")
 		taskCmd, _ := valueObject.NewUnixCommand(cliCmd)
 		taskTag, _ := valueObject.NewScheduledTaskTag("marketplace")
@@ -311,8 +390,12 @@ func (service *MarketplaceService) DeleteInstalledItem(
 		installedId, shouldUninstallServices,
 	)
 
-	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(service.persistentDbSvc)
-	marketplaceCmdRepo := marketplaceInfra.NewMarketplaceCmdRepo(service.persistentDbSvc)
+	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(
+		service.persistentDbSvc,
+	)
+	marketplaceCmdRepo := marketplaceInfra.NewMarketplaceCmdRepo(
+		service.persistentDbSvc,
+	)
 
 	err = useCase.DeleteMarketplaceInstalledItem(
 		marketplaceQueryRepo, marketplaceCmdRepo, deleteMarketplaceInstalledItem,

+ 3 - 1
src/presentation/ui/presenter/marketplace.go

@@ -79,7 +79,9 @@ func (presenter *MarketplacePresenter) marketplaceOverviewFactory(listType strin
 
 	installedItemsList := []entity.MarketplaceInstalledItem{}
 	if listType == "installed" {
-		responseOutput := presenter.marketplaceService.ReadInstalledItems()
+		responseOutput := presenter.marketplaceService.ReadInstalledItems(
+			map[string]interface{}{},
+		)
 		if responseOutput.Status != service.Success {
 			return overview, errors.New("FailedToReadInstalledItems")
 		}