From e959faf9da033dfc2f3659ee8a620ccb175330b1 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 6 Feb 2024 17:00:26 +0100 Subject: [PATCH] enhancement(graph): refrain from registering routes via the Router interface After some back an forth we agreed on keeping the routes defined in a central place for now. (cherry picked from commit e7985f42b6edf92f0a4344d4f3f8c5e28c23e276) --- .../graph/pkg/service/v0/api_drives_drive_item.go | 8 -------- services/graph/pkg/service/v0/graph.go | 12 ------------ services/graph/pkg/service/v0/service.go | 10 ++-------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/services/graph/pkg/service/v0/api_drives_drive_item.go b/services/graph/pkg/service/v0/api_drives_drive_item.go index 6f077153af..ac83f58f87 100644 --- a/services/graph/pkg/service/v0/api_drives_drive_item.go +++ b/services/graph/pkg/service/v0/api_drives_drive_item.go @@ -182,14 +182,6 @@ func NewDrivesDriveItemApi(drivesDriveItemService DrivesDriveItemProvider, logge }, nil } -// Routes returns the routes that should be registered for this api -func (api DrivesDriveItemApi) Routes() []Route { - return []Route{ - {http.MethodPost, "/v1beta1/drives/{driveID}/items/{itemID}/children", api.CreateDriveItem}, - {http.MethodDelete, "/v1beta1/drives/{driveID}/items/{itemID}", api.DeleteDriveItem}, - } -} - func (api DrivesDriveItemApi) DeleteDriveItem(w http.ResponseWriter, r *http.Request) { ctx := r.Context() _, itemID, err := GetDriveAndItemIDParam(r, &api.logger) diff --git a/services/graph/pkg/service/v0/graph.go b/services/graph/pkg/service/v0/graph.go index 3767e6dc00..33893e18e2 100644 --- a/services/graph/pkg/service/v0/graph.go +++ b/services/graph/pkg/service/v0/graph.go @@ -59,18 +59,6 @@ type RoleService interface { RemoveRoleFromUser(ctx context.Context, in *settingssvc.RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error) } -// A Route defines the parameters for an api endpoint -type Route struct { - Method string - Pattern string - HandlerFunc http.HandlerFunc -} - -// Router defines the required methods for retrieving api routes -type Router interface { - Routes() []Route -} - // Graph defines implements the business logic for Service. type Graph struct { config *config.Config diff --git a/services/graph/pkg/service/v0/service.go b/services/graph/pkg/service/v0/service.go index 963584d861..cdca38915c 100644 --- a/services/graph/pkg/service/v0/service.go +++ b/services/graph/pkg/service/v0/service.go @@ -217,14 +217,6 @@ func NewService(opts ...Option) (Graph, error) { m.Route(options.Config.HTTP.Root, func(r chi.Router) { r.Use(middleware.StripSlashes) - for _, router := range []Router{ - drivesDriveItemApi, - } { - for _, route := range router.Routes() { - r.Method(route.Method, route.Pattern, route.HandlerFunc) - } - } - r.Route("/v1beta1", func(r chi.Router) { r.Route("/me", func(r chi.Router) { r.Get("/drives", svc.GetDrives(APIVersion_1_Beta_1)) @@ -236,6 +228,8 @@ func NewService(opts ...Option) (Graph, error) { r.Route("/drives", func(r chi.Router) { r.Get("/", svc.GetAllDrives(APIVersion_1_Beta_1)) r.Route("/{driveID}/items/{itemID}", func(r chi.Router) { + r.Delete("/", drivesDriveItemApi.DeleteDriveItem) + r.Post("/children", drivesDriveItemApi.CreateDriveItem) r.Post("/invite", svc.Invite) r.Route("/permissions", func(r chi.Router) { r.Get("/", svc.ListPermissions)