2022-01-22 23:58:10 -06:00
|
|
|
package coderd
|
|
|
|
|
|
|
|
|
|
import (
|
2022-03-07 11:40:54 -06:00
|
|
|
"net/http"
|
2022-01-22 23:58:10 -06:00
|
|
|
|
2024-08-28 13:24:28 -05:00
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
2024-07-18 12:28:36 -10:00
|
|
|
"github.com/coder/coder/v2/coderd/database/db2sdk"
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/coderd/httpapi"
|
|
|
|
|
"github.com/coder/coder/v2/coderd/httpmw"
|
|
|
|
|
"github.com/coder/coder/v2/codersdk"
|
2022-01-22 23:58:10 -06:00
|
|
|
)
|
|
|
|
|
|
2024-07-18 12:28:36 -10:00
|
|
|
// @Summary Get organizations
|
|
|
|
|
// @ID get-organizations
|
|
|
|
|
// @Security CoderSessionToken
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Tags Organizations
|
|
|
|
|
// @Success 200 {object} []codersdk.Organization
|
|
|
|
|
// @Router /organizations [get]
|
|
|
|
|
func (api *API) organizations(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
|
ctx := r.Context()
|
2024-08-28 13:24:28 -05:00
|
|
|
organizations, err := api.Database.GetOrganizations(ctx, database.GetOrganizationsParams{})
|
2024-07-18 12:28:36 -10:00
|
|
|
if httpapi.Is404Error(err) {
|
|
|
|
|
httpapi.ResourceNotFound(rw)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
|
|
|
|
Message: "Internal error fetching organizations.",
|
|
|
|
|
Detail: err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 16:07:53 -05:00
|
|
|
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.List(organizations, db2sdk.Organization))
|
2024-07-18 12:28:36 -10:00
|
|
|
}
|
|
|
|
|
|
2023-01-11 12:16:09 +01:00
|
|
|
// @Summary Get organization by ID
|
|
|
|
|
// @ID get-organization-by-id
|
|
|
|
|
// @Security CoderSessionToken
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Tags Organizations
|
|
|
|
|
// @Param organization path string true "Organization ID" format(uuid)
|
|
|
|
|
// @Success 200 {object} codersdk.Organization
|
|
|
|
|
// @Router /organizations/{organization} [get]
|
2023-03-21 09:10:22 -05:00
|
|
|
func (*API) organization(rw http.ResponseWriter, r *http.Request) {
|
2022-09-21 17:07:00 -05:00
|
|
|
ctx := r.Context()
|
2022-03-07 11:40:54 -06:00
|
|
|
organization := httpmw.OrganizationParam(r)
|
2022-05-17 13:43:19 -05:00
|
|
|
|
2024-07-25 16:07:53 -05:00
|
|
|
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.Organization(organization))
|
2022-01-22 23:58:10 -06:00
|
|
|
}
|