Skip to content

Commit

Permalink
Sort by ID during CSV export
Browse files Browse the repository at this point in the history
Fixes #1997

Add methods to sort by ID in various DAO interfaces and implementations.

* **DAO Interfaces:**
  - Add `readAllOrderedById` method to `EmojiDao`, `ImageDao`, `LetterDao`, `LetterSoundDao`, `NumberDao`, `SoundDao`, `StoryBookDao`, and `WordDao` interfaces.

* **DAO Implementations:**
  - Implement `readAllOrderedById` method in `EmojiDaoJpa`, `ImageDaoJpa`, `LetterDaoJpa`, `LetterSoundDaoJpa`, `NumberDaoJpa`, `SoundDaoJpa`, `StoryBookDaoJpa`, and `WordDaoJpa` classes.

* **CSV Export Controllers:**
  - Update `EmojiCsvExportController` to use `emojiDao.readAllOrderedById`.
  - Update `LetterSoundCsvExportController` to use `letterSoundDao.readAllOrderedById`.
  - Update `LetterCsvExportController` to use `letterDao.readAllOrderedById`.
  - Update `NumberCsvExportController` to use `numberDao.readAllOrderedById`.
  - Update `SoundCsvExportController` to use `soundDao.readAllOrderedById`.
  - Update `StoryBookCsvExportController` to use `storyBookDao.readAllOrderedById`.
  - Update `WordCsvExportController` to use `wordDao.readAllOrderedById`.
  • Loading branch information
AbaSheger committed Feb 12, 2025
1 parent 30c00ed commit 2cad4d4
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/EmojiDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface EmojiDao extends GenericDao<Emoji> {
* Fetch all Emojis that have been labeled by a Word.
*/
List<Emoji> readAllLabeled(Word word) throws DataAccessException;

List<Emoji> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/ImageDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface ImageDao extends GenericDao<Image> {
* Fetch all Images that have been labeled by a Word.
*/
List<Image> readAllLabeled(Word word) throws DataAccessException;

List<Image> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/LetterDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface LetterDao extends GenericDao<Letter> {
List<Letter> readAllOrdered() throws DataAccessException;

List<Letter> readAllOrderedByUsage() throws DataAccessException;

List<Letter> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/LetterSoundDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface LetterSoundDao extends GenericDao<LetterSound> {
List<LetterSound> readAllOrderedByUsage() throws DataAccessException;

List<LetterSound> readAllOrderedByLettersLength() throws DataAccessException;

List<LetterSound> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/NumberDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface NumberDao extends GenericDao<Number> {
Number readByValue(Integer value) throws DataAccessException;

List<Number> readAllOrdered() throws DataAccessException;

List<Number> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/SoundDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface SoundDao extends GenericDao<Sound> {
List<Sound> readAllOrderedByIpaValueCharacterLength() throws DataAccessException;

List<Sound> readAllOrderedByUsage() throws DataAccessException;

List<Sound> readAllOrderedById() throws DataAccessException;
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/StoryBookDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface StoryBookDao extends GenericDao<StoryBook> {
List<StoryBook> readAllOrdered(ReadingLevel readingLevel) throws DataAccessException;

List<StoryBook> readAllUnleveled() throws DataAccessException;

List<StoryBook> readAllOrderedById() throws DataAccessException; // Pd3b6
}
2 changes: 2 additions & 0 deletions src/main/java/ai/elimu/dao/WordDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface WordDao extends GenericDao<Word> {
List<Word> readLatest() throws DataAccessException;

List<Word> readInflections(Word word) throws DataAccessException;

List<Word> readAllOrderedById() throws DataAccessException;
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/EmojiDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ public List<Emoji> readAllLabeled(Word word) throws DataAccessException {
.setParameter("word", word)
.getResultList();
}

@Override
public List<Emoji> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM Emoji e " +
"ORDER BY e.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/ImageDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ public List<Image> readAllLabeled(Word word) throws DataAccessException {
.setParameter("word", word)
.getResultList();
}

@Override
public List<Image> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT i " +
"FROM Image i " +
"ORDER BY i.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/LetterDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ public List<Letter> readAllOrderedByUsage() throws DataAccessException {
"ORDER BY l.usageCount DESC, l.text")
.getResultList();
}

@Override
public List<Letter> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT l " +
"FROM Letter l " +
"ORDER BY l.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/LetterSoundDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ public List<LetterSound> readAllOrderedByLettersLength() throws DataAccessExcept
"ORDER BY lsc.letters.size DESC, lsc.usageCount DESC")
.getResultList();
}

@Override
public List<LetterSound> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT lsc " +
"FROM LetterSound lsc " +
"ORDER BY lsc.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/NumberDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public List<Number> readAllOrdered() throws DataAccessException {
"ORDER BY n.value")
.getResultList();
}

@Override
public List<Number> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT n " +
"FROM Number n " +
"ORDER BY n.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/SoundDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ public List<Sound> readAllOrderedByUsage() throws DataAccessException {
"ORDER BY s.usageCount DESC, s.valueIpa")
.getResultList();
}

@Override
public List<Sound> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT s " +
"FROM Sound s " +
"ORDER BY s.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/StoryBookDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ public List<StoryBook> readAllUnleveled() throws DataAccessException {
"ORDER BY book.title")
.getResultList();
}

@Override
public List<StoryBook> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT book " +
"FROM StoryBook book " +
"ORDER BY book.id")
.getResultList();
}
}
9 changes: 9 additions & 0 deletions src/main/java/ai/elimu/dao/jpa/WordDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ public List<Word> readInflections(Word word) throws DataAccessException {
.setParameter("word", word)
.getResultList();
}

@Override
public List<Word> readAllOrderedById() throws DataAccessException {
return em.createQuery(
"SELECT w " +
"FROM Word w " +
"ORDER BY w.id")
.getResultList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<Emoji> emojis = emojiDao.readAllOrdered();
List<Emoji> emojis = emojiDao.readAllOrderedById();
logger.info("emojis.size(): " + emojis.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<Letter> letters = letterDao.readAllOrderedByUsage();
List<Letter> letters = letterDao.readAllOrderedById();
logger.info("letters.size(): " + letters.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<LetterSound> letterSounds = letterSoundDao.readAllOrderedByUsage();
List<LetterSound> letterSounds = letterSoundDao.readAllOrderedById();
logger.info("letterSounds.size(): " + letterSounds.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<Number> numbers = numberDao.readAllOrdered();
List<Number> numbers = numberDao.readAllOrderedById();
logger.info("numbers.size(): " + numbers.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<Sound> sounds = soundDao.readAllOrderedByUsage();
List<Sound> sounds = soundDao.readAllOrderedById();
logger.info("sounds.size(): " + sounds.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
List<StoryBook> storyBooks = storyBookDao.readAllOrderedById();
logger.info("storyBooks.size(): " + storyBooks.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void handleRequest(
) throws IOException {
logger.info("handleRequest");

List<Word> words = wordDao.readAllOrderedByUsage();
List<Word> words = wordDao.readAllOrderedById();
logger.info("words.size(): " + words.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
Expand Down

0 comments on commit 2cad4d4

Please sign in to comment.