about summary refs log tree commit diff
path: root/src/db
diff options
context:
space:
mode:
authorhanemile <mail@emile.space>2020-07-19 13:10:44 +0200
committerhanemile <mail@emile.space>2020-07-19 13:10:44 +0200
commitfa7cc403aaf9cfc61a54cbbc132c361965e747ae (patch)
tree0a40f270f7f7dcf75055ff5b31fa20e993a582a1 /src/db
parentfc63adf55849f748a37cef4c425a19a1c0f0e76e (diff)
past talks can now be seen
Diffstat (limited to 'src/db')
-rw-r--r--src/db/go.mod1
-rw-r--r--src/db/go.sum3
-rw-r--r--src/db/talk.go39
3 files changed, 40 insertions, 3 deletions
diff --git a/src/db/go.mod b/src/db/go.mod
index 4e70ab6..64c66b8 100644
--- a/src/db/go.mod
+++ b/src/db/go.mod
@@ -3,6 +3,7 @@ module git.darknebu.la/chaosdorf/freitagsfoo/src/db
 go 1.13
 
 require (
+	git.darknebu.la/chaosdorf/freitagsfoo/src/structs v0.0.0-20200718235609-fc63adf55849
 	github.com/go-pg/pg/v9 v9.1.6
 	github.com/google/uuid v1.1.1
 	github.com/sirupsen/logrus v1.6.0
diff --git a/src/db/go.sum b/src/db/go.sum
index eb7a67e..e0d640e 100644
--- a/src/db/go.sum
+++ b/src/db/go.sum
@@ -11,6 +11,9 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl
 cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
 cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+git.darknebu.la/chaosdorf/freitagsfoo v0.0.0-20200718235609-fc63adf55849 h1:xI4zrY9O8OoR7ais9O+b+ntKoKi4Ln4mb2iUys/e66k=
+git.darknebu.la/chaosdorf/freitagsfoo/src/structs v0.0.0-20200718235609-fc63adf55849 h1:dkaulG2hAwns3QvFwFQEq2DVhiRsGPKvDmV5VrI3sfQ=
+git.darknebu.la/chaosdorf/freitagsfoo/src/structs v0.0.0-20200718235609-fc63adf55849/go.mod h1:dxRyc1J0ktxxbrlUpd3Uujtx+KgGGidcIpfFBT5ftBc=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
diff --git a/src/db/talk.go b/src/db/talk.go
index c286aa8..9693d0c 100644
--- a/src/db/talk.go
+++ b/src/db/talk.go
@@ -2,6 +2,7 @@ package db
 
 import (
 	"fmt"
+	"time"
 
 	"git.darknebu.la/chaosdorf/freitagsfoo/src/structs"
 	pg "github.com/go-pg/pg/v9"
@@ -21,7 +22,7 @@ func InsertTalk(db *pg.DB, talk *structs.Talk) error {
 // UpcomingTalksLimited returns the next 3 upcoming talks
 func UpcomingTalksLimited(db *pg.DB) ([]structs.Talk, error) {
 	var talks []structs.Talk
-	err := db.Model(&talks).Order("id DESC").Limit(3).Select()
+	err := db.Model(&talks).Order("date DESC").Where("date > ?", time.Now()).Limit(3).Select()
 	if err != nil {
 		return []structs.Talk{}, fmt.Errorf("could not get the talks from the db: %s", err)
 	}
@@ -32,7 +33,29 @@ func UpcomingTalksLimited(db *pg.DB) ([]structs.Talk, error) {
 // UpcomingTalks returns the next upcoming talks
 func UpcomingTalks(db *pg.DB) ([]structs.Talk, error) {
 	var talks []structs.Talk
-	err := db.Model(&talks).Order("id DESC").Select()
+	err := db.Model(&talks).Order("date DESC").Where("date > ?", time.Now()).Select()
+	if err != nil {
+		return []structs.Talk{}, fmt.Errorf("could not get the talks from the db: %s", err)
+	}
+
+	return talks, nil
+}
+
+// PastTalksLimited returns the past 3 talks
+func PastTalksLimited(db *pg.DB) ([]structs.Talk, error) {
+	var talks []structs.Talk
+	err := db.Model(&talks).Order("date DESC").Where("date < ?", time.Now()).Limit(3).Select()
+	if err != nil {
+		return []structs.Talk{}, fmt.Errorf("could not get the talks from the db: %s", err)
+	}
+
+	return talks, nil
+}
+
+// PastTalks returns the next upcoming talks
+func PastTalks(db *pg.DB) ([]structs.Talk, error) {
+	var talks []structs.Talk
+	err := db.Model(&talks).Order("date DESC").Where("date < ?", time.Now()).Select()
 	if err != nil {
 		return []structs.Talk{}, fmt.Errorf("could not get the talks from the db: %s", err)
 	}
@@ -42,9 +65,19 @@ func UpcomingTalks(db *pg.DB) ([]structs.Talk, error) {
 
 // CountUpcomingTalks counts the amount of talks upcoming
 func CountUpcomingTalks(db *pg.DB) (int, error) {
+	var talks []structs.Talk
+	count, err := db.Model(&talks).Where("date > ?", time.Now()).Where("upcoming = ?", true).SelectAndCount()
+	if err != nil {
+		return -1, fmt.Errorf("could not get the talks from the db: %s", err)
+	}
+
+	return count, nil
+}
 
+// CountPastTalks counts the amount of past talks
+func CountPastTalks(db *pg.DB) (int, error) {
 	var talks []structs.Talk
-	count, err := db.Model(&talks).Where("upcoming = ?", true).SelectAndCount()
+	count, err := db.Model(&talks).Where("date < ?", time.Now()).SelectAndCount()
 	if err != nil {
 		return -1, fmt.Errorf("could not get the talks from the db: %s", err)
 	}