Skip to content

Commit

Permalink
[#11878] Add sort by created_at for getAllPendingRequests (#13038)
Browse files Browse the repository at this point in the history
* feat: add order-by

* fix: fix failing test case

* fix: add missing created-at field

* fix: test case comment
  • Loading branch information
EuniceSim142 authored Apr 16, 2024
1 parent 665752c commit 7b05fec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ public void testExecute() {

assertEquals(2, arData.size());

// account request 1
assertEquals(arData.get(0).getEmail(), accountRequest1.getEmail());
assertEquals(arData.get(0).getInstitute(), accountRequest1.getInstitute());
assertEquals(arData.get(0).getName(), accountRequest1.getName());
assertEquals(arData.get(0).getRegistrationKey(), accountRequest1.getRegistrationKey());
// account request 1 (with the most recent created_at)
assertEquals(arData.get(1).getEmail(), accountRequest1.getEmail());
assertEquals(arData.get(1).getInstitute(), accountRequest1.getInstitute());
assertEquals(arData.get(1).getName(), accountRequest1.getName());
assertEquals(arData.get(1).getRegistrationKey(), accountRequest1.getRegistrationKey());

// account request 2
assertEquals(arData.get(1).getEmail(), accountRequest2.getEmail());
assertEquals(arData.get(1).getInstitute(), accountRequest2.getInstitute());
assertEquals(arData.get(1).getName(), accountRequest2.getName());
assertEquals(arData.get(1).getRegistrationKey(), accountRequest2.getRegistrationKey());
assertEquals(arData.get(0).getEmail(), accountRequest2.getEmail());
assertEquals(arData.get(0).getInstitute(), accountRequest2.getInstitute());
assertEquals(arData.get(0).getName(), accountRequest2.getName());
assertEquals(arData.get(0).getRegistrationKey(), accountRequest2.getRegistrationKey());
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"name": "Instructor 1",
"email": "instr1@teammates.tmt",
"institute": "TEAMMATES Test Institute 1",
"registeredAt": "2010-02-14T00:00:00Z"
"registeredAt": "2010-02-14T00:00:00Z",
"createdAt": "2011-02-01T00:00:00Z"
},
"instructor2": {
"id": "00000000-0000-4000-8000-000000000102",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public List<AccountRequest> getPendingAccountRequests() {
CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder();
CriteriaQuery<AccountRequest> cr = cb.createQuery(AccountRequest.class);
Root<AccountRequest> root = cr.from(AccountRequest.class);
cr.select(root).where(cb.equal(root.get("status"), AccountRequestStatus.PENDING));
cr.select(root)
.where(cb.equal(root.get("status"), AccountRequestStatus.PENDING))
.orderBy(cb.desc(root.get("createdAt")));

TypedQuery<AccountRequest> query = HibernateUtil.createQuery(cr);
return query.getResultList();
Expand Down

0 comments on commit 7b05fec

Please sign in to comment.