From 48d42a92c9c1c88b893cbe88853e141fd7118161 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Tue, 8 Jul 2025 20:16:46 +0200 Subject: [PATCH] Refactor API routes to include "_op" prefix for last workspace and file operations --- server/internal/app/routes.go | 10 +++++----- server/internal/handlers/file_handlers.go | 6 +++--- .../handlers/file_handlers_integration_test.go | 16 ++++++++-------- server/internal/handlers/workspace_handlers.go | 4 ++-- .../workspace_handlers_integration_test.go | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/server/internal/app/routes.go b/server/internal/app/routes.go index 94ac6e4..5ecc275 100644 --- a/server/internal/app/routes.go +++ b/server/internal/app/routes.go @@ -114,8 +114,8 @@ func setupRouter(o Options) *chi.Mux { r.Route("/workspaces", func(r chi.Router) { r.Get("/", handler.ListWorkspaces()) r.Post("/", handler.CreateWorkspace()) - r.Get("/last", handler.GetLastWorkspaceName()) - r.Put("/last", handler.UpdateLastWorkspaceName()) + r.Get("/_op/last", handler.GetLastWorkspaceName()) + r.Put("/_op/last", handler.UpdateLastWorkspaceName()) // Single workspace routes r.Route("/{workspaceName}", func(r chi.Router) { @@ -129,9 +129,9 @@ func setupRouter(o Options) *chi.Mux { // File routes r.Route("/files", func(r chi.Router) { r.Get("/", handler.ListFiles()) - r.Get("/last", handler.GetLastOpenedFile()) - r.Put("/last", handler.UpdateLastOpenedFile()) - r.Get("/lookup", handler.LookupFileByName()) + r.Get("/_op/last", handler.GetLastOpenedFile()) + r.Put("/_op/last", handler.UpdateLastOpenedFile()) + r.Get("/_op/lookup", handler.LookupFileByName()) r.Post("/*", handler.SaveFile()) r.Get("/*", handler.GetFileContent()) diff --git a/server/internal/handlers/file_handlers.go b/server/internal/handlers/file_handlers.go index 538742e..92b26e2 100644 --- a/server/internal/handlers/file_handlers.go +++ b/server/internal/handlers/file_handlers.go @@ -90,7 +90,7 @@ func (h *Handler) ListFiles() http.HandlerFunc { // @Success 200 {object} LookupResponse // @Failure 400 {object} ErrorResponse "Filename is required" // @Failure 404 {object} ErrorResponse "File not found" -// @Router /workspaces/{workspace_name}/files/lookup [get] +// @Router /workspaces/{workspace_name}/files/_op/lookup [get] func (h *Handler) LookupFileByName() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx, ok := context.GetRequestContext(w, r) @@ -382,7 +382,7 @@ func (h *Handler) DeleteFile() http.HandlerFunc { // @Success 200 {object} LastOpenedFileResponse // @Failure 400 {object} ErrorResponse "Invalid file path" // @Failure 500 {object} ErrorResponse "Failed to get last opened file" -// @Router /workspaces/{workspace_name}/files/last [get] +// @Router /workspaces/{workspace_name}/files/_op/last [get] func (h *Handler) GetLastOpenedFile() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx, ok := context.GetRequestContext(w, r) @@ -433,7 +433,7 @@ func (h *Handler) GetLastOpenedFile() http.HandlerFunc { // @Failure 400 {object} ErrorResponse "Invalid file path" // @Failure 404 {object} ErrorResponse "File not found" // @Failure 500 {object} ErrorResponse "Failed to update file" -// @Router /workspaces/{workspace_name}/files/last [put] +// @Router /workspaces/{workspace_name}/files/_op/last [put] func (h *Handler) UpdateLastOpenedFile() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx, ok := context.GetRequestContext(w, r) diff --git a/server/internal/handlers/file_handlers_integration_test.go b/server/internal/handlers/file_handlers_integration_test.go index 962b8f9..ea94e31 100644 --- a/server/internal/handlers/file_handlers_integration_test.go +++ b/server/internal/handlers/file_handlers_integration_test.go @@ -124,7 +124,7 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { require.Equal(t, http.StatusOK, rr.Code) // Search for the file - rr = h.makeRequest(t, http.MethodGet, baseURL+"/lookup?filename="+filename, nil, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodGet, baseURL+"/_op/lookup?filename="+filename, nil, h.RegularTestUser) require.Equal(t, http.StatusOK, rr.Code) var response struct { @@ -135,7 +135,7 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { assert.Len(t, response.Paths, 2) // Search for non-existent file - rr = h.makeRequest(t, http.MethodGet, baseURL+"/lookup?filename=nonexistent.md", nil, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodGet, baseURL+"/_op/lookup?filename=nonexistent.md", nil, h.RegularTestUser) assert.Equal(t, http.StatusNotFound, rr.Code) }) @@ -158,7 +158,7 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { t.Run("last opened file", func(t *testing.T) { // Initially should be empty - rr := h.makeRequest(t, http.MethodGet, baseURL+"/last", nil, h.RegularTestUser) + rr := h.makeRequest(t, http.MethodGet, baseURL+"/_op/last", nil, h.RegularTestUser) require.Equal(t, http.StatusOK, rr.Code) var response struct { @@ -174,11 +174,11 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { }{ FilePath: "docs/readme.md", } - rr = h.makeRequest(t, http.MethodPut, baseURL+"/last", updateReq, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodPut, baseURL+"/_op/last", updateReq, h.RegularTestUser) require.Equal(t, http.StatusNoContent, rr.Code) // Verify update - rr = h.makeRequest(t, http.MethodGet, baseURL+"/last", nil, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodGet, baseURL+"/_op/last", nil, h.RegularTestUser) require.Equal(t, http.StatusOK, rr.Code) err = json.NewDecoder(rr.Body).Decode(&response) @@ -187,7 +187,7 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { // Test invalid file path updateReq.FilePath = "nonexistent.md" - rr = h.makeRequest(t, http.MethodPut, baseURL+"/last", updateReq, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodPut, baseURL+"/_op/last", updateReq, h.RegularTestUser) assert.Equal(t, http.StatusNotFound, rr.Code) }) @@ -202,8 +202,8 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) { {"get file", http.MethodGet, baseURL + "/test.md", nil}, {"save file", http.MethodPost, baseURL + "/test.md", "content"}, {"delete file", http.MethodDelete, baseURL + "/test.md", nil}, - {"get last file", http.MethodGet, baseURL + "/last", nil}, - {"update last file", http.MethodPut, baseURL + "/last", struct{ FilePath string }{"test.md"}}, + {"get last file", http.MethodGet, baseURL + "/_op/last", nil}, + {"update last file", http.MethodPut, baseURL + "/_op/last", struct{ FilePath string }{"test.md"}}, } for _, tc := range tests { diff --git a/server/internal/handlers/workspace_handlers.go b/server/internal/handlers/workspace_handlers.go index 663c966..788b76f 100644 --- a/server/internal/handlers/workspace_handlers.go +++ b/server/internal/handlers/workspace_handlers.go @@ -407,7 +407,7 @@ func (h *Handler) DeleteWorkspace() http.HandlerFunc { // @Produce json // @Success 200 {object} LastWorkspaceNameResponse // @Failure 500 {object} ErrorResponse "Failed to get last workspace" -// @Router /workspaces/last [get] +// @Router /workspaces/_op/last [get] func (h *Handler) GetLastWorkspaceName() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx, ok := context.GetRequestContext(w, r) @@ -444,7 +444,7 @@ func (h *Handler) GetLastWorkspaceName() http.HandlerFunc { // @Success 204 "No Content - Last workspace updated successfully" // @Failure 400 {object} ErrorResponse "Invalid request body" // @Failure 500 {object} ErrorResponse "Failed to update last workspace" -// @Router /workspaces/last [put] +// @Router /workspaces/_op/last [put] func (h *Handler) UpdateLastWorkspaceName() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx, ok := context.GetRequestContext(w, r) diff --git a/server/internal/handlers/workspace_handlers_integration_test.go b/server/internal/handlers/workspace_handlers_integration_test.go index cb73efa..38cef62 100644 --- a/server/internal/handlers/workspace_handlers_integration_test.go +++ b/server/internal/handlers/workspace_handlers_integration_test.go @@ -211,7 +211,7 @@ func testWorkspaceHandlers(t *testing.T, dbConfig DatabaseConfig) { t.Run("last workspace", func(t *testing.T) { t.Run("get last workspace", func(t *testing.T) { - rr := h.makeRequest(t, http.MethodGet, "/api/v1/workspaces/last", nil, h.RegularTestUser) + rr := h.makeRequest(t, http.MethodGet, "/api/v1/workspaces/_op/last", nil, h.RegularTestUser) require.Equal(t, http.StatusOK, rr.Code) var response struct { @@ -229,11 +229,11 @@ func testWorkspaceHandlers(t *testing.T, dbConfig DatabaseConfig) { WorkspaceName: workspace.Name, } - rr := h.makeRequest(t, http.MethodPut, "/api/v1/workspaces/last", req, h.RegularTestUser) + rr := h.makeRequest(t, http.MethodPut, "/api/v1/workspaces/_op/last", req, h.RegularTestUser) require.Equal(t, http.StatusNoContent, rr.Code) // Verify the update - rr = h.makeRequest(t, http.MethodGet, "/api/v1/workspaces/last", nil, h.RegularTestUser) + rr = h.makeRequest(t, http.MethodGet, "/api/v1/workspaces/_op/last", nil, h.RegularTestUser) require.Equal(t, http.StatusOK, rr.Code) var response struct {