Skip to content
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

fix: sorting for completed and scheduled maintenance entries #384

Merged
Merged
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion backend/internal/data/repo/repo_maintenance_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"errors"
"time"

"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
Expand Down Expand Up @@ -130,21 +131,35 @@
item.HasGroupWith(group.IDEQ(groupID)),
),
)
if filters.Status == MaintenanceFilterStatusScheduled {

Check failure on line 134 in backend/internal/data/repo/repo_maintenance_entry.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

ifElseChain: rewrite if-else to switch statement (gocritic)
query = query.Where(maintenanceentry.Or(
maintenanceentry.DateIsNil(),
maintenanceentry.DateEQ(time.Time{}),
maintenanceentry.DateGT(time.Now()),
))
// Sort scheduled entries by ascending scheduled date
query = query.Order(
maintenanceentry.ByScheduledDate(sql.OrderAsc()),
)
} else if filters.Status == MaintenanceFilterStatusCompleted {
query = query.Where(
maintenanceentry.Not(maintenanceentry.Or(
maintenanceentry.DateIsNil(),
maintenanceentry.DateEQ(time.Time{}),
maintenanceentry.DateGT(time.Now()),
)))
// Sort completed entries by descending completion date
query = query.Order(
maintenanceentry.ByDate(sql.OrderDesc()),
)
} else {
// Sort entries by default by scheduled and maintenance date in descending order
query = query.Order(
maintenanceentry.ByScheduledDate(sql.OrderDesc()),
maintenanceentry.ByDate(sql.OrderDesc()),
)
}
entries, err := query.WithItem().Order(maintenanceentry.ByScheduledDate()).All(ctx)
entries, err := query.WithItem().All(ctx)

if err != nil {
return []MaintenanceEntryWithDetails{}, err
Expand Down
Loading