Skip to content

Commit

Permalink
fix: cleanup sort order by conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 14, 2024
1 parent a118baf commit 6d1f025
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 48 deletions.
4 changes: 1 addition & 3 deletions gen/go/proto/services/citizenstore/citizenstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@ func (s *Server) ListUserActivity(ctx context.Context, req *ListUserActivityRequ
orderBys = append(orderBys, column.DESC())
}
} else {
orderBys = append(orderBys,
tUserActivity.CreatedAt.DESC(),
)
orderBys = append(orderBys, tUserActivity.CreatedAt.DESC())
}

stmt := tUserActivity.
Expand Down
4 changes: 1 addition & 3 deletions gen/go/proto/services/dmv/vehicles.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ func (s *Server) ListVehicles(ctx context.Context, req *ListVehiclesRequest) (*L
orderBys = append(orderBys, column.DESC())
}
} else {
orderBys = append(orderBys,
tVehicles.Plate.ASC(),
)
orderBys = append(orderBys, tVehicles.Plate.ASC())
}

columns := dbutils.Columns{
Expand Down
4 changes: 1 addition & 3 deletions gen/go/proto/services/docstore/docstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ func (s *Server) ListDocuments(ctx context.Context, req *ListDocumentsRequest) (
)
}
} else {
orderBys = append(orderBys,
tDocumentShort.UpdatedAt.DESC(),
)
orderBys = append(orderBys, tDocumentShort.UpdatedAt.DESC())
}

pag, limit := req.Pagination.GetResponseWithPageSize(count.TotalCount, DocsDefaultPageSize)
Expand Down
19 changes: 7 additions & 12 deletions gen/go/proto/services/jobs/colleagues.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ func (s *Server) ListColleagues(ctx context.Context, req *ListColleaguesRequest)
// Convert proto sort to db sorting
orderBys := []jet.OrderByClause{}
if req.Sort != nil {
var column jet.Column
var columns []jet.Column
switch req.Sort.Column {
case "name":
column = nil
columns = append(columns, tUser.Firstname, tUser.Lastname)
case "rank":
fallthrough
default:
column = tUser.JobGrade
columns = append(columns, tUser.JobGrade)
}

if column != nil {
for _, column := range columns {
if req.Sort.Direction == database.AscSortDirection {
orderBys = append(orderBys, column.ASC())
} else {
Expand All @@ -115,13 +115,10 @@ func (s *Server) ListColleagues(ctx context.Context, req *ListColleaguesRequest)
} else {
orderBys = append(orderBys,
tUser.JobGrade.ASC(),
tUser.Firstname.ASC(),
tUser.Lastname.ASC(),
)
}
// Always append firstname and lastname sorting
orderBys = append(orderBys,
tUser.Firstname.ASC(),
tUser.Lastname.ASC(),
)

stmt := tUser.
SELECT(
Expand Down Expand Up @@ -788,9 +785,7 @@ func (s *Server) ListColleagueActivity(ctx context.Context, req *ListColleagueAc
orderBys = append(orderBys, column.DESC())
}
} else {
orderBys = append(orderBys,
tJobsUserActivity.CreatedAt.DESC(),
)
orderBys = append(orderBys, tJobsUserActivity.CreatedAt.DESC())
}

tTargetUserProps := tUserProps.AS("target_user_props")
Expand Down
20 changes: 10 additions & 10 deletions gen/go/proto/services/jobs/conduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,25 @@ func (s *Server) ListConductEntries(ctx context.Context, req *ListConductEntries
// Convert proto sort to db sorting
orderBys := []jet.OrderByClause{}
if req.Sort != nil {
var column jet.Column
var columns []jet.Column
switch req.Sort.Column {
case "type":
column = tConduct.Type
columns = append(columns, tConduct.Type, tConduct.ID)
case "id":
fallthrough
default:
column = tConduct.ID
columns = append(columns, tConduct.ID)
}

if req.Sort.Direction == database.AscSortDirection {
orderBys = append(orderBys, column.ASC())
} else {
orderBys = append(orderBys, column.DESC())
for _, column := range columns {
if req.Sort.Direction == database.AscSortDirection {
orderBys = append(orderBys, column.ASC())
} else {
orderBys = append(orderBys, column.DESC())
}
}
} else {
orderBys = append(orderBys,
tConduct.ID.DESC(),
)
orderBys = append(orderBys, tConduct.ID.DESC())
}

tUser := tUser.AS("target_user")
Expand Down
16 changes: 5 additions & 11 deletions gen/go/proto/services/jobs/timeclock.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,32 +294,26 @@ func (s *Server) ListInactiveEmployees(ctx context.Context, req *ListInactiveEmp
// Convert proto sort to db sorting
orderBys := []jet.OrderByClause{}
if req.Sort != nil {
var column jet.Column
var columns []jet.Column
switch req.Sort.Column {
case "name":
column = nil
columns = append(columns, tUser.Firstname, tUser.Lastname)
case "rank":
fallthrough
default:
column = tUser.JobGrade
columns = append(columns, tUser.JobGrade)
}

if column != nil {
for _, column := range columns {
if req.Sort.Direction == database.AscSortDirection {
orderBys = append(orderBys, column.ASC())
} else {
orderBys = append(orderBys, column.DESC())
}
}
} else {
orderBys = append(orderBys,
tConduct.ID.DESC(),
)
orderBys = append(orderBys, tUser.JobGrade.ASC())
}
orderBys = append(orderBys,
tUser.Firstname.ASC(),
tUser.Lastname.ASC(),
)

stmt := tTimeClock.
SELECT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ func (s *Server) ListQualificationRequests(ctx context.Context, req *ListQualifi
orderBys = append(orderBys, column.DESC())
}
} else {
orderBys = append(orderBys,
tQualiRequests.CreatedAt.DESC(),
)
orderBys = append(orderBys, tQualiRequests.CreatedAt.DESC())
}

stmt := tQualiRequests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ func (s *Server) ListQualificationsResults(ctx context.Context, req *ListQualifi
orderBys = append(orderBys, column.DESC())
}
} else {
orderBys = append(orderBys,
tQualiResults.CreatedAt.DESC(),
)
orderBys = append(orderBys, tQualiResults.CreatedAt.DESC())
}

stmt := tQualiResults.
Expand Down

0 comments on commit 6d1f025

Please sign in to comment.