Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/app/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type app struct {
services *services.AllServices
bus *eventbus.EventBus
authLimiter *authRateLimiter
foundLabelLimiter *simpleRateLimiter
notifierTestLimiter *simpleRateLimiter
otel *otel.Provider
}
Expand All @@ -38,6 +39,7 @@ func new(conf *config.Config) *app {
}

s.authLimiter = newAuthRateLimiter(s.conf.Auth.RateLimit)
s.foundLabelLimiter = newSimpleRateLimiter(60, time.Minute, s.conf.Options.TrustProxy) // 60 requests per minute
s.notifierTestLimiter = newSimpleRateLimiter(10, time.Minute, s.conf.Options.TrustProxy) // 10 requests per minute

return s
Expand Down
53 changes: 53 additions & 0 deletions backend/app/api/handlers/v1/v1_ctrl_found_item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package v1

import (
"net/http"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/hay-kot/httpkit/errchain"
"github.com/hay-kot/httpkit/server"
"github.com/sysadminsmedia/homebox/backend/internal/data/repo"
"github.com/sysadminsmedia/homebox/backend/internal/sys/validate"
"github.com/sysadminsmedia/homebox/backend/internal/web/adapters"
)

// HandleFoundEntityContact godoc
//
// @Summary Get found item contact
// @Tags Entities
// @Produce json
// @Param id path string true "Entity ID"
// @Success 200 {object} repo.FoundEntityContact
// @Router /v1/found/entities/{id} [GET]
func (ctrl *V1Controller) HandleFoundEntityContact() errchain.HandlerFunc {
fn := func(r *http.Request, ID uuid.UUID) (repo.FoundEntityContact, error) {
return ctrl.repo.Entities.GetFoundEntityContact(r.Context(), ID)
}

return adapters.CommandID("id", fn, http.StatusOK)
}

// HandleFoundAssetContact godoc
//
// @Summary Get found asset contact
// @Tags Entities
// @Produce json
// @Param id path string true "Asset ID"
// @Success 200 {object} repo.FoundEntityContact
// @Router /v1/found/assets/{id} [GET]
func (ctrl *V1Controller) HandleFoundAssetContact() errchain.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) error {
assetID, ok := repo.ParseAssetID(chi.URLParam(r, "id"))
if !ok || assetID.Nil() {
return validate.NewRouteKeyError("id")
}

contact, err := ctrl.repo.Entities.GetFoundEntityContactByAssetID(r.Context(), assetID)
if err != nil {
return err
}

return server.JSON(rw, http.StatusOK, contact)
}
}
2 changes: 2 additions & 0 deletions backend/app/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR

r.Post("/users/register", chain.ToHandlerFunc(v1Ctrl.HandleUserRegistration()))
r.Post("/users/login", chain.ToHandlerFunc(v1Ctrl.HandleAuthLogin(providers...), a.mwAuthRateLimit))
r.Get("/found/entities/{id}", chain.ToHandlerFunc(v1Ctrl.HandleFoundEntityContact(), a.foundLabelLimiter.middleware))
r.Get("/found/assets/{id}", chain.ToHandlerFunc(v1Ctrl.HandleFoundAssetContact(), a.foundLabelLimiter.middleware))

if a.conf.OIDC.Enabled {
r.Get("/users/login/oidc", chain.ToHandlerFunc(v1Ctrl.HandleOIDCLogin(), a.mwAuthRateLimit))
Expand Down
188 changes: 132 additions & 56 deletions backend/app/api/static/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,62 @@ const docTemplate = `{
}
}
},
"/v1/found/assets/{id}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Entities"
],
"summary": "Get found asset contact",
"parameters": [
{
"type": "string",
"description": "Asset ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/repo.FoundEntityContact"
}
}
}
}
},
"/v1/found/entities/{id}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Entities"
],
"summary": "Get found item contact",
"parameters": [
{
"type": "string",
"description": "Entity ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/repo.FoundEntityContact"
}
}
}
}
},
"/v1/groups": {
"get": {
"security": [
Expand Down Expand Up @@ -1439,36 +1495,6 @@ const docTemplate = `{
}
}
}
},
"post": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Group"
],
"summary": "Add User to Group",
"parameters": [
{
"description": "User ID",
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1.GroupMemberAdd"
}
}
],
"responses": {
"204": {
"description": "No Content"
}
}
}
},
"/v1/groups/members/{user_id}": {
Expand Down Expand Up @@ -3718,6 +3744,13 @@ const docTemplate = `{
"$ref": "#/definitions/ent.Tag"
}
},
"user_groups": {
"description": "UserGroups holds the value of the user_groups edge.",
"type": "array",
"items": {
"$ref": "#/definitions/ent.UserGroup"
}
},
"users": {
"description": "Users holds the value of the users edge.",
"type": "array",
Expand Down Expand Up @@ -4097,14 +4130,6 @@ const docTemplate = `{
"description": "OidcSubject holds the value of the \"oidc_subject\" field.",
"type": "string"
},
"role": {
"description": "Role holds the value of the \"role\" field.",
"allOf": [
{
"$ref": "#/definitions/user.Role"
}
]
},
"settings": {
"description": "Settings holds the value of the \"settings\" field.",
"type": "object",
Expand Down Expand Up @@ -4150,6 +4175,63 @@ const docTemplate = `{
"items": {
"$ref": "#/definitions/ent.Notifier"
}
},
"user_groups": {
"description": "UserGroups holds the value of the user_groups edge.",
"type": "array",
"items": {
"$ref": "#/definitions/ent.UserGroup"
}
}
}
},
"ent.UserGroup": {
"type": "object",
"properties": {
"edges": {
"description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the UserGroupQuery when eager-loading is set.",
"allOf": [
{
"$ref": "#/definitions/ent.UserGroupEdges"
}
]
},
"group_id": {
"description": "GroupID holds the value of the \"group_id\" field.",
"type": "string"
},
"role": {
"description": "Role holds the value of the \"role\" field.",
"allOf": [
{
"$ref": "#/definitions/usergroup.Role"
}
]
},
"user_id": {
"description": "UserID holds the value of the \"user_id\" field.",
"type": "string"
}
}
},
"ent.UserGroupEdges": {
"type": "object",
"properties": {
"group": {
"description": "Group holds the value of the group edge.",
"allOf": [
{
"$ref": "#/definitions/ent.Group"
}
]
},
"user": {
"description": "User holds the value of the user edge.",
"allOf": [
{
"$ref": "#/definitions/ent.User"
}
]
}
}
},
Expand Down Expand Up @@ -5096,6 +5178,17 @@ const docTemplate = `{
}
}
},
"repo.FoundEntityContact": {
"type": "object",
"properties": {
"itemId": {
"type": "string"
},
"ownerEmail": {
"type": "string"
}
}
},
"repo.Group": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5647,9 +5740,6 @@ const docTemplate = `{
"id": {
"type": "string"
},
"isOwner": {
"type": "boolean"
},
"isSuperuser": {
"type": "boolean"
},
Expand All @@ -5673,9 +5763,6 @@ const docTemplate = `{
"id": {
"type": "string"
},
"isOwner": {
"type": "boolean"
},
"name": {
"type": "string"
}
Expand Down Expand Up @@ -5772,7 +5859,7 @@ const docTemplate = `{
"TypeTime"
]
},
"user.Role": {
"usergroup.Role": {
"type": "string",
"enum": [
"user",
Expand Down Expand Up @@ -5944,17 +6031,6 @@ const docTemplate = `{
}
}
},
"v1.GroupMemberAdd": {
"type": "object",
"required": [
"userId"
],
"properties": {
"userId": {
"type": "string"
}
}
},
"v1.LoginForm": {
"type": "object",
"properties": {
Expand Down
Loading
Loading