Skip to content

Commit

Permalink
Implement GET /v3/space/spaceguid
Browse files Browse the repository at this point in the history
Korifi issue: #2303
  • Loading branch information
danail-branekov committed Mar 17, 2023
1 parent 04796be commit 06f6fe8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/handlers/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ func (h *Space) delete(r *http.Request) (*routing.Response, error) {
return routing.NewResponse(http.StatusAccepted).WithHeader("Location", presenter.JobURLForRedirects(spaceGUID, presenter.SpaceDeleteOperation, h.apiBaseURL)), nil
}

func (h *Space) get(r *http.Request) (*routing.Response, error) {
authInfo, _ := authorization.InfoFromContext(r.Context())
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.space.get")

spaceGUID := routing.URLParam(r, "guid")

space, err := h.spaceRepo.GetSpace(r.Context(), authInfo, spaceGUID)
if err != nil {
return nil, apierrors.LogAndReturn(logger, apierrors.ForbiddenAsNotFound(err), "Failed to fetch space from Kubernetes", "GUID", spaceGUID)
}

spaceResult := presenter.ForSpace(space, h.apiBaseURL)
return routing.NewResponse(http.StatusOK).WithBody(spaceResult), nil
}

func (h *Space) UnauthenticatedRoutes() []routing.Route {
return nil
}
Expand All @@ -145,6 +160,7 @@ func (h *Space) AuthenticatedRoutes() []routing.Route {
{Method: "POST", Pattern: SpacesPath, Handler: h.create},
{Method: "PATCH", Pattern: SpacePath, Handler: h.update},
{Method: "DELETE", Pattern: SpacePath, Handler: h.delete},
{Method: "GET", Pattern: SpacePath, Handler: h.get},
}
}

Expand Down

0 comments on commit 06f6fe8

Please sign in to comment.