label stubs

This commit is contained in:
Hayden 2022-09-01 15:11:14 -08:00
parent 26ecb5a9d4
commit f956ec8eb2
8 changed files with 567 additions and 17 deletions

View file

@ -261,6 +261,170 @@ const docTemplate = `{
}
}
},
"/v1/labels": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Get All Labels",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/server.Results"
},
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
}
]
}
}
}
},
"post": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Create a new label",
"parameters": [
{
"description": "Label Data",
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/types.LabelCreate"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelSummary"
}
}
}
}
},
"/v1/labels/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Gets a label and fields",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
},
"put": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "updates a label",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
},
"delete": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "deletes a label",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": ""
}
}
}
},
"/v1/locations": {
"get": {
"security": [
@ -1108,6 +1272,15 @@ const docTemplate = `{
}
}
},
"types.LabelCreate": {
"type": "object"
},
"types.LabelOut": {
"type": "object"
},
"types.LabelSummary": {
"type": "object"
},
"types.LocationCreate": {
"type": "object",
"properties": {

View file

@ -253,6 +253,170 @@
}
}
},
"/v1/labels": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Get All Labels",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/server.Results"
},
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
}
]
}
}
}
},
"post": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Create a new label",
"parameters": [
{
"description": "Label Data",
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/types.LabelCreate"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelSummary"
}
}
}
}
},
"/v1/labels/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "Gets a label and fields",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
},
"put": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "updates a label",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.LabelOut"
}
}
}
},
"delete": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Labels"
],
"summary": "deletes a label",
"parameters": [
{
"type": "string",
"description": "Label ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": ""
}
}
}
},
"/v1/locations": {
"get": {
"security": [
@ -1100,6 +1264,15 @@
}
}
},
"types.LabelCreate": {
"type": "object"
},
"types.LabelOut": {
"type": "object"
},
"types.LabelSummary": {
"type": "object"
},
"types.LocationCreate": {
"type": "object",
"properties": {

View file

@ -353,6 +353,12 @@ definitions:
updatedAt:
type: string
type: object
types.LabelCreate:
type: object
types.LabelOut:
type: object
types.LabelSummary:
type: object
types.LocationCreate:
properties:
description:
@ -583,6 +589,103 @@ paths:
summary: Update a User
tags:
- 'Admin: Users'
/v1/labels:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/server.Results'
- properties:
items:
items:
$ref: '#/definitions/types.LabelOut'
type: array
type: object
security:
- Bearer: []
summary: Get All Labels
tags:
- Labels
post:
parameters:
- description: Label Data
in: body
name: payload
required: true
schema:
$ref: '#/definitions/types.LabelCreate'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/types.LabelSummary'
security:
- Bearer: []
summary: Create a new label
tags:
- Labels
/v1/labels/{id}:
delete:
parameters:
- description: Label ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"204":
description: ""
security:
- Bearer: []
summary: deletes a label
tags:
- Labels
get:
parameters:
- description: Label ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/types.LabelOut'
security:
- Bearer: []
summary: Gets a label and fields
tags:
- Labels
put:
parameters:
- description: Label ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/types.LabelOut'
security:
- Bearer: []
summary: updates a label
tags:
- Labels
/v1/locations:
get:
produces:

View file

@ -55,6 +55,12 @@ func (a *app) newRouter(repos *repo.AllRepos) *chi.Mux {
r.Get(v1Base("/locations/{id}"), v1Handlers.HandleLocationGet())
r.Put(v1Base("/locations/{id}"), v1Handlers.HandleLocationUpdate())
r.Delete(v1Base("/locations/{id}"), v1Handlers.HandleLocationDelete())
r.Get(v1Base("/labels"), v1Handlers.HandleLabelsGetAll())
r.Post(v1Base("/labels"), v1Handlers.HandleLabelsCreate())
r.Get(v1Base("/labels/{id}"), v1Handlers.HandleLabelGet())
r.Put(v1Base("/labels/{id}"), v1Handlers.HandleLabelUpdate())
r.Delete(v1Base("/labels/{id}"), v1Handlers.HandleLabelDelete())
})
r.Group(func(r chi.Router) {

View file

@ -0,0 +1,36 @@
package v1
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/internal/services"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/content/backend/pkgs/logger"
"github.com/hay-kot/content/backend/pkgs/server"
)
/*
This is where we put partial snippets/functions for actions that are commonly
used within the controller class. This _hopefully_ helps with code duplication
and makes it a little more consistent when error handling and logging.
*/
// partialParseIdAndUser parses the ID from the requests URL and pulls the user
// from the context. If either of these fail, it will return an error. When an error
// occurs it will also write the error to the response. As such, if an error is returned
// from this function you can return immediately without writing to the response.
func (ctrl *V1Controller) partialParseIdAndUser(w http.ResponseWriter, r *http.Request) (uuid.UUID, *types.UserOut, error) {
uid, err := uuid.Parse(chi.URLParam(r, "id"))
if err != nil {
ctrl.log.Debug(err.Error(), logger.Props{
"details": "failed to convert id to valid UUID",
})
server.RespondError(w, http.StatusBadRequest, err)
return uuid.Nil, nil, err
}
user := services.UseUserCtx(r.Context())
return uid, user, nil
}

View file

@ -0,0 +1,69 @@
package v1
import (
"net/http"
)
// HandleLabelsGetAll godoc
// @Summary Get All Labels
// @Tags Labels
// @Produce json
// @Success 200 {object} server.Results{items=[]types.LabelOut}
// @Router /v1/labels [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleLabelsGetAll() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
// HandleLabelsCreate godoc
// @Summary Create a new label
// @Tags Labels
// @Produce json
// @Param payload body types.LabelCreate true "Label Data"
// @Success 200 {object} types.LabelSummary
// @Router /v1/labels [POST]
// @Security Bearer
func (ctrl *V1Controller) HandleLabelsCreate() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
// HandleLabelDelete godocs
// @Summary deletes a label
// @Tags Labels
// @Produce json
// @Param id path string true "Label ID"
// @Success 204
// @Router /v1/labels/{id} [DELETE]
// @Security Bearer
func (ctrl *V1Controller) HandleLabelDelete() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
// HandleLabelGet godocs
// @Summary Gets a label and fields
// @Tags Labels
// @Produce json
// @Param id path string true "Label ID"
// @Success 200 {object} types.LabelOut
// @Router /v1/labels/{id} [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleLabelGet() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
// HandleLabelUpdate godocs
// @Summary updates a label
// @Tags Labels
// @Produce json
// @Param id path string true "Label ID"
// @Success 200 {object} types.LabelOut
// @Router /v1/labels/{id} [PUT]
// @Security Bearer
func (ctrl *V1Controller) HandleLabelUpdate() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}

View file

@ -3,11 +3,8 @@ package v1
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/internal/services"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/content/backend/pkgs/logger"
"github.com/hay-kot/content/backend/pkgs/server"
)
@ -61,20 +58,6 @@ func (ctrl *V1Controller) HandleLocationCreate() http.HandlerFunc {
}
}
func (ctrl *V1Controller) partialParseIdAndUser(w http.ResponseWriter, r *http.Request) (uuid.UUID, *types.UserOut, error) {
uid, err := uuid.Parse(chi.URLParam(r, "id"))
if err != nil {
ctrl.log.Debug(err.Error(), logger.Props{
"details": "failed to convert id to valid UUID",
})
server.RespondError(w, http.StatusBadRequest, err)
return uuid.Nil, nil, err
}
user := services.UseUserCtx(r.Context())
return uid, user, nil
}
// HandleLocationDelete godocs
// @Summary deletes a location
// @Tags Locations

View file

@ -0,0 +1,7 @@
package types
type LabelOut struct{}
type LabelCreate struct{}
type LabelSummary struct{}