mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-21 22:36:31 +00:00
31b34241e0
* change /content/ -> /homebox/ * add cache to code generators * update env variables to set data storage * update env variables * set env variables in prod container * implement attachment post route (WIP) * get attachment endpoint * attachment download * implement string utilities lib * implement generic drop zone * use explicit truncate * remove clean dir * drop strings composable for lib * update item types and add attachments * add attachment API * implement service context * consolidate API code * implement editing attachments * implement upload limit configuration * improve error handling * add docs for max upload size * fix test cases
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/internal/services"
|
|
"github.com/hay-kot/homebox/backend/internal/types"
|
|
"github.com/hay-kot/homebox/backend/pkgs/server"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
/*
|
|
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 {
|
|
log.Err(err).Msg("failed to parse id")
|
|
server.RespondError(w, http.StatusBadRequest, err)
|
|
return uuid.Nil, nil, err
|
|
}
|
|
|
|
user := services.UseUserCtx(r.Context())
|
|
return uid, user, nil
|
|
}
|