Skip to content

Commit

Permalink
refactor: rewrite if-else as switch-case
Browse files Browse the repository at this point in the history
  • Loading branch information
zebrapurring committed Dec 12, 2024
1 parent 2e20832 commit c5ffa0e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions backend/internal/data/repo/repo_maintenance_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func (r *MaintenanceEntryRepository) GetMaintenanceByItemID(ctx context.Context,
item.HasGroupWith(group.IDEQ(groupID)),
),
)
if filters.Status == MaintenanceFilterStatusScheduled {
switch filters.Status {
case MaintenanceFilterStatusScheduled:
query = query.Where(maintenanceentry.Or(
maintenanceentry.DateIsNil(),
maintenanceentry.DateEQ(time.Time{}),
Expand All @@ -141,7 +142,7 @@ func (r *MaintenanceEntryRepository) GetMaintenanceByItemID(ctx context.Context,
query = query.Order(
maintenanceentry.ByScheduledDate(sql.OrderAsc()),
)
} else if filters.Status == MaintenanceFilterStatusCompleted {
case MaintenanceFilterStatusCompleted:
query = query.Where(
maintenanceentry.Not(maintenanceentry.Or(
maintenanceentry.DateIsNil(),
Expand All @@ -152,7 +153,7 @@ func (r *MaintenanceEntryRepository) GetMaintenanceByItemID(ctx context.Context,
query = query.Order(
maintenanceentry.ByDate(sql.OrderDesc()),
)
} else {
default:
// Sort entries by default by scheduled and maintenance date in descending order
query = query.Order(
maintenanceentry.ByScheduledDate(sql.OrderDesc()),
Expand Down

0 comments on commit c5ffa0e

Please sign in to comment.