Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
event attendees are now sorted by when they RSVP'd
Browse files Browse the repository at this point in the history
  • Loading branch information
jgayfer committed Aug 7, 2017
1 parent 0a25dbd commit a294f99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased
### Changed
- Events are now sorted by their start time
- Events are now sorted in the events channel by their start time
- Event attendees are now sorted by when they RSVP'd

## [0.2.0] - 2017-08-02
### Added
Expand Down
2 changes: 1 addition & 1 deletion cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def set_attendance(self, username, server_id, attending, title, message):
"""Send updated event attendance info to db and update the event"""
with DBase() as db:
db.add_user(server_id, username)
db.update_attendance(username, server_id, attending, title)
db.update_attendance(username, server_id, attending, title, datetime.now())

# Update event message in place for a more seamless user experience
with DBase() as db:
Expand Down
18 changes: 9 additions & 9 deletions db/dbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def create_event(self, title, start_time, time_zone, server_id, description):
def get_events(self, server_id):
sql = """
SELECT title as e, description, start_time, time_zone, (
SELECT GROUP_CONCAT(DISTINCT username)
SELECT GROUP_CONCAT(DISTINCT username ORDER BY last_updated)
FROM user_event
WHERE user_event.server_id = %s
AND user_event.title = e
AND user_event.attending = 1)
AS accepted, (
SELECT GROUP_CONCAT(DISTINCT username)
SELECT GROUP_CONCAT(DISTINCT username ORDER BY last_updated)
FROM user_event
WHERE user_event.server_id = %s
AND user_event.title = e
Expand All @@ -79,25 +79,25 @@ def get_events(self, server_id):
self.cur.execute(sql, (server_id, server_id, server_id))
return self.cur.fetchall()

def update_attendance(self, username, server_id, attending, title):
def update_attendance(self, username, server_id, attending, title, last_updated):
sql = """
INSERT INTO user_event (username, server_id, title, attending)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE attending = %s;
INSERT INTO user_event (username, server_id, title, attending, last_updated)
VALUES (%s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE attending = %s, last_updated = %s;
"""
self.cur.execute(sql, (username, server_id, title, attending, attending))
self.cur.execute(sql, (username, server_id, title, attending, last_updated, attending, last_updated))
self.conn.commit()

def get_event(self, server_id, title):
sql = """
SELECT title, description, start_time, time_zone, (
SELECT GROUP_CONCAT(DISTINCT username)
SELECT GROUP_CONCAT(DISTINCT username ORDER BY last_updated)
FROM user_event
WHERE user_event.server_id = %s
AND user_event.title = %s
AND user_event.attending = 1)
AS accepted, (
SELECT GROUP_CONCAT(DISTINCT username)
SELECT GROUP_CONCAT(DISTINCT username ORDER BY last_updated)
FROM user_event
WHERE user_event.server_id = %s
AND user_event.title = %s
Expand Down
1 change: 1 addition & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CREATE TABLE user_event (
server_id VARCHAR(40) NOT NULL,
title VARCHAR(256) NOT NULL,
attending BOOLEAN NOT NULL,
last_updated DATETIME NOT NULL,
PRIMARY KEY (username, server_id, title),
FOREIGN KEY (server_id, title) REFERENCES events(server_id, title)
ON DELETE CASCADE,
Expand Down

0 comments on commit a294f99

Please sign in to comment.