Skip to content

Commit 1ae0f5b

Browse files
committed
feat: order by created at desc
1 parent 657a29d commit 1ae0f5b

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

apps/history-service/handlers/createOrUpdate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"google.golang.org/grpc/status"
1414
)
1515

16+
// Unused
1617
func (s *Service) CreateOrUpdateHistory(w http.ResponseWriter, r *http.Request) {
1718
ctx := r.Context()
1819

apps/history-service/handlers/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"google.golang.org/grpc/status"
99
)
1010

11-
// Delete a code snippet by ID
11+
// Delete a code snippet by ID: unused
1212
func (s *Service) DeleteHistory(w http.ResponseWriter, r *http.Request) {
1313
ctx := r.Context()
1414

apps/history-service/handlers/listquestionhistory.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"history-service/models"
66
"net/http"
77

8+
"cloud.google.com/go/firestore"
89
"github.com/go-chi/chi/v5"
910
"google.golang.org/api/iterator"
1011
)
@@ -20,8 +21,14 @@ func (s *Service) ListUserQuestionHistories(w http.ResponseWriter, r *http.Reque
2021
collRef := s.Client.Collection("collaboration-history")
2122

2223
// Query data
23-
iterUser := collRef.Where("user", "==", username).Where("questionDocRefId", "==", questionDocRefID).Documents(ctx)
24-
iterMatchedUser := collRef.Where("matchedUser", "==", username).Where("questionDocRefId", "==", questionDocRefID).Documents(ctx)
24+
iterUser := collRef.Where("user", "==", username).
25+
Where("questionDocRefId", "==", questionDocRefID).
26+
OrderBy("createdAt", firestore.Desc).
27+
Documents(ctx)
28+
iterMatchedUser := collRef.Where("matchedUser", "==", username).
29+
Where("questionDocRefId", "==", questionDocRefID).
30+
OrderBy("createdAt", firestore.Desc).
31+
Documents(ctx)
2532

2633
// Map data
2734
var histories []models.CollaborationHistory
@@ -62,6 +69,10 @@ func (s *Service) ListUserQuestionHistories(w http.ResponseWriter, r *http.Reque
6269
}
6370
history.HistoryDocRefID = doc.Ref.ID
6471

72+
// Swap matched user and user
73+
history.MatchedUser = history.User
74+
history.User = username
75+
6576
histories = append(histories, history)
6677
}
6778

apps/history-service/handlers/listuserhistory.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"history-service/models"
66
"net/http"
77

8+
"cloud.google.com/go/firestore"
89
"github.com/go-chi/chi/v5"
910
"google.golang.org/api/iterator"
1011
)
@@ -19,8 +20,12 @@ func (s *Service) ListUserHistories(w http.ResponseWriter, r *http.Request) {
1920
collRef := s.Client.Collection("collaboration-history")
2021

2122
// Query data
22-
iterUser := collRef.Where("user", "==", username).Documents(ctx)
23-
iterMatchedUser := collRef.Where("matchedUser", "==", username).Documents(ctx)
23+
iterUser := collRef.Where("user", "==", username).
24+
OrderBy("createdAt", firestore.Desc).
25+
Documents(ctx)
26+
iterMatchedUser := collRef.Where("matchedUser", "==", username).
27+
OrderBy("createdAt", firestore.Desc).
28+
Documents(ctx)
2429

2530
// Map data
2631
var histories []models.CollaborationHistory
@@ -61,6 +66,10 @@ func (s *Service) ListUserHistories(w http.ResponseWriter, r *http.Request) {
6166
}
6267
history.HistoryDocRefID = doc.Ref.ID
6368

69+
// Swap matched user and user
70+
history.MatchedUser = history.User
71+
history.User = username
72+
6473
histories = append(histories, history)
6574
}
6675

apps/history-service/handlers/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"google.golang.org/grpc/status"
1414
)
1515

16-
// Update an existing code snippet
16+
// Update an existing code snippet: Unused
1717
func (s *Service) UpdateHistory(w http.ResponseWriter, r *http.Request) {
1818
ctx := r.Context()
1919

0 commit comments

Comments
 (0)