Coder Social home page Coder Social logo

Comments (7)

JakeCooper avatar JakeCooper commented on June 3, 2024

Definitely possible. If you wanna add it to the CLI, it’s just deleteProject(Id) in our GraphQL API

from cli.

TaroballzChen avatar TaroballzChen commented on June 3, 2024

@JakeCooper
I add delete.go document in cmd/ folder and the content as follow:

package cmd

import (
	"context"
	"fmt"

	"github.com/railwayapp/cli/entity"
	"github.com/railwayapp/cli/ui"
	"github.com/railwayapp/cli/uuid"
)

func(h *Handler)Delete(ctx context.Context, req *entity.CommandRequest)error{
	if len(req.Args) > 0 {
		// projectID provided as argument
		arg := req.Args[0]

		if (uuid.IsValidUUID(arg)) {
			project, err := h.ctrl.GetProject(ctx, arg)
			if (err != nil) {
				return err
			}

			return h.ctrl.DeleteProject(ctx, project.Id)
		}

		project, err := h.ctrl.GetProjectByName(ctx, arg)
		if (err != nil) {
			return err
		}

		return h.ctrl.DeleteProject(ctx, project.Id)
	}

	h.Unlink(ctx, req)

	isLoggedIn, err := h.ctrl.IsLoggedIn(ctx)
	if err != nil {
		return err
	}

	if isLoggedIn {
		return h.deleteFromAccount(ctx, req)
	} else {
		return h.deleteFromID(ctx, req)
	}

}

func (h *Handler) deleteFromAccount(ctx context.Context, req *entity.CommandRequest) error {
	projects, err := h.ctrl.GetProjects(ctx)
	if err != nil {
		return err
	}

	if len(projects) == 0 {
		fmt.Printf("No Projects could be deleted.")
		return nil
	}

	project, err := ui.PromptProjects(projects)
	if err != nil {
		return err
	}

	return h.ctrl.DeleteProject(ctx, project.Id)
}

func (h *Handler) deleteFromID(ctx context.Context, req *entity.CommandRequest) error {
	projectID, err := ui.PromptText("Enter your project id")
	if err != nil {
		return err
	}

	project, err := h.ctrl.GetProject(ctx, projectID)
	if (err != nil) {
		return err
	}

	return h.ctrl.DeleteProject(ctx, project.Id)
}

append DeleteProject function in controller/project.go

func (c *Controller) DeleteProject(ctx context.Context, projectID string) error {
	return c.gtwy.DeleteProject(ctx, projectID)
}

and append addRootCmd execution about deleting project operation in init function which in project's main.go as follow

	addRootCmd(&cobra.Command{
		Use:   "delete",
		Short: "Delete Project, may specify projectId as an argument",
		RunE:  contextualize(handler.Delete, handler.Panic),
	})

the result as follow
image

the delete operation seems to unsuccessful, any idea?

from cli.

ndneighbor avatar ndneighbor commented on June 3, 2024

Hey! @TaroballzChen I will be reviewing this once I wake up and working through on why it might not be working. The good news is that the CLI is using all of the same gQL mutations as our front-end so I can check that out and try it against your changes.

from cli.

TaroballzChen avatar TaroballzChen commented on June 3, 2024

Hi! @ndneighbor I'm grateful to hear that. If any good news during checking, plz guide me how to do that!

from cli.

ndneighbor avatar ndneighbor commented on June 3, 2024

Alright, got some news for you- I looked into deleteProject in the controller of the project and it matches the front-end call. I am going to review with the team to see if there is something else that might have caused the 400.

(I also noticed that if you try to delete a project with an id that doesn't exist it errors out too, so I want to clean up that flow for you as well.)

Thank you for your patience.

from cli.

ndneighbor avatar ndneighbor commented on June 3, 2024

Alright, this feature is in the latest CLI version @TaroballzChen, try it out and let me know what you think!

from cli.

TaroballzChen avatar TaroballzChen commented on June 3, 2024

I have try it, and the result looks good for me. Thanks for your help

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.