Skip to content

Commit

Permalink
wip rework
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix committed Dec 12, 2023
1 parent 0cca8f1 commit a0f069a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func newEchoServer(log *otelzap.Logger, pool *pgxpool.Pool, gw2ApiClient *gw2.Ap
app.DELETE("/api-v2/dev/application/:id", web.DeleteDevApplicationEndpoint(), authMw)
app.GET("/api-v2/dev/application/:id/user", web.DevApplicationUsersEndpoint(), authMw)
app.PUT("/api-v2/dev/application/:id/client", web.CreateDevApplicationClientEndpoint(), authMw)
app.DELETE("/api-v2/dev/application/:app_id/client/:client_id", web.DeleteDevApplicationClientEndpoint(), authMw)
app.PATCH("/api-v2/dev/application/:app_id/client/:client_id/user/:user_id", web.UpdateDevApplicationClientUserEndpoint(), authMw)

return app
Expand Down
4 changes: 3 additions & 1 deletion web/dev_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ VALUES
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, map[string]string{})
return c.JSON(http.StatusOK, map[string]any{
"id": applicationId,
})
})
}

Expand Down
46 changes: 46 additions & 0 deletions web/dev_application_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,52 @@ AND id = $2
})
}

func DeleteDevApplicationClientEndpoint() echo.HandlerFunc {
return wrapAuthenticatedHandlerFunc(func(c echo.Context, rctx RequestContext, session service.Session) error {
var applicationId, clientId uuid.UUID
if values, err := util.EchoAllParams(c, uuid.FromString, "app_id", "client_id"); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
} else {
applicationId, clientId = values[0], values[1]
}

ctx := c.Request().Context()

var deleted bool
err := rctx.ExecuteTx(ctx, pgx.TxOptions{}, func(tx pgx.Tx) error {
const sql = `
DELETE FROM application_clients
WHERE id = (
SELECT app_clients.id
FROM application_clients app_clients
INNER JOIN applications apps
ON app_clients.application_id = apps.id
WHERE apps.account_id = $1
AND apps.id = $2
AND app_clients.id = $3
)
`
tag, err := tx.Exec(ctx, sql, session.AccountId, applicationId, clientId)
if err != nil {
return err
}

deleted = tag.RowsAffected() > 0
return nil
})

if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

if !deleted {
return echo.NewHTTPError(http.StatusNotFound, errors.New("the client does not exist"))
}

return c.JSON(http.StatusOK, map[string]string{})
})
}

func UpdateDevApplicationClientUserEndpoint() echo.HandlerFunc {
return wrapAuthenticatedHandlerFunc(func(c echo.Context, rctx RequestContext, session service.Session) error {
var applicationId, clientId, userId uuid.UUID
Expand Down

0 comments on commit a0f069a

Please sign in to comment.