api

package
v0.1.0-a6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCategory

func AddCategory(w http.ResponseWriter, r *http.Request)

AddCategory handler @Summary AddCategory @Description Add a category @Description The new ressource Location is returned in the header @Description [requires admin] @Tags Categories @Accept json

@Router /categories [post] @Param category body model.Category true "Category body" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func AddSoftware

func AddSoftware(w http.ResponseWriter, r *http.Request)

AddSoftware handler @Summary AddSoftware @Description Add a software @Description The new ressource Location is returned in the header @Tags Softwares @Accept json

@Router /softwares [post] @Param software body model.SoftwarePatch true "Software patch body" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 500

func AddSubscription

func AddSubscription(w http.ResponseWriter, r *http.Request)

AddSubscription handler @Summary AddSubscription @Description Add a subscription @Tags Subscriptions @Accept json

@Router /api/v1/users/{userID}/subscriptions/{softwareID} [put] @Param userID path int true "User ID" @Param softwareID path int true "Software ID" @Param subscription body model.SubscriptionPatch true "Subscription patch body" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func AddSubscriptionTag

func AddSubscriptionTag(w http.ResponseWriter, r *http.Request)

AddSubscriptionTag handler @Summary AddSubscriptionTag @Description Add a subscription tag @Tags Subscriptions @Accept json

@Router /api/v1/users/{userID}/subscriptions/{softwareID}/tags/{tagID} [put] @Param userID path int true "User ID" @Param softwareID path int true "Software ID" @Param tagID path int true "Software ID" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func AddUser

func AddUser(w http.ResponseWriter, r *http.Request)

AddUser handler @Summary AddUser @Description Add a user @Description The new ressource Location is returned in the header @Description [requires admin] @Tags Users @Accept json

@Router /users [post] @Param user body model.UserPatch true "User patch body" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func AddUserTag

func AddUserTag(w http.ResponseWriter, r *http.Request)

AddUserTag handler @Summary AddUserTag @Description Add a user tag @Description The new ressource Location is returned in the header @Tags Tags @Accept json

@Router /users/{userID}/tags [post] @Param userID path int true "User ID" @Param tag body model.TagPatch true "Tag patch body" @Success 201 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func Auth

func Auth(w http.ResponseWriter, r *http.Request)

Auth handler @Summary Auth @Description Auth with user auth body @Tags Auth @Accept json @Produce json

@Router /auth [post] @Param auth body model.Auth true "Auth body" @Success 200 {object} model.Token @Failure 401 {object} model.AppError @Failure 500

func CategoryCtx

func CategoryCtx(next http.Handler) http.Handler

CategoryCtx middleware

func CategoryFromCtx

func CategoryFromCtx(ctx context.Context) *model.Category

CategoryFromCtx get data from context

func ClaimsFromCtx

func ClaimsFromCtx(ctx context.Context) jwt.MapClaims

ClaimsFromCtx get data from context

func ClaimsUserID

func ClaimsUserID(claims jwt.MapClaims) uint64

ClaimsUserID extract the user id from the jwt token

func CrawlSoftwares

func CrawlSoftwares(w http.ResponseWriter, r *http.Request)

CrawlSoftwares handler @Summary CrawlSoftwares @Description Crawl softwares manually @Tags System @Produce json

@Router /system/crawl [get] @Success 202 @Failure 500

func DeleteCategory

func DeleteCategory(w http.ResponseWriter, r *http.Request)

DeleteCategory handler @Summary DeleteCategory @Description Delete a category @Description [requires admin] @Tags Categories

@Router /categories/{categoryName} [delete] @Param categoryName path string true "Category Name" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func DeleteSoftware

func DeleteSoftware(w http.ResponseWriter, r *http.Request)

DeleteSoftware handler @Summary DeleteSoftware @Description Delete a Software @Description [requires admin or ownership permissions] @Tags Softwares

@Router /softwares/{softwareID} [delete] @Param softwareID path int true "Software ID" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func DeleteSubscription

func DeleteSubscription(w http.ResponseWriter, r *http.Request)

