mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 21:16:31 +00:00
23b5892aef
* introduce scaffold for new models * wip: shoutrrr wrapper (may remove) * update schema files * gen: ent code * gen: migrations * go mod tidy * add group_id to notifier * db migration * new mapper helpers * notifier repo * introduce experimental adapter pattern for hdlrs * refactor adapters to fit more common use cases * new routes for notifiers * update errors to fix validation panic * go tidy * reverse checkbox label display * wip: notifiers UI * use badges instead of text * improve documentation * add scaffold schema reference * remove notifier service * refactor schema folder * support group edges via scaffold * delete test file * include link to API docs * audit and update documentation + improve format * refactor schema edges * refactor * add custom validator * set validate + order fields by name * fix failing tests
27 lines
872 B
Go
27 lines
872 B
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/internal/sys/validate"
|
|
)
|
|
|
|
// routeID extracts the ID from the request URL. If the ID is not in a valid
|
|
// format, an error is returned. If a error is returned, it can be directly returned
|
|
// from the handler. the validate.ErrInvalidID error is known by the error middleware
|
|
// and will be handled accordingly.
|
|
//
|
|
// Example: /api/v1/ac614db5-d8b8-4659-9b14-6e913a6eb18a -> uuid.UUID{ac614db5-d8b8-4659-9b14-6e913a6eb18a}
|
|
func (ctrl *V1Controller) routeID(r *http.Request) (uuid.UUID, error) {
|
|
return ctrl.routeUUID(r, "id")
|
|
}
|
|
|
|
func (ctrl *V1Controller) routeUUID(r *http.Request, key string) (uuid.UUID, error) {
|
|
ID, err := uuid.Parse(chi.URLParam(r, key))
|
|
if err != nil {
|
|
return uuid.Nil, validate.NewRouteKeyError(key)
|
|
}
|
|
return ID, nil
|
|
}
|