-
Notifications
You must be signed in to change notification settings - Fork 0
/
donations-grpc.go
45 lines (37 loc) · 1.07 KB
/
donations-grpc.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package goautowp
import (
"context"
"github.com/autowp/goautowp/itemofday"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
)
type DonationsGRPCServer struct {
UnimplementedDonationsServer
itemOfDay *itemofday.Repository
donationsVodPrice int32
}
func NewDonationsGRPCServer(itemOfDay *itemofday.Repository, donationsVodPrice int32) *DonationsGRPCServer {
return &DonationsGRPCServer{
itemOfDay: itemOfDay,
donationsVodPrice: donationsVodPrice,
}
}
func (s *DonationsGRPCServer) GetVODData(ctx context.Context, _ *emptypb.Empty) (*VODDataResponse, error) {
dates := make([]*VODDataDate, 0)
nextDates, err := s.itemOfDay.NextDates(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
for _, nextDate := range nextDates {
dates = append(dates, &VODDataDate{
Date: timestamppb.New(nextDate.Date),
Free: nextDate.Free,
})
}
return &VODDataResponse{
Dates: dates,
Sum: s.donationsVodPrice,
}, nil
}