-
-
Notifications
You must be signed in to change notification settings - Fork 441
Maintenance plans / Recurring maintenance #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/hay-kot/httpkit/errchain" | ||
| "github.com/sysadminsmedia/homebox/backend/internal/core/services" | ||
| "github.com/sysadminsmedia/homebox/backend/internal/data/repo" | ||
| "github.com/sysadminsmedia/homebox/backend/internal/web/adapters" | ||
| ) | ||
|
|
||
| // HandleMaintenancePlanGetAll godoc | ||
| // | ||
| // @Summary Query Maintenance Plans | ||
| // @Tags Item Maintenance | ||
| // @Produce json | ||
| // @Param id path string true "Item ID" | ||
| // @Success 200 {array} repo.MaintenancePlan[] | ||
| // @Router /v1/entities/{id}/maintenance/plans [GET] | ||
| // @Security Bearer | ||
| func (ctrl *V1Controller) HandleMaintenancePlanGetAll() errchain.HandlerFunc { | ||
| fn := func(r *http.Request, itemID uuid.UUID, _ struct{}) ([]repo.MaintenancePlan, error) { | ||
| auth := services.NewContext(r.Context()) | ||
| return ctrl.repo.MaintEntry.ListPlansByItemID(auth, auth.GID, itemID) | ||
| } | ||
|
|
||
| return adapters.QueryID("id", fn, http.StatusOK) | ||
| } | ||
|
|
||
| // HandleMaintenancePlanCreate godoc | ||
| // | ||
| // @Summary Create Maintenance Plan | ||
| // @Tags Item Maintenance | ||
| // @Produce json | ||
| // @Param id path string true "Item ID" | ||
| // @Param payload body repo.MaintenancePlanCreate true "Plan Data" | ||
| // @Success 201 {object} repo.MaintenancePlan | ||
| // @Router /v1/entities/{id}/maintenance/plans [POST] | ||
| // @Security Bearer | ||
| func (ctrl *V1Controller) HandleMaintenancePlanCreate() errchain.HandlerFunc { | ||
| fn := func(r *http.Request, itemID uuid.UUID, body repo.MaintenancePlanCreate) (repo.MaintenancePlan, error) { | ||
| auth := services.NewContext(r.Context()) | ||
| return ctrl.repo.MaintEntry.CreatePlan(auth, itemID, body) | ||
| } | ||
|
|
||
| return adapters.ActionID("id", fn, http.StatusCreated) | ||
| } | ||
|
Comment on lines
+41
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm no other call site invokes Validate() on these DTOs (to be sure the handler is the only entry point).
rg -nP '\b(MaintenancePlanCreate|MaintenancePlanUpdate)\b' --type=go -g '!**/vendor/**'
rg -nP '\.Validate\(\)' --type=go -g '!**/vendor/**' | rg -i 'maintenance'Repository: sysadminsmedia/homebox Length of output: 13038 🏁 Script executed: #!/bin/bash
# Check the actual Validate() implementations
sed -n '56,75p' backend/internal/data/repo/repo_maintenance_plan.go
echo "---"
sed -n '64,75p' backend/internal/data/repo/repo_maintenance_plan.go
echo "---"
# Check the full handler file
cat -n backend/app/api/handlers/v1/v1_ctrl_maintenance_plan.go | head -75Repository: sysadminsmedia/homebox Length of output: 4032 🏁 Script executed: #!/bin/bash
# Check the CreatePlan and UpdatePlan implementations
sed -n '125,160p' backend/internal/data/repo/repo_maintenance_plan.go
echo "---"
# Check if validate package is used in other handlers
rg -n 'validate\.' backend/app/api/handlers/v1/ --type=go | head -20
echo "---"
# Check if CreatePlan calls Validate()
rg -A10 'func.*CreatePlan' backend/internal/data/repo/repo_maintenance_plan.go | head -20Repository: sysadminsmedia/homebox Length of output: 4020 🏁 Script executed: #!/bin/bash
# Check coding guidelines for handler validation requirements
grep -n "Validate\|validation\|validate" backend/app/api/handlers/v1/*.go | grep -i "pattern\|should\|must" | head -10
echo "---"
# Check other handlers with body validation to see the pattern
rg -B3 'body\.Validate' backend/app/api/handlers/v1/ --type=go | head -30Repository: sysadminsmedia/homebox Length of output: 70 🏁 Script executed: #!/bin/bash
# Check if any handler calls Validate() on body
rg 'body\.Validate\(\)' backend/app/api/handlers/ --type=go
echo "---"
# Check if CreatePlan/UpdatePlan methods have any validation despite not calling Validate()
sed -n '125,175p' backend/internal/data/repo/repo_maintenance_plan.goRepository: sysadminsmedia/homebox Length of output: 1551 Call
Affected handlers and fixHandleMaintenancePlanCreate (lines 42–47): fn := func(r *http.Request, itemID uuid.UUID, body repo.MaintenancePlanCreate) (repo.MaintenancePlan, error) {
+ if err := body.Validate(); err != nil {
+ return repo.MaintenancePlan{}, validate.NewRequestError(err, http.StatusBadRequest)
+ }
auth := services.NewContext(r.Context())
return ctrl.repo.MaintEntry.CreatePlan(auth, itemID, body)
}HandleMaintenancePlanUpdate (lines 61–66): Apply the same pattern. 🤖 Prompt for AI Agents |
||
|
|
||
| // HandleMaintenancePlanUpdate godoc | ||
| // | ||
| // @Summary Update Maintenance Plan | ||
| // @Tags Maintenance | ||
| // @Produce json | ||
| // @Param id path string true "Plan ID" | ||
| // @Param payload body repo.MaintenancePlanUpdate true "Plan Data" | ||
| // @Success 200 {object} repo.MaintenancePlan | ||
| // @Router /v1/maintenance/plans/{id} [PUT] | ||
| // @Security Bearer | ||
| func (ctrl *V1Controller) HandleMaintenancePlanUpdate() errchain.HandlerFunc { | ||
| fn := func(r *http.Request, planID uuid.UUID, body repo.MaintenancePlanUpdate) (repo.MaintenancePlan, error) { | ||
| auth := services.NewContext(r.Context()) | ||
| return ctrl.repo.MaintEntry.UpdatePlan(auth, planID, body) | ||
| } | ||
|
|
||
| return adapters.ActionID("id", fn, http.StatusOK) | ||
| } | ||
|
|
||
| // HandleMaintenancePlanDelete godoc | ||
| // | ||
| // @Summary Delete Maintenance Plan | ||
| // @Tags Maintenance | ||
| // @Produce json | ||
| // @Param id path string true "Plan ID" | ||
| // @Success 204 | ||
| // @Router /v1/maintenance/plans/{id} [DELETE] | ||
| // @Security Bearer | ||
| func (ctrl *V1Controller) HandleMaintenancePlanDelete() errchain.HandlerFunc { | ||
| fn := func(r *http.Request, planID uuid.UUID) (any, error) { | ||
| auth := services.NewContext(r.Context()) | ||
| return nil, ctrl.repo.MaintEntry.DeletePlan(auth, planID) | ||
| } | ||
|
|
||
| return adapters.CommandID("id", fn, http.StatusNoContent) | ||
| } | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.