From 96d576b76d8f2bca123999f2f09111ad1a1644dd Mon Sep 17 00:00:00 2001 From: ItsNotGoodName Date: Sun, 17 Sep 2023 21:20:59 -0700 Subject: [PATCH] fix(repo): trace list ordering --- internal/repo/trace.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/repo/trace.go b/internal/repo/trace.go index 4d60623..31258e9 100644 --- a/internal/repo/trace.go +++ b/internal/repo/trace.go @@ -80,10 +80,16 @@ func TraceList(ctx context.Context, db database.Querier, page pagination.Page, r Count int `sql:"primary_key"` Trace []models.Trace } - err := SELECT(tracePJ, Raw("t.count").AS("count")). + query := SELECT(tracePJ, Raw("t.count").AS("count")). FROM(subQuery.AsTable("t"). - LEFT_JOIN(Traces, RawString("t.request_id").EQ(Traces.RequestID))). - QueryContext(ctx, db, &res) + LEFT_JOIN(Traces, RawString("t.request_id").EQ(Traces.RequestID))) + // Order + if req.Ascending { + query = query.ORDER_BY(Traces.Seq.ASC()) + } else { + query = query.ORDER_BY(Traces.Seq.DESC()) + } + err := query.QueryContext(ctx, db, &res) if err != nil && !errors.Is(err, ErrNoRows) { return models.DTOTraceListResult{}, err }