DeleteSubscription handler @Summary DeleteSubscription @Description Delete a Subscription @Description [requires admin or ownership permissions] @Tags Subscriptions

@Router /api/v1/users/{userID}/subscriptions/{softwareID} [delete] @Param userID path int true "User ID" @Param softwareID path int true "Software ID" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func DeleteSubscriptionTag

func DeleteSubscriptionTag(w http.ResponseWriter, r *http.Request)

DeleteSubscriptionTag handler @Summary DeleteSubscriptionTag @Description Delete a subscription tag @Tags Subscriptions @Accept json

@Router /api/v1/users/{userID}/subscriptions/{softwareID}/tags/{tagID} [delete] @Param userID path int true "User ID" @Param softwareID path int true "Software ID" @Param tagID path int true "Software ID" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func DeleteUser

func DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser handler @Summary DeleteUser @Description Delete a user @Description [requires admin or ownership permissions] @Tags Users

@Router /users/{userID} [delete] @Param userID path int true "User ID" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func DeleteUserTag

func DeleteUserTag(w http.ResponseWriter, r *http.Request)

DeleteUserTag handler @Summary DeleteUserTag @Description Delete a tag @Description [requires admin or ownership permissions] @Tags Tags

@Router /users/{userID}/tags/{tagID} [delete] @Param userID path int true "User ID" @Param tagID path int true "Tag ID" @Success 204 @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func GetCategories

func GetCategories(w http.ResponseWriter, r *http.Request)

GetCategories handler @Summary GetCategories @Description Get all categories @Tags Categories @Produce json

@Router /categories [get] @Success 200 {array} model.Category @Failure 401 {object} model.AppError @Failure 500

func GetInfo

func GetInfo(w http.ResponseWriter, r *http.Request)

GetInfo handler @Summary GetInfo @Description Get application informations @Tags System @Produce json

@Router /info [get] @Success 200 {object} model.Info @Failure 500

func GetSoftware

func GetSoftware(w http.ResponseWriter, r *http.Request)

GetSoftware handler @Summary GetSoftware @Description Get a software @Tags Softwares @Produce json

@Router /softwares/{softwareID} [get] @Param softwareID path int true "Software ID" @Success 200 {object} model.Software @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func GetSoftwares

func GetSoftwares(w http.ResponseWriter, r *http.Request)

GetSoftwares handler @Summary GetSoftwares @Description Get all softwares @Tags Softwares @Produce json

@Router /softwares [get] @Success 200 {array} model.Software @Failure 401 {object} model.AppError @Failure 500

func GetSubscriptions

func GetSubscriptions(w http.ResponseWriter, r *http.Request)

GetSubscriptions handler @Summary GetSubscriptions @Description Get all user subscriptions @Description [requires admin or ownership permissions] @Tags Subscriptions @Produce json

@Router /users/{userID}/subscriptions [get] @Param userID path int true "User ID" @Success 200 {array} model.Subscription @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func GetUser

func GetUser(w http.ResponseWriter, r *http.Request)

GetUser handler @Summary GetUser @Description Get a user @Description [requires admin or ownership permissions] @Tags Users @Produce json

@Router /users/{userID} [get] @Param userID path int true "User ID" @Success 200 {object} model.User @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func GetUserTags

func GetUserTags(w http.ResponseWriter, r *http.Request)

GetUserTags handler @Summary GetUserTags @Description Get all user tags @Description [requires admin or ownership permissions] @Tags Tags @Produce json

@Router /users/{userID}/tags [get] @Param userID path int true "User ID" @Success 200 {array} model.Tag @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func GetUsers

func GetUsers(w http.ResponseWriter, r *http.Request)

GetUsers handler @Summary GetUsers @Description Get all users @Description [requires admin] @Tags Users @Produce json

@Router /users [get] @Success 200 {array} model.User @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func HasError

func HasError(w http.ResponseWriter, err *model.AppError) bool

HasError check wether an error occured and write it to response writer

func Init

func Init(a *app.App, root chi.Router)

Init a new API and build api routes

func IsAdmin

func IsAdmin(claims jwt.MapClaims) bool

IsAdmin check wether jwt token has admin role

func JSON

