Skip to content

Commit

Permalink
refactor(dao): LetterSoundPeerReviewEvent
Browse files Browse the repository at this point in the history
refs #1677
  • Loading branch information
jo-elimu committed Jul 13, 2024
1 parent 65755f1 commit 4a0525f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/main/java/ai/elimu/dao/LetterSoundPeerReviewEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.List;
import org.springframework.dao.DataAccessException;

public interface LetterSoundPeerReviewEventDao extends GenericDao<LetterSoundCorrespondencePeerReviewEvent> {
public interface LetterSoundPeerReviewEventDao extends GenericDao<LetterSoundPeerReviewEvent> {

List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException;

List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondence letterSoundCorrespondence) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondence letterSoundCorrespondence) throws DataAccessException;

List<LetterSoundCorrespondencePeerReviewEvent> readAll(Contributor contributor) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(Contributor contributor) throws DataAccessException;

List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException;

Long readCount(Contributor contributor) throws DataAccessException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.List;
import org.springframework.dao.DataAccessException;

public class LetterSoundPeerReviewEventDaoJpa extends GenericDaoJpa<LetterSoundCorrespondencePeerReviewEvent> implements LetterSoundPeerReviewEventDao {
public class LetterSoundPeerReviewEventDaoJpa extends GenericDaoJpa<LetterSoundPeerReviewEvent> implements LetterSoundPeerReviewEventDao {

@Override
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
"FROM LetterSoundPeerReviewEvent event " +
"WHERE event.letterSoundContributionEvent = :letterSoundContributionEvent " +
"AND event.contributor = :contributor " +
"ORDER BY event.time DESC")
Expand All @@ -24,32 +24,32 @@ public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorresp
}

@Override
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
"FROM LetterSoundPeerReviewEvent event " +
"WHERE event.letterSoundContributionEvent.letterSound = :letterSound " +
"ORDER BY event.time DESC")
.setParameter("letterSound", letterSound)
.getResultList();
}

@Override
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(Contributor contributor) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(Contributor contributor) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
"FROM LetterSoundPeerReviewEvent event " +
"WHERE event.contributor = :contributor " +
"ORDER BY event.time DESC")
.setParameter("contributor", contributor)
.getResultList();
}

@Override
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
"FROM LetterSoundPeerReviewEvent event " +
"WHERE event.letterSoundContributionEvent = :letterSoundContributionEvent " +
"ORDER BY event.time DESC")
.setParameter("letterSoundContributionEvent", letterSoundContributionEvent)
Expand All @@ -59,7 +59,7 @@ public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorresp
@Override
public Long readCount(Contributor contributor) throws DataAccessException {
return (Long) em.createQuery("SELECT COUNT(event) " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
"FROM LetterSoundPeerReviewEvent event " +
"WHERE event.contributor = :contributor")
.setParameter("contributor", contributor)
.getSingleResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* was added/edited by another {@link Contributor}.
*/
@Entity
public class LetterSoundCorrespondencePeerReviewEvent extends PeerReviewEvent {
public class LetterSoundPeerReviewEvent extends PeerReviewEvent {

/**
* The contribution event which is being peer-reviewed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ai.elimu.dao.LetterSoundPeerReviewEventDao;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class LetterSoundPeerReviewsController {
private EmojiDao emojiDao;

/**
* Get {@link LetterSoundCorrespondenceContributionEvent}s pending a {@link LetterSoundCorrespondencePeerReviewEvent} for the current {@link Contributor}.
* Get {@link LetterSoundCorrespondenceContributionEvent}s pending a {@link LetterSoundPeerReviewEvent} for the current {@link Contributor}.
*/
@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpSession session, Model model) {
Expand All @@ -60,7 +60,7 @@ public String handleGetRequest(HttpSession session, Model model) {
}

// Check if the current Contributor has already peer-reviewed this LetterSoundCorrespondence contribution
List<LetterSoundCorrespondencePeerReviewEvent> letterSoundPeerReviewEvents = letterSoundPeerReviewEventDao.readAll(mostRecentLetterSoundContributionEvent, contributor);
List<LetterSoundPeerReviewEvent> letterSoundPeerReviewEvents = letterSoundPeerReviewEventDao.readAll(mostRecentLetterSoundContributionEvent, contributor);
if (letterSoundPeerReviewEvents.isEmpty()) {
letterSoundContributionEventsPendingPeerReview.add(mostRecentLetterSoundContributionEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ai.elimu.model.contributor.Contributor;
import org.apache.logging.log4j.Logger;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import ai.elimu.model.enums.PeerReviewStatus;
import ai.elimu.util.DiscordHelper;
import ai.elimu.web.context.EnvironmentContextLoaderListener;
Expand Down Expand Up @@ -54,7 +54,7 @@ public String handleSubmit(
logger.info("letterSoundContributionEvent: " + letterSoundContributionEvent);

// Store the peer review event
LetterSoundCorrespondencePeerReviewEvent letterSoundPeerReviewEvent = new LetterSoundCorrespondencePeerReviewEvent();
LetterSoundPeerReviewEvent letterSoundPeerReviewEvent = new LetterSoundPeerReviewEvent();
letterSoundPeerReviewEvent.setContributor(contributor);
letterSoundPeerReviewEvent.setLetterSoundContributionEvent(letterSoundContributionEvent);
letterSoundPeerReviewEvent.setApproved(approved);
Expand All @@ -76,7 +76,7 @@ public String handleSubmit(
// Update the peer review status
int approvedCount = 0;
int notApprovedCount = 0;
for (LetterSoundCorrespondencePeerReviewEvent peerReviewEvent : letterSoundPeerReviewEventDao.readAll(letterSoundContributionEvent)) {
for (LetterSoundPeerReviewEvent peerReviewEvent : letterSoundPeerReviewEventDao.readAll(letterSoundContributionEvent)) {
if (peerReviewEvent.isApproved()) {
approvedCount++;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/META-INF/jpa-schema-export.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

drop table if exists LetterSoundCorrespondenceContributionEvent;

drop table if exists LetterSoundCorrespondencePeerReviewEvent;
drop table if exists LetterSoundPeerReviewEvent;

drop table if exists Number;

Expand Down Expand Up @@ -410,7 +410,7 @@
primary key (id)
) engine=MyISAM;

create table LetterSoundCorrespondencePeerReviewEvent (
create table LetterSoundPeerReviewEvent (
id bigint not null auto_increment,
approved bit,
comment varchar(1000),
Expand Down Expand Up @@ -907,13 +907,13 @@
foreign key (letterSound_id)
references LetterSoundCorrespondence (id);

alter table LetterSoundCorrespondencePeerReviewEvent
add constraint FKnx18la2q9jr95bmprkttiymxc
alter table LetterSoundPeerReviewEvent
add constraint FK3wapf4y5anhgnjbqna2qjyie4
foreign key (contributor_id)
references Contributor (id);

alter table LetterSoundCorrespondencePeerReviewEvent
add constraint FKff8dsceebikiyr8csxbxn6ml0
alter table LetterSoundPeerReviewEvent
add constraint FK4ec0wl5mmi2uh5sg7ll20dyjk
foreign key (letterSoundContributionEvent_id)
references LetterSoundCorrespondenceContributionEvent (id);

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/db/migration/2004010.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 2.4.10

# "LetterSoundCorrespondencePeerReviewEvent" → "LetterSoundPeerReviewEvent"
DROP TABLE `LetterSoundPeerReviewEvent`;
ALTER TABLE `LetterSoundCorrespondencePeerReviewEvent` RENAME `LetterSoundPeerReviewEvent`;

0 comments on commit 4a0525f

Please sign in to comment.