aboutsummaryrefslogtreecommitdiffstats
path: root/api/handlers/schedule.go
blob: 061e6f9a2a593301240ada650e2619c4a055ea25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package handlers

import (
	"net/http"

	"github.com/LMBishop/confplanner/api/dto"
	"github.com/LMBishop/confplanner/pkg/schedule"
	"github.com/golang-cz/nilslice"
)

func GetSchedule(service schedule.Service) http.HandlerFunc {
	return dto.WrapResponseFunc(func(w http.ResponseWriter, r *http.Request) error {
		schedule, lastUpdated, err := service.GetSchedule()
		if err != nil {
			return err
		}

		return &dto.OkResponse{
			Code: http.StatusOK,
			Data: &dto.GetScheduleResponse{
				Schedule:    nilslice.Initialize(*schedule),
				LastUpdated: lastUpdated,
			},
		}
	})
}