5
5
"history-service/models"
6
6
"net/http"
7
7
8
+ "cloud.google.com/go/firestore"
8
9
"github.com/go-chi/chi/v5"
9
10
"google.golang.org/api/iterator"
10
11
)
@@ -20,8 +21,14 @@ func (s *Service) ListUserQuestionHistories(w http.ResponseWriter, r *http.Reque
20
21
collRef := s .Client .Collection ("collaboration-history" )
21
22
22
23
// 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 )
25
32
26
33
// Map data
27
34
var histories []models.CollaborationHistory
@@ -62,6 +69,10 @@ func (s *Service) ListUserQuestionHistories(w http.ResponseWriter, r *http.Reque
62
69
}
63
70
history .HistoryDocRefID = doc .Ref .ID
64
71
72
+ // Swap matched user and user
73
+ history .MatchedUser = history .User
74
+ history .User = username
75
+
65
76
histories = append (histories , history )
66
77
}
67
78
0 commit comments