web

package
v0.0.0-...-25ffe3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaTypeMarkdown = "text/markdown"
)

Variables

View Source
var (
	ErrInternal = ApiError{
		Status: http.StatusInternalServerError,
		Code:   "internal",
	}

	ErrUnauthorized = ApiError{
		Status: http.StatusUnauthorized,
		Code:   "unauthorized",
	}

	ErrResourceNotFound = ApiError{
		Status: http.StatusNotFound,
		Code:   "resource.notfound",
	}

	ErrContraintViolation = ApiError{
		Status: http.StatusConflict,
		Code:   "validation.constraint.violation",
	}

	ErrRecipeInvalid = ApiError{
		Status: http.StatusUnprocessableEntity,
		Code:   "validation.recipe.invalid",
	}

	ErrMultipartUnexpectedPart = ApiError{
		Status: http.StatusUnprocessableEntity,
		Code:   "validation.multipart.unexpectedpart",
	}
)

Functions

func NewRouter

func NewRouter(
	transactions *service.TransactionService,
	oidcHandler *oidc.Handler,
	oidcSession *oidc.Session,
	sessions *SessionController,
	assets *AssetController,
	recipes *RecipeController,
) http.Handler

func NewServer

func NewServer(handler http.Handler) *http.Server

Types

type ApiError

type ApiError struct {
	Status   int    `json:"status"`
	Code     string `json:"code"`
	Internal error  `json:"-"`

} // @name ApiError

func (ApiError) Error

func (e ApiError) Error() string

func (ApiError) WithInternal

func (e ApiError) WithInternal(err error) ApiError

type AssetController

type AssetController struct {
	// contains filtered or unexported fields
}

func NewAssetController

func NewAssetController(assets *service.AssetService) *AssetController

func (*AssetController) Download

func (c *AssetController) Download(ctx echo.Context) error

@summary Download an asset @id downloadAsset @tags assets @router /assets/{assetId} [get] @produce application/octet-stream @param assetId path string true "Asset ID" @param thumbnail query string false "Thumbnail version of an image" @success 200 {blob} blob @failure 400 {object} ApiError @failure 404 {object} ApiError

type AssetMetadataDto

type AssetMetadataDto struct {
	ID   xid.ID `json:"id"`
	Href string `json:"href"`

} // @name AssetMetadata

type CreateRecipeResponse

type CreateRecipeResponse struct {
	ID xid.ID `json:"id"`

} // @name CreateRecipeResponse

type DeleteRecipeRequest

type DeleteRecipeRequest struct {
	ID xid.ID `param:"recipeId"`
}

type DownloadAssetRequest

type DownloadAssetRequest struct {
	ID        xid.ID                `param:"assetId"`
	Thumbnail service.ThumbnailSize `query:"thumbnail"`
}

type ReadRecipeRequest

type ReadRecipeRequest struct {
	ID xid.ID `json:"-" param:"recipeId"`
}

type RecipeController

type RecipeController struct {
	// contains filtered or unexported fields
}

func NewRecipeController

func NewRecipeController(recipes *service.RecipeService) *RecipeController

func (*RecipeController) Create

func (c *RecipeController) Create(ctx echo.Context) error

@summary Create a new recipe @id createRecipe @tags recipes @router /recipes [post] @accept text/markdown @produce application/json @param content body string true "Recipe content" @success 201 {object} CreateRecipeResponse @failure 400 {object} ApiError @failure 422 {object} ApiError

func (*RecipeController) Delete

func (c *RecipeController) Delete(ctx echo.Context) error

@summary Delete a recipe @id deleteRecipe @tags recipes @router /recipes/{recipeId} [delete] @param recipeId path string true "Recipe ID" @success 204 @failure 400 {object} ApiError @failure 404 {object} ApiError

func (*RecipeController) List

func (c *RecipeController) List(ctx echo.Context) error

@summary List recipes @id listRecipes @tags recipes @router /recipes [get] @produce application/json @success 200 {array} RecipeMetadataDto

func (*RecipeController) ListImages

func (c *RecipeController) ListImages(ctx echo.Context) error

@summary List recipe images @id listRecipeImages @tags recipes assets @router /recipes/{recipeId}/images [get] @param recipeId path string true "Recipe ID" @produce application/json @success 200 {array} AssetMetadataDto

func (*RecipeController) Read

func (c *RecipeController) Read(ctx echo.Context) error

@summary Read a recipe @id readRecipe @tags recipes @router /recipes/{recipeId} [get] @produce text/markdown @param recipeId path string true "Recipe ID" @success 200 {string} string @failure 400 {object} ApiError @failure 404 {object} ApiError

func (*RecipeController) Update

func (c *RecipeController) Update(ctx echo.Context) error

@summary Update a recipe @id updateRecipe @tags recipes @router /recipes/{recipeId} [put] @accept text/markdown @param recipeId path string true "Recipe ID" @param content body string true "Recipe content" @success 204 @failure 400 {object} ApiError @failure 404 {object} ApiError @failure 409 {object} ApiError @failure 422 {object} ApiError

func (*RecipeController) UploadImage

func (c *RecipeController) UploadImage(ctx echo.Context) error

@summary Upload a new recipe image @id uploadRecipeImage @tags recipes assets @router /recipes/{recipeId}/images [post] @accept multipart/form-data @produce application/json @param recipeId path string true "Recipe ID" @param image formData file true "Image" @success 201 {object} AssetMetadataDto @failure 400 {object} ApiError @failure 404 {object} ApiError @failure 422 {object} ApiError

type RecipeMetadataDto

type RecipeMetadataDto struct {
	ID        xid.ID `json:"id"`
	Title     string `json:"title"`
	ImageHref string `json:"imageHref"`

} // @name RecipeMetadata

type SessionController

type SessionController struct {
	// contains filtered or unexported fields
}

func NewSessionController

func NewSessionController(session *oidc.Session) *SessionController

func (*SessionController) UserInfo

func (c *SessionController) UserInfo(ctx echo.Context) error

@summary Get user info @id userInfo @tags session @router /session/info [get] @produce application/json @success 200 {object} UserInfoResponse @success 401 {object} ApiError

type UpdateRecipeRequest

type UpdateRecipeRequest struct {
	ID xid.ID `json:"-" param:"recipeId"`
}

type UploadRecipeImageRequest

type UploadRecipeImageRequest struct {
	ID xid.ID `json:"-" param:"recipeId"`
}

type UserInfoResponse

type UserInfoResponse struct {
	Subject    string `json:"subject"`
	Email      string `json:"email"`
	Username   string `json:"username"`
	Name       string `json:"name"`
	PictureUrl string `json:"pictureUrl"`

} // @name UserInfo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL