Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Enable hard delete by param #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/v1/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (r *Router) Routes(rg *gin.RouterGroup) {
srv.GET("", amw.RequiredScopes(readScopes("server")), r.serverGet)
srv.PUT("", amw.RequiredScopes(updateScopes("server")), r.serverUpdate)
srv.DELETE("", amw.RequiredScopes(deleteScopes("server")), r.serverDelete)
srv.DELETE("/:hard-delete", amw.RequiredScopes(deleteScopes("server")), r.serverDelete)

// /servers/:uuid/attributes
srvAttrs := srv.Group("/attributes")
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"reflect"
"strconv"

"github.com/gin-gonic/gin"
"github.com/volatiletech/null/v8"
Expand Down Expand Up @@ -126,7 +127,8 @@ func (r *Router) serverDelete(c *gin.Context) {
return
}

if _, err = dbSRV.Delete(c.Request.Context(), r.DB, false); err != nil {
hardDelete, _ := strconv.ParseBool(c.Param("hard-delete"))
if _, err = dbSRV.Delete(c.Request.Context(), r.DB, hardDelete); err != nil {
dbErrorResponse(c, err)
return
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/api/v1/server_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
type ClientInterface interface {
Create(context.Context, Server) (*uuid.UUID, *ServerResponse, error)
Delete(context.Context, Server) (*ServerResponse, error)
DeleteNow(context.Context, Server) (*ServerResponse, error)
Get(context.Context, uuid.UUID) (*Server, *ServerResponse, error)
List(context.Context, *ServerListParams) ([]Server, *ServerResponse, error)
Update(context.Context, uuid.UUID, Server) (*ServerResponse, error)
Expand Down Expand Up @@ -78,11 +79,16 @@ func (c *Client) Create(ctx context.Context, srv Server) (*uuid.UUID, *ServerRes
return &u, resp, nil
}

// Delete will attempt to delete a server in Hollow and return an error on failure
// Delete will attempt to soft delete a server in Hollow and return an error on failure
func (c *Client) Delete(ctx context.Context, srv Server) (*ServerResponse, error) {
return c.delete(ctx, fmt.Sprintf("%s/%s", serversEndpoint, srv.UUID))
}

// DeleteNow will attempt to hard delete a server in Hollow and return an error on failure
func (c *Client) DeleteNow(ctx context.Context, srv Server) (*ServerResponse, error) {
return c.delete(ctx, fmt.Sprintf("%s/%s/true", serversEndpoint, srv.UUID))
}

// Get will return a server by it's UUID
func (c *Client) Get(ctx context.Context, srvUUID uuid.UUID) (*Server, *ServerResponse, error) {
path := fmt.Sprintf("%s/%s", serversEndpoint, srvUUID)
Expand Down