Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/services/jurorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const jurorService = {

getRoundVotesStats: (id) => apiBackend.get(`juror/round/${id}/votes-stats`),

getCampaignFaves: (campaignId) => apiBackend.get(`juror/campaign/${campaignId}/favorites`),

faveImage: (roundId, entryId) => apiBackend.post(`juror/round/${roundId}/${entryId}/fave`, {}),

unfaveImage: (roundId, entryId) =>
Expand Down
5 changes: 5 additions & 0 deletions montage/juror_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ def skip_rating(user_dao, round_id, request, request_dict):
juror_dao.skip_voting(vote_id, round_id)
return {'data': {'success': True}}

def get_campaign_favorites(user_dao, campaign_id):
juror_dao = JurorDAO(user_dao)
faves = juror_dao.get_campaign_favorites(campaign_id)
return [f.to_details_dict() for f in faves]


def submit_fave(user_dao, round_id, entry_id):
juror_dao = JurorDAO(user_dao)
Expand Down
19 changes: 16 additions & 3 deletions montage/rdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

MAINTAINERS = [
'MahmoudHashemi', 'Slaporte', 'Yarl', 'LilyOfTheWest',
'Jayprakash12345', 'Ciell', 'Effeietsanders'
'Jayprakash12345', 'Ciell', 'Effeietsanders',
]

"""
Expand Down Expand Up @@ -2869,21 +2869,33 @@ def apply_ranking(self, ballot):
vote.status = COMPLETED_STATUS
self.rdb_session.add(vote)
return

def get_campaign_favorites(self, campaign_id):
return (
self.query(Favorite).filter(
Favorite.campaign_id == campaign_id,
Favorite.user == self.user,
Favorite.status == ACTIVE_STATUS
).all()
)

def fave(self, round_id, entry_id):
round_entry = self.get_round_entry(round_id, entry_id)
campaign_id = round_entry.round.campaign.id

existing_fave = (self.query(Favorite)
.filter_by(entry_id=entry_id,
campaign_id=campaign_id,
user=self.user)
.first()) # there should be one
if existing_fave:
existing_fave.modified_date = datetime.datetime.utcnow()
existing_fave.status = ACTIVE_STATUS
return

round_entry = self.get_round_entry(round_id, entry_id)
fave = Favorite(entry_id=round_entry.entry.id,
round_entry_id = round_entry.id,
campaign_id=round_entry.round.campaign.id,
campaign_id=campaign_id,
user=self.user,
status=ACTIVE_STATUS)
self.rdb_session.add(fave)
Expand All @@ -2893,6 +2905,7 @@ def unfave(self, round_id, entry_id):
.join(RoundEntry, RoundEntry.id == Favorite.round_entry_id)
.filter(Favorite.entry_id == entry_id,
Favorite.user == self.user,
Favorite.status == ACTIVE_STATUS,
RoundEntry.round_id == round_id)
.one())
fave.status = CANCELLED_STATUS
Expand Down