Skip to content

Commit

Permalink
website: attempt to make schedule page work
Browse files Browse the repository at this point in the history
  • Loading branch information
icxes committed Mar 21, 2024
1 parent cb8c4f0 commit 6e5f7c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
7 changes: 4 additions & 3 deletions radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,15 +1076,16 @@ func (day ScheduleDay) String() string {
type ScheduleEntry struct {
ID ScheduleID
// Weekday is the day this entry is for
Weekday ScheduleDay
//Weekday ScheduleDay
Weekday int
// Text is the actual body of the entry
Text string
// Owner is who "owns" this day for streaming rights
Owner *User
User *User
// UpdatedAt is when this was updated
UpdatedAt time.Time
// UpdatedBy is who updated this
UpdatedBy User
// UpdatedBy User
// Notification indicates if we should notify users of this entry
Notification bool
}
31 changes: 29 additions & 2 deletions storage/mariadb/schedule.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package mariadb

import radio "github.com/R-a-dio/valkyrie"
import (
radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/errors"
"github.com/jmoiron/sqlx"
)

type ScheduleStorage struct {
handle handle
}

func (ss ScheduleStorage) Latest() ([]radio.ScheduleEntry, error) {
return nil, nil
const op errors.Op = "mariadb/ScheduleStorage.Latest"
handle, deferFn := ss.handle.span(op)
defer deferFn()

var query = `
SELECT
schedule.id AS id,
schedule.weekday AS weekday,
schedule.text AS text,
schedule.owner AS 'user.id',
schedule.updated_at AS updated_at,
schedule.notification AS notification
FROM
schedule
`

var schedule []radio.ScheduleEntry

err := sqlx.Select(handle, &schedule, query)
if err != nil {
return nil, errors.E(op, err)
}

return schedule, nil
}

func (ss ScheduleStorage) Update(entry radio.ScheduleEntry) error {
Expand Down
28 changes: 17 additions & 11 deletions website/public/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ package public
import (
"net/http"

"github.com/R-a-dio/valkyrie/errors"
radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/website/middleware"
)

type ScheduleInput struct {
middleware.Input

Schedule []radio.ScheduleEntry
}

func NewScheduleInput(r *http.Request) ScheduleInput {
return ScheduleInput{
Input: middleware.InputFromRequest(r),
func NewScheduleInput(ss radio.ScheduleStorageService, r *http.Request) (*ScheduleInput, error) {
schedule, err := ss.Schedule(r.Context()).Latest()
if err != nil {
return nil, err
}

return &ScheduleInput{
Input: middleware.InputFromRequest(r),
Schedule: schedule,
}, nil
}

func (ScheduleInput) TemplateBundle() string {
Expand All @@ -30,13 +38,11 @@ func (s State) GetSchedule(w http.ResponseWriter, r *http.Request) {
}

func (s State) getSchedule(w http.ResponseWriter, r *http.Request) error {
const op errors.Op = "website/public.getSchedule"

input := NewScheduleInput(r)

err := s.Templates.Execute(w, r, input)
input, err := NewScheduleInput(s.Storage, r)
if err != nil {
return errors.E(op, err)
s.errorHandler(w, r, err)
return err
}
return nil

return s.Templates.Execute(w, r, input)
}

0 comments on commit 6e5f7c3

Please sign in to comment.