func JSON(w http.ResponseWriter, data []byte)

JSON write data to reponse writer and set the right content type

func Pagination

func Pagination(next http.Handler) http.Handler

Pagination middleware allow to insert pagination as query parameters

func PatchSoftware

func PatchSoftware(w http.ResponseWriter, r *http.Request)

PatchSoftware handler @Summary PatchSoftware @Description Patch a Software @Description [requires admin or ownership permissions] @Tags Softwares @Accept json @Produce json

@Router /softwares/{softwareID} [patch] @Param softwareID path int true "Software ID" @Param software body model.SoftwarePatch true "Software patch body" @Success 200 {object} model.Software @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func PatchSubscription

func PatchSubscription(w http.ResponseWriter, r *http.Request)

PatchSubscription handler @Summary PatchSubscription @Description Patch a Subscription @Description [requires admin or ownership permissions] @Tags Subscriptions @Accept json @Produce json

@Router /api/v1/users/{userID}/subscriptions/{softwareID} [patch] @Param userID path int true "User ID" @Param softwareID path int true "Software ID" @Param subscription body model.SubscriptionPatch true "Subscription patch body" @Success 200 {object} model.Subscription @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func PatchUser

func PatchUser(w http.ResponseWriter, r *http.Request)

PatchUser handler @Summary PatchUser @Description Patch a user @Description [requires admin or ownership permissions] @Tags Users @Accept json @Produce json

@Router /users/{userID} [patch] @Param userID path int true "User ID" @Param user body model.UserPatch true "User patch body" @Success 200 {object} model.User @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func PatchUserTag

func PatchUserTag(w http.ResponseWriter, r *http.Request)

PatchUserTag handler @Summary PatchUserTag @Description Patch a tag @Description [requires admin or ownership permissions] @Tags Tags @Accept json @Produce json

@Router /users/{userID}/tags/{tagID} [patch] @Param userID path int true "User ID" @Param tagID path int true "Tag ID" @Param tag body model.TagPatch true "Tag patch body" @Success 200 {object} model.Tag @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 403 {object} model.AppError @Failure 500

func Plain

func Plain(w http.ResponseWriter, data []byte)

Plain write data to reponse writer and set the right content type

func Register

func Register(w http.ResponseWriter, r *http.Request)

Register handler @Summary Register @Description Register with user registration body @Tags Auth @Accept json

@Router /register [post] @Param registration body model.Registration true "Registration body" @Success 201 @Failure 400 {object} model.AppError @Failure 500

func Search(w http.ResponseWriter, r *http.Request)

Search handler @Summary Search @Description Search for softwares @Tags Softwares @Produce json

@Router /search [get] @Param q query string true "Search query" @Success 200 {array} model.Software @Failure 400 {object} model.AppError @Failure 401 {object} model.AppError @Failure 500

func SetContentTypeJSON

func SetContentTypeJSON(w http.ResponseWriter)

SetContentTypeJSON set the content type to application json

func SetContentTypePlain

func SetContentTypePlain(w http.ResponseWriter)

SetContentTypePlain set the content type to text plain

func SoftwareCtx

func SoftwareCtx(next http.Handler) http.Handler

SoftwareCtx middleware

func SoftwareFromCtx

func SoftwareFromCtx(ctx context.Context) *model.Software

SoftwareFromCtx get data from context

func Sorting

func Sorting(next http.Handler) http.Handler

Sorting middleware allow to insert sorting as query parameters

func UserCtx

func UserCtx(next http.Handler) http.Handler

UserCtx middleware

func UserFromCtx

func UserFromCtx(ctx context.Context) *model.User

UserFromCtx get data from context

Types

type API

type API struct{ *app.App }

API structure

type CtxKey

type CtxKey string

CtxKey string type

const PaginationKey CtxKey = "pagination"

PaginationKey constant

const SortingKey CtxKey = "sorting"

SortingKey constant

type PaginateValues

type PaginateValues struct {
	Limit  string
	Offset string
}

PaginateValues structure

type SortingValues

type SortingValues struct {
	SortBy  string
	OrderBy string
}

SortingValues structure

Jump to

Keyboard shortcuts

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