89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/errcodes"
|
|
api "git.intra.yksa.space/gsn/gsn-proxy/pkg/rest"
|
|
)
|
|
|
|
var (
|
|
_ api.Handler = (*Handler)(nil)
|
|
)
|
|
|
|
type Handler struct {
|
|
svc Service
|
|
}
|
|
|
|
func New(svc Service) *Handler {
|
|
return &Handler{
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (h *Handler) GetSatellites(ctx context.Context) (*api.GetSatellitesOK, error) {
|
|
satellites, err := h.svc.GetSatellites(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ret := make([]api.GetSatellitesOKSatellitesItem, 0, len(satellites))
|
|
for _, val := range satellites {
|
|
ret = append(ret, api.GetSatellitesOKSatellitesItem{
|
|
ID: val.ID,
|
|
DisplayName: val.DisplayName,
|
|
Status: api.GetSatellitesOKSatellitesItemStatus(val.Status),
|
|
})
|
|
}
|
|
|
|
return &api.GetSatellitesOK{
|
|
Satellites: ret,
|
|
}, nil
|
|
}
|
|
|
|
func (h *Handler) GetStations(ctx context.Context) (*api.GetStationsOK, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (h *Handler) GetSubscriptions(ctx context.Context) (*api.GetSubscriptionsOK, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (h *Handler) SubscribeSatellite(ctx context.Context, req *api.SubscribeSatelliteReq) (*api.SubscribeSatelliteOK, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (h *Handler) SubscribeStation(ctx context.Context, req *api.SubscribeStationReq) (*api.SubscribeStationOK, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (h *Handler) Unsubscribe(ctx context.Context, params api.UnsubscribeParams) error {
|
|
return nil
|
|
}
|
|
|
|
func (h *Handler) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
|
|
if errcode, ok := err.(*errcodes.ErrorCode); ok {
|
|
resp := api.Error{
|
|
Message: errcode.Message,
|
|
}
|
|
|
|
if errcode.Details != "" {
|
|
resp.Details = api.NewOptString(errcode.Details)
|
|
}
|
|
|
|
return &api.ErrorStatusCode{
|
|
StatusCode: errcode.StatusCode,
|
|
Response: resp,
|
|
}
|
|
}
|
|
|
|
return &api.ErrorStatusCode{
|
|
StatusCode: http.StatusInternalServerError,
|
|
Response: api.Error{
|
|
Message: fmt.Sprintf("undefined internal error"),
|
|
Details: api.NewOptString(err.Error()),
|
|
},
|
|
}
|
|
}
|