-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
website/admin: add basic queue and schedule handlers
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package admin | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
|
||
radio "github.com/R-a-dio/valkyrie" | ||
"github.com/R-a-dio/valkyrie/errors" | ||
"github.com/R-a-dio/valkyrie/website/middleware" | ||
"github.com/gorilla/csrf" | ||
) | ||
|
||
type QueueInput struct { | ||
middleware.Input | ||
CSRFTokenInput template.HTML | ||
|
||
Queue []radio.QueueEntry | ||
} | ||
|
||
func (QueueInput) TemplateBundle() string { | ||
return "queue" | ||
} | ||
|
||
// TODO: make this use radio.QueueService | ||
func NewQueueInput(qs radio.StreamerService, r *http.Request) (*QueueInput, error) { | ||
const op errors.Op = "website/admin.NewQueueInput" | ||
|
||
queue, err := qs.Queue(r.Context()) | ||
if err != nil { | ||
return nil, errors.E(op, err) | ||
} | ||
|
||
input := &QueueInput{ | ||
Input: middleware.InputFromRequest(r), | ||
CSRFTokenInput: csrf.TemplateField(r), | ||
Queue: queue, | ||
} | ||
return input, nil | ||
} | ||
|
||
func (s *State) GetQueue(w http.ResponseWriter, r *http.Request) { | ||
input, err := NewQueueInput(s.Conf().Streamer.Client(), r) | ||
if err != nil { | ||
s.errorHandler(w, r, err, "") | ||
return | ||
} | ||
|
||
err = s.TemplateExecutor.Execute(w, r, input) | ||
if err != nil { | ||
s.errorHandler(w, r, err, "") | ||
return | ||
} | ||
} |
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,50 @@ | ||
package admin | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
|
||
radio "github.com/R-a-dio/valkyrie" | ||
"github.com/R-a-dio/valkyrie/errors" | ||
"github.com/R-a-dio/valkyrie/website/middleware" | ||
"github.com/gorilla/csrf" | ||
) | ||
|
||
type ScheduleInput struct { | ||
middleware.Input | ||
CSRFTokenInput template.HTML | ||
|
||
Schedule []*radio.ScheduleEntry | ||
} | ||
|
||
func (ScheduleInput) TemplateBundle() string { | ||
return "schedule" | ||
} | ||
|
||
func NewScheduleInput(ss radio.ScheduleStorage, r *http.Request) (*ScheduleInput, error) { | ||
const op errors.Op = "website/admin.NewScheduleInput" | ||
schedule, err := ss.Latest() | ||
if err != nil { | ||
return nil, errors.E(op, err) | ||
} | ||
|
||
return &ScheduleInput{ | ||
Input: middleware.InputFromRequest(r), | ||
CSRFTokenInput: csrf.TemplateField(r), | ||
Schedule: schedule, | ||
}, nil | ||
} | ||
|
||
func (s *State) GetSchedule(w http.ResponseWriter, r *http.Request) { | ||
input, err := NewScheduleInput(s.Storage.Schedule(r.Context()), r) | ||
if err != nil { | ||
s.errorHandler(w, r, err, "") | ||
return | ||
} | ||
|
||
err = s.TemplateExecutor.Execute(w, r, input) | ||
if err != nil { | ||
s.errorHandler(w, r, err, "") | ||
return | ||
} | ||
} |