File tree Expand file tree Collapse file tree
src/main/java/zenika/oss/stats Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import jakarta .ws .rs .Path ;
66import jakarta .ws .rs .PathParam ;
77import jakarta .ws .rs .core .Response ;
8+ import zenika .oss .stats .exception .DatabaseException ;
9+ import zenika .oss .stats .services .FirestoreServices ;
810
911@ ApplicationScoped
1012@ Path ("/v1/contributions/" )
1113public class ContributionsRessources {
14+ private final FirestoreServices firestoreServices ;
15+
16+ @ jakarta .inject .Inject
17+ public ContributionsRessources (FirestoreServices firestoreServices ) {
18+ this .firestoreServices = firestoreServices ;
19+ }
20+
1221 /**
1322 * Get contributions for one member.
1423 *
@@ -17,11 +26,8 @@ public class ContributionsRessources {
1726 */
1827 @ GET
1928 @ Path ("/contributions/member/{memberId}" )
20- public Response getContributionsByMember (@ PathParam ("memberId" ) String memberId ) {
21-
22- return Response .ok ()
23- .build ();
24-
29+ public Response getContributionsByMember (@ PathParam ("memberId" ) String memberId ) throws DatabaseException {
30+ return Response .ok (firestoreServices .getContributionsForAMemberOrderByYear (memberId )).build ();
2531 }
2632
2733 @ GET
Original file line number Diff line number Diff line change @@ -161,4 +161,22 @@ public <T> void deleteAllDocuments(FirestoreCollections collectionType) throws D
161161 throw new DatabaseException (exception );
162162 }
163163 }
164+
165+ public List <StatsContribution > getContributionsForAMemberOrderByYear (String memberId ) throws DatabaseException {
166+ List <StatsContribution > stats = null ;
167+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
168+ Query query = zStats .whereEqualTo ("githubHandle" , memberId );
169+ ApiFuture <QuerySnapshot > querySnapshot = query .get ();
170+ try {
171+ stats = querySnapshot .get ().getDocuments ().stream ()
172+ .map (document -> document .toObject (StatsContribution .class ))
173+ .sorted ((s1 , s2 ) -> s2 .getYear ().compareTo (s1 .getYear ()))
174+ .sorted ((s1 , s2 ) -> s2 .getMonth ().compareTo (s1 .getMonth ()))
175+ .collect (java .util .stream .Collectors .toList ());
176+ } catch (InterruptedException | ExecutionException exception ) {
177+ throw new DatabaseException (exception );
178+ }
179+
180+ return stats ;
181+ }
164182}
You can’t perform that action at this time.
0 commit comments