Skip to content

Commit

Permalink
feat: Add an endpoint to get all content types
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 15, 2024
1 parent 07c1e4a commit 66033e5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/api/get-content-types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/Dobefu/csb/cmd/cs_sdk"
)

func GetContentTypes() (map[string]interface{}, error) {
data, err := cs_sdk.Request("content_types", "GET", nil)

if err != nil {
return nil, err
}

return data, nil
}
1 change: 1 addition & 0 deletions cmd/server/handle-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func HandleRoutes(mux *http.ServeMux, apiPath string) {

apiRoute(mux, apiPath, "/get-entry-by-url", "GET", v1.GetEntryByUrl)
apiRoute(mux, apiPath, "/get-entry-by-uid", "GET", v1.GetEntryByUid)
apiRoute(mux, apiPath, "/content-types", "GET", v1.GetContentTypes)
}

func apiRoute(
Expand Down
28 changes: 28 additions & 0 deletions cmd/server/routes/v1/get-content-types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v1

import (
"encoding/json"
"fmt"
"net/http"

"github.com/Dobefu/csb/cmd/api"
"github.com/Dobefu/csb/cmd/server/utils"
)

func GetContentTypes(w http.ResponseWriter, r *http.Request) {
output, err := api.GetContentTypes()

if err != nil {
utils.PrintError(w, err, false)
return
}

json, err := json.Marshal(output["content_types"])

if err != nil {
utils.PrintError(w, err, true)
return
}

fmt.Fprint(w, string(json))
}

0 comments on commit 66033e5

Please sign in to comment.