-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add website events integration
- Loading branch information
Showing
15 changed files
with
495 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,6 @@ logs/ | |
|
||
# DB | ||
*.db | ||
|
||
# UI Test file | ||
ui/screen/test.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE IF NOT EXISTS event ( | ||
id INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
date TIMESTAMP NOT NULL, | ||
academic_year TEXT NOT NULL, | ||
location TEXT NOT NULL | ||
); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE IF EXISTS event; | ||
-- +goose StatementEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- CRUD | ||
|
||
|
||
-- name: GetAllEvents :many | ||
SELECT * | ||
FROM event; | ||
|
||
-- name: CreateEvent :one | ||
INSERT INTO event (name, date, academic_year, location) | ||
VALUES (?, ?, ?, ?) | ||
RETURNING *; | ||
|
||
-- name: DeleteEvent :exec | ||
DELETE FROM event | ||
WHERE id = ?; | ||
|
||
|
||
-- Other | ||
|
||
|
||
-- name: GetEventByAcademicYear :many | ||
SELECT * | ||
FROM event | ||
WHERE academic_year = ?; | ||
|
||
-- name: DeleteEventByAcademicYear :exec | ||
DELETE FROM event | ||
WHERE academic_year = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/zeusWPI/scc/internal/pkg/db" | ||
"github.com/zeusWPI/scc/internal/pkg/event" | ||
"github.com/zeusWPI/scc/pkg/config" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// Event starts the event instance | ||
func Event(db *db.DB) (*event.Event, chan bool) { | ||
ev := event.New(db) | ||
done := make(chan bool) | ||
|
||
go eventPeriodicUpdate(ev, done) | ||
|
||
return ev, done | ||
} | ||
|
||
func eventPeriodicUpdate(ev *event.Event, done chan bool) { | ||
interval := config.GetDefaultInt("event.interval_s", 3600) | ||
zap.S().Info("EventL Starting periodic leaderboard update with an interval of ", interval, " seconds") | ||
|
||
ticker := time.NewTimer(time.Duration(interval) * time.Second) | ||
defer ticker.Stop() | ||
|
||
// Run immediatly once | ||
zap.S().Info("Event: Updating events") | ||
if err := ev.Update(); err != nil { | ||
zap.S().Error("Event: Error updating events\n", err) | ||
} | ||
|
||
for { | ||
select { | ||
case <-done: | ||
zap.S().Info("Event: Stopping periodic leaderboard update") | ||
return | ||
case <-ticker.C: | ||
// Update leaderboard | ||
zap.S().Info("Event: Updating events") | ||
if err := ev.Update(); err != nil { | ||
zap.S().Error("Event: Error updating events\n", err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.