-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ws): add CRUD operations to backend (#66)
* feat(ws): Notebooks 2.0 // Backend // List Workspaces API - II In this PR: - FUP for Notebooks 2.0 // Backend // List Workspaces API (#60) review - Create /api/v1/workspaces to return all workspaces - Review API endpoints as requested Signed-off-by: Eder Ignatowicz <ignatowicz@gmail.com> * Notebooks 2.0 // Backend // CRUD Workspaces API In this PR: - Created handlers and repositories for create, get and delete workspace - Improved the type of our json response Signed-off-by: Eder Ignatowicz <ignatowicz@gmail.com> * feat(ws): Notebooks 2.0 // Backend // List WorkspaceKinds This PR builds on top of: #61 and #65 In this PR: - Created handlers and repositories for get workspacekinds This PR closes #51 Signed-off-by: Eder Ignatowicz <ignatowicz@gmail.com> * mathew: fix linting Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com> --------- Signed-off-by: Eder Ignatowicz <ignatowicz@gmail.com> Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com> Co-authored-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
- Loading branch information
1 parent
f852c16
commit e46633b
Showing
17 changed files
with
1,255 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
run: | ||
timeout: 5m | ||
allow-parallel-runners: true | ||
|
||
issues: | ||
# don't skip warning about doc comments | ||
# don't exclude the default set of lint | ||
exclude-use-default: false | ||
# restore some of the defaults | ||
# (fill in the rest as needed) | ||
exclude-rules: | ||
- path: "api/*" | ||
linters: | ||
- lll | ||
- path: "internal/*" | ||
linters: | ||
- dupl | ||
- lll | ||
linters: | ||
disable-all: true | ||
enable: | ||
- dupl | ||
- errcheck | ||
- exportloopref | ||
- goconst | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- nakedret | ||
- prealloc | ||
- staticcheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
* Copyright 2024. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* / | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
|
||
"github.com/kubeflow/notebooks/workspaces/backend/internal/models" | ||
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories" | ||
) | ||
|
||
type WorkspaceKindsEnvelope Envelope[[]models.WorkspaceKindModel] | ||
type WorkspaceKindEnvelope Envelope[models.WorkspaceKindModel] | ||
|
||
func (a *App) GetWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||
name := ps.ByName("name") | ||
|
||
if name == "" { | ||
a.serverErrorResponse(w, r, fmt.Errorf("workspace kind name is missing")) | ||
return | ||
} | ||
|
||
workspaceKind, err := a.repositories.WorkspaceKind.GetWorkspaceKind(r.Context(), name) | ||
if err != nil { | ||
if errors.Is(err, repositories.ErrWorkspaceKindNotFound) { | ||
a.notFoundResponse(w, r) | ||
return | ||
} | ||
a.serverErrorResponse(w, r, err) | ||
return | ||
} | ||
|
||
workspaceKindEnvelope := WorkspaceKindEnvelope{ | ||
Data: workspaceKind, | ||
} | ||
|
||
err = a.WriteJSON(w, http.StatusOK, workspaceKindEnvelope, nil) | ||
if err != nil { | ||
a.serverErrorResponse(w, r, err) | ||
} | ||
} | ||
|
||
func (a *App) GetWorkspaceKindsHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
workspaceKinds, err := a.repositories.WorkspaceKind.GetWorkspaceKinds(r.Context()) | ||
if err != nil { | ||
a.serverErrorResponse(w, r, err) | ||
return | ||
} | ||
|
||
workspaceKindsEnvelope := WorkspaceKindsEnvelope{ | ||
Data: workspaceKinds, | ||
} | ||
|
||
err = a.WriteJSON(w, http.StatusOK, workspaceKindsEnvelope, nil) | ||
if err != nil { | ||
a.serverErrorResponse(w, r, err) | ||
} | ||
} |
Oops, something went wrong.