feat: it works
This commit is contained in:
parent
6302dd62d6
commit
778d5ef146
25 changed files with 638 additions and 106 deletions
11
internal/transport/rest/handler/deps.go
Normal file
11
internal/transport/rest/handler/deps.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/ds"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetSatellites(ctx context.Context) ([]ds.Satellite, error)
|
||||
}
|
||||
89
internal/transport/rest/handler/handler.go
Normal file
89
internal/transport/rest/handler/handler.go
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
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()),
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue