HW13 WIP 010

pull/14/head
Andrey Ivanov 2020-10-12 17:19:04 +03:00 committed by tiburon
parent 19b81ab02a
commit 2ae42a6b0f
6 changed files with 518 additions and 207 deletions

View File

@ -5,14 +5,16 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec
github.com/dmitryt/otus-golang-hw/hw12_13_14_15_calendar v0.0.0-20200916093948-5ca8860569b6
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2
github.com/grpc-ecosystem/grpc-gateway v1.15.0
github.com/stretchr/testify v1.4.0
github.com/rs/zerolog v1.20.0
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.15.0 // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344
golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/genproto v0.0.0-20200815001618-f69a88009b70
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect

View File

@ -8,27 +8,30 @@ import (
)
type Config struct {
Server struct {
Server Server
Grpc Server
Logger Logger
Storage Storage
}
type Server struct {
Address string
Port string
}
Grpc struct {
Address string
Port string
}
Logger struct {
}
type Logger struct {
File string
Level string
MuteStdout bool
}
Storage struct {
}
type Storage struct {
InMemory bool
SQLHost string
SQLPort string
SQLDbase string
SQLUser string
SQLPass string
}
}
// Confita может быти и хороша, но она не возвращает ошибки, если не может распарсить файл в структуру. Мне не нравится такая "молчаливость".

View File

@ -7,7 +7,7 @@ import (
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
)
func pbevent2event(pbe *Event) (res event.Event, err error) {
func (s Service) buildStorageEvent (pbe *CreateReq) (res event.Event, err error) {
res = event.Event{Title: pbe.Title, Note: pbe.Note, UserID: pbe.UserID}
res.Date, err = ptypes.Timestamp(pbe.Date)
if err != nil {
@ -24,7 +24,7 @@ func pbevent2event(pbe *Event) (res event.Event, err error) {
return res, nil
}
func pbeventWitID2eventAndID(pbe *EventWthID) (id event.ID, evt event.Event, err error) {
func (s Service) buildStorageEventAndID(pbe *UpdateReq) (id event.ID, evt event.Event, err error) {
evt = event.Event{Title: pbe.Event.Title, Note: pbe.Event.Note, UserID: pbe.Event.UserID}
evt.Date, err = ptypes.Timestamp(pbe.Event.Date)
if err != nil {
@ -41,8 +41,9 @@ func pbeventWitID2eventAndID(pbe *EventWthID) (id event.ID, evt event.Event, err
return event.ID(pbe.ID), evt, nil
}
func evtMap2pbEventList(evtMap map[event.ID]event.Event) (*EventList, error) {
var events = &EventList{}
func (s Service) buildEventList(evtMap map[event.ID]event.Event) ([]*Event, error) {
var events = []*Event{}
var err error
for k, v := range evtMap {
evt := Event{ID: int64(k), Title: v.Title, Latency: ptypes.DurationProto(v.Latency), Note: v.Note, UserID: v.UserID, NotifyTime: ptypes.DurationProto(v.NotifyTime)}
@ -50,12 +51,12 @@ func evtMap2pbEventList(evtMap map[event.ID]event.Event) (*EventList, error) {
if err != nil {
return nil, err
}
events.Events = append(events.Events, &evt)
events = append(events, &evt)
}
return events, err
}
func pbDate2Time(e *Date) (start time.Time, qrange string, err error) {
func (s Service) buildTimeAndRange(e *GetByDateReq) (start time.Time, qrange string, err error) {
date, err := ptypes.Timestamp(e.Date)
return date, string(e.Range), err
}

View File

@ -10,7 +10,6 @@ import (
duration "github.com/golang/protobuf/ptypes/duration"
empty "github.com/golang/protobuf/ptypes/empty"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
_ "google.golang.org/genproto/googleapis/api/annotations"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@ -143,85 +142,125 @@ func (m *Event) GetNotifyTime() *duration.Duration {
return nil
}
type EventList struct {
Events []*Event `protobuf:"bytes,1,rep,name=Events,proto3" json:"Events,omitempty"`
type CreateReq struct {
Title string `protobuf:"bytes,2,opt,name=Title,proto3" json:"Title,omitempty"`
Date *timestamp.Timestamp `protobuf:"bytes,3,opt,name=Date,proto3" json:"Date,omitempty"`
Latency *duration.Duration `protobuf:"bytes,4,opt,name=Latency,proto3" json:"Latency,omitempty"`
Note string `protobuf:"bytes,5,opt,name=Note,proto3" json:"Note,omitempty"`
UserID int64 `protobuf:"varint,6,opt,name=UserID,proto3" json:"UserID,omitempty"`
NotifyTime *duration.Duration `protobuf:"bytes,7,opt,name=NotifyTime,proto3" json:"NotifyTime,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventList) Reset() { *m = EventList{} }
func (m *EventList) String() string { return proto.CompactTextString(m) }
func (*EventList) ProtoMessage() {}
func (*EventList) Descriptor() ([]byte, []int) {
func (m *CreateReq) Reset() { *m = CreateReq{} }
func (m *CreateReq) String() string { return proto.CompactTextString(m) }
func (*CreateReq) ProtoMessage() {}
func (*CreateReq) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{1}
}
func (m *EventList) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventList.Unmarshal(m, b)
func (m *CreateReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CreateReq.Unmarshal(m, b)
}
func (m *EventList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventList.Marshal(b, m, deterministic)
func (m *CreateReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CreateReq.Marshal(b, m, deterministic)
}
func (m *EventList) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventList.Merge(m, src)
func (m *CreateReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_CreateReq.Merge(m, src)
}
func (m *EventList) XXX_Size() int {
return xxx_messageInfo_EventList.Size(m)
func (m *CreateReq) XXX_Size() int {
return xxx_messageInfo_CreateReq.Size(m)
}
func (m *EventList) XXX_DiscardUnknown() {
xxx_messageInfo_EventList.DiscardUnknown(m)
func (m *CreateReq) XXX_DiscardUnknown() {
xxx_messageInfo_CreateReq.DiscardUnknown(m)
}
var xxx_messageInfo_EventList proto.InternalMessageInfo
var xxx_messageInfo_CreateReq proto.InternalMessageInfo
func (m *EventList) GetEvents() []*Event {
func (m *CreateReq) GetTitle() string {
if m != nil {
return m.Events
return m.Title
}
return ""
}
func (m *CreateReq) GetDate() *timestamp.Timestamp {
if m != nil {
return m.Date
}
return nil
}
type EventID struct {
func (m *CreateReq) GetLatency() *duration.Duration {
if m != nil {
return m.Latency
}
return nil
}
func (m *CreateReq) GetNote() string {
if m != nil {
return m.Note
}
return ""
}
func (m *CreateReq) GetUserID() int64 {
if m != nil {
return m.UserID
}
return 0
}
func (m *CreateReq) GetNotifyTime() *duration.Duration {
if m != nil {
return m.NotifyTime
}
return nil
}
type CreateRsp struct {
ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventID) Reset() { *m = EventID{} }
func (m *EventID) String() string { return proto.CompactTextString(m) }
func (*EventID) ProtoMessage() {}
func (*EventID) Descriptor() ([]byte, []int) {
func (m *CreateRsp) Reset() { *m = CreateRsp{} }
func (m *CreateRsp) String() string { return proto.CompactTextString(m) }
func (*CreateRsp) ProtoMessage() {}
func (*CreateRsp) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{2}
}
func (m *EventID) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventID.Unmarshal(m, b)
func (m *CreateRsp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CreateRsp.Unmarshal(m, b)
}
func (m *EventID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventID.Marshal(b, m, deterministic)
func (m *CreateRsp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CreateRsp.Marshal(b, m, deterministic)
}
func (m *EventID) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventID.Merge(m, src)
func (m *CreateRsp) XXX_Merge(src proto.Message) {
xxx_messageInfo_CreateRsp.Merge(m, src)
}
func (m *EventID) XXX_Size() int {
return xxx_messageInfo_EventID.Size(m)
func (m *CreateRsp) XXX_Size() int {
return xxx_messageInfo_CreateRsp.Size(m)
}
func (m *EventID) XXX_DiscardUnknown() {
xxx_messageInfo_EventID.DiscardUnknown(m)
func (m *CreateRsp) XXX_DiscardUnknown() {
xxx_messageInfo_CreateRsp.DiscardUnknown(m)
}
var xxx_messageInfo_EventID proto.InternalMessageInfo
var xxx_messageInfo_CreateRsp proto.InternalMessageInfo
func (m *EventID) GetID() int64 {
func (m *CreateRsp) GetID() int64 {
if m != nil {
return m.ID
}
return 0
}
type EventWthID struct {
type UpdateReq struct {
ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
Event *Event `protobuf:"bytes,2,opt,name=Event,proto3" json:"Event,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -229,46 +268,202 @@ type EventWthID struct {
XXX_sizecache int32 `json:"-"`
}
func (m *EventWthID) Reset() { *m = EventWthID{} }
func (m *EventWthID) String() string { return proto.CompactTextString(m) }
func (*EventWthID) ProtoMessage() {}
func (*EventWthID) Descriptor() ([]byte, []int) {
func (m *UpdateReq) Reset() { *m = UpdateReq{} }
func (m *UpdateReq) String() string { return proto.CompactTextString(m) }
func (*UpdateReq) ProtoMessage() {}
func (*UpdateReq) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{3}
}
func (m *EventWthID) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventWthID.Unmarshal(m, b)
func (m *UpdateReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UpdateReq.Unmarshal(m, b)
}
func (m *EventWthID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventWthID.Marshal(b, m, deterministic)
func (m *UpdateReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UpdateReq.Marshal(b, m, deterministic)
}
func (m *EventWthID) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventWthID.Merge(m, src)
func (m *UpdateReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_UpdateReq.Merge(m, src)
}
func (m *EventWthID) XXX_Size() int {
return xxx_messageInfo_EventWthID.Size(m)
func (m *UpdateReq) XXX_Size() int {
return xxx_messageInfo_UpdateReq.Size(m)
}
func (m *EventWthID) XXX_DiscardUnknown() {
xxx_messageInfo_EventWthID.DiscardUnknown(m)
func (m *UpdateReq) XXX_DiscardUnknown() {
xxx_messageInfo_UpdateReq.DiscardUnknown(m)
}
var xxx_messageInfo_EventWthID proto.InternalMessageInfo
var xxx_messageInfo_UpdateReq proto.InternalMessageInfo
func (m *EventWthID) GetID() int64 {
func (m *UpdateReq) GetID() int64 {
if m != nil {
return m.ID
}
return 0
}
func (m *EventWthID) GetEvent() *Event {
func (m *UpdateReq) GetEvent() *Event {
if m != nil {
return m.Event
}
return nil
}
type Date struct {
type DeleteReq struct {
ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *DeleteReq) Reset() { *m = DeleteReq{} }
func (m *DeleteReq) String() string { return proto.CompactTextString(m) }
func (*DeleteReq) ProtoMessage() {}
func (*DeleteReq) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{4}
}
func (m *DeleteReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_DeleteReq.Unmarshal(m, b)
}
func (m *DeleteReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_DeleteReq.Marshal(b, m, deterministic)
}
func (m *DeleteReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_DeleteReq.Merge(m, src)
}
func (m *DeleteReq) XXX_Size() int {
return xxx_messageInfo_DeleteReq.Size(m)
}
func (m *DeleteReq) XXX_DiscardUnknown() {
xxx_messageInfo_DeleteReq.DiscardUnknown(m)
}
var xxx_messageInfo_DeleteReq proto.InternalMessageInfo
func (m *DeleteReq) GetID() int64 {
if m != nil {
return m.ID
}
return 0
}
type ListResp struct {
Events []*Event `protobuf:"bytes,1,rep,name=Events,proto3" json:"Events,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ListResp) Reset() { *m = ListResp{} }
func (m *ListResp) String() string { return proto.CompactTextString(m) }
func (*ListResp) ProtoMessage() {}
func (*ListResp) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{5}
}
func (m *ListResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ListResp.Unmarshal(m, b)
}
func (m *ListResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ListResp.Marshal(b, m, deterministic)
}
func (m *ListResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_ListResp.Merge(m, src)
}
func (m *ListResp) XXX_Size() int {
return xxx_messageInfo_ListResp.Size(m)
}
func (m *ListResp) XXX_DiscardUnknown() {
xxx_messageInfo_ListResp.DiscardUnknown(m)
}
var xxx_messageInfo_ListResp proto.InternalMessageInfo
func (m *ListResp) GetEvents() []*Event {
if m != nil {
return m.Events
}
return nil
}
type GetByIDReq struct {
ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetByIDReq) Reset() { *m = GetByIDReq{} }
func (m *GetByIDReq) String() string { return proto.CompactTextString(m) }
func (*GetByIDReq) ProtoMessage() {}
func (*GetByIDReq) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{6}
}
func (m *GetByIDReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetByIDReq.Unmarshal(m, b)
}
func (m *GetByIDReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetByIDReq.Marshal(b, m, deterministic)
}
func (m *GetByIDReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetByIDReq.Merge(m, src)
}
func (m *GetByIDReq) XXX_Size() int {
return xxx_messageInfo_GetByIDReq.Size(m)
}
func (m *GetByIDReq) XXX_DiscardUnknown() {
xxx_messageInfo_GetByIDReq.DiscardUnknown(m)
}
var xxx_messageInfo_GetByIDReq proto.InternalMessageInfo
func (m *GetByIDReq) GetID() int64 {
if m != nil {
return m.ID
}
return 0
}
type GetByIDResp struct {
Events []*Event `protobuf:"bytes,1,rep,name=Events,proto3" json:"Events,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetByIDResp) Reset() { *m = GetByIDResp{} }
func (m *GetByIDResp) String() string { return proto.CompactTextString(m) }
func (*GetByIDResp) ProtoMessage() {}
func (*GetByIDResp) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{7}
}
func (m *GetByIDResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetByIDResp.Unmarshal(m, b)
}
func (m *GetByIDResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetByIDResp.Marshal(b, m, deterministic)
}
func (m *GetByIDResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetByIDResp.Merge(m, src)
}
func (m *GetByIDResp) XXX_Size() int {
return xxx_messageInfo_GetByIDResp.Size(m)
}
func (m *GetByIDResp) XXX_DiscardUnknown() {
xxx_messageInfo_GetByIDResp.DiscardUnknown(m)
}
var xxx_messageInfo_GetByIDResp proto.InternalMessageInfo
func (m *GetByIDResp) GetEvents() []*Event {
if m != nil {
return m.Events
}
return nil
}
type GetByDateReq struct {
Date *timestamp.Timestamp `protobuf:"bytes,1,opt,name=Date,proto3" json:"Date,omitempty"`
Range QueryRange `protobuf:"varint,2,opt,name=Range,proto3,enum=grpcserver.QueryRange" json:"Range,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -276,93 +471,135 @@ type Date struct {
XXX_sizecache int32 `json:"-"`
}
func (m *Date) Reset() { *m = Date{} }
func (m *Date) String() string { return proto.CompactTextString(m) }
func (*Date) ProtoMessage() {}
func (*Date) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{4}
func (m *GetByDateReq) Reset() { *m = GetByDateReq{} }
func (m *GetByDateReq) String() string { return proto.CompactTextString(m) }
func (*GetByDateReq) ProtoMessage() {}
func (*GetByDateReq) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{8}
}
func (m *Date) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Date.Unmarshal(m, b)
func (m *GetByDateReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetByDateReq.Unmarshal(m, b)
}
func (m *Date) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Date.Marshal(b, m, deterministic)
func (m *GetByDateReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetByDateReq.Marshal(b, m, deterministic)
}
func (m *Date) XXX_Merge(src proto.Message) {
xxx_messageInfo_Date.Merge(m, src)
func (m *GetByDateReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetByDateReq.Merge(m, src)
}
func (m *Date) XXX_Size() int {
return xxx_messageInfo_Date.Size(m)
func (m *GetByDateReq) XXX_Size() int {
return xxx_messageInfo_GetByDateReq.Size(m)
}
func (m *Date) XXX_DiscardUnknown() {
xxx_messageInfo_Date.DiscardUnknown(m)
func (m *GetByDateReq) XXX_DiscardUnknown() {
xxx_messageInfo_GetByDateReq.DiscardUnknown(m)
}
var xxx_messageInfo_Date proto.InternalMessageInfo
var xxx_messageInfo_GetByDateReq proto.InternalMessageInfo
func (m *Date) GetDate() *timestamp.Timestamp {
func (m *GetByDateReq) GetDate() *timestamp.Timestamp {
if m != nil {
return m.Date
}
return nil
}
func (m *Date) GetRange() QueryRange {
func (m *GetByDateReq) GetRange() QueryRange {
if m != nil {
return m.Range
}
return QueryRange_DAY
}
type GetByDateResp struct {
Events []*Event `protobuf:"bytes,1,rep,name=Events,proto3" json:"Events,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetByDateResp) Reset() { *m = GetByDateResp{} }
func (m *GetByDateResp) String() string { return proto.CompactTextString(m) }
func (*GetByDateResp) ProtoMessage() {}
func (*GetByDateResp) Descriptor() ([]byte, []int) {
return fileDescriptor_afa6debe97205904, []int{9}
}
func (m *GetByDateResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetByDateResp.Unmarshal(m, b)
}
func (m *GetByDateResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetByDateResp.Marshal(b, m, deterministic)
}
func (m *GetByDateResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetByDateResp.Merge(m, src)
}
func (m *GetByDateResp) XXX_Size() int {
return xxx_messageInfo_GetByDateResp.Size(m)
}
func (m *GetByDateResp) XXX_DiscardUnknown() {
xxx_messageInfo_GetByDateResp.DiscardUnknown(m)
}
var xxx_messageInfo_GetByDateResp proto.InternalMessageInfo
func (m *GetByDateResp) GetEvents() []*Event {
if m != nil {
return m.Events
}
return nil
}
func init() {
proto.RegisterEnum("grpcserver.QueryRange", QueryRange_name, QueryRange_value)
proto.RegisterType((*Event)(nil), "grpcserver.Event")
proto.RegisterType((*EventList)(nil), "grpcserver.EventList")
proto.RegisterType((*EventID)(nil), "grpcserver.EventID")
proto.RegisterType((*EventWthID)(nil), "grpcserver.EventWthID")
proto.RegisterType((*Date)(nil), "grpcserver.Date")
proto.RegisterType((*CreateReq)(nil), "grpcserver.CreateReq")
proto.RegisterType((*CreateRsp)(nil), "grpcserver.CreateRsp")
proto.RegisterType((*UpdateReq)(nil), "grpcserver.UpdateReq")
proto.RegisterType((*DeleteReq)(nil), "grpcserver.DeleteReq")
proto.RegisterType((*ListResp)(nil), "grpcserver.ListResp")
proto.RegisterType((*GetByIDReq)(nil), "grpcserver.GetByIDReq")
proto.RegisterType((*GetByIDResp)(nil), "grpcserver.GetByIDResp")
proto.RegisterType((*GetByDateReq)(nil), "grpcserver.GetByDateReq")
proto.RegisterType((*GetByDateResp)(nil), "grpcserver.GetByDateResp")
}
func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
var fileDescriptor_afa6debe97205904 = []byte{
// 546 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xdd, 0x8a, 0xd3, 0x5c,
0x14, 0x9d, 0xb4, 0xf9, 0x99, 0xee, 0x7e, 0x5f, 0xcd, 0x6c, 0xb5, 0x66, 0xa2, 0x68, 0xc9, 0x8d,
0xb5, 0x48, 0x02, 0x1d, 0x10, 0x14, 0xbc, 0x70, 0x3c, 0x41, 0xa3, 0x33, 0x15, 0x43, 0x87, 0x41,
0xef, 0x32, 0xd3, 0x33, 0x35, 0xd0, 0x26, 0x21, 0x39, 0x1d, 0x28, 0xa5, 0x37, 0xbe, 0x82, 0x8f,
0xe2, 0xa3, 0xf8, 0x0a, 0xbe, 0x84, 0x77, 0x92, 0x9d, 0xd4, 0x29, 0x4d, 0x8b, 0xde, 0x9d, 0xb3,
0xd7, 0xda, 0x6b, 0xed, 0x9f, 0x93, 0x80, 0x3e, 0x4e, 0x93, 0xcb, 0x8c, 0xa7, 0xd7, 0x3c, 0xb5,
0x93, 0x34, 0x16, 0x31, 0xc2, 0x4d, 0xc4, 0x7c, 0x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f, 0x55, 0x87, 0xd3, 0xe7, 0xc3, 0x40,
0x7b, 0xc3, 0xc5, 0xf1, 0xdc, 0x63, 0xdb, 0xab, 0xd9, 0x21, 0x53, 0x16, 0x83, 0x65, 0x31, 0xa7,
0xd0, 0x20, 0x15, 0xda, 0xa6, 0xbe, 0x9e, 0x92, 0x47, 0x76, 0x89, 0xdc, 0x23, 0x91, 0x03, 0xbc,
0xe5, 0x2c, 0x72, 0xda, 0xd2, 0x59, 0xd0, 0x4a, 0x97, 0xc7, 0xff, 0x7d, 0x5e, 0xfb, 0xcf, 0x5c,
0xa8, 0xd4, 0xd9, 0xd1, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x0d, 0x16, 0xbf, 0x8e, 0x04,
0x00, 0x00,
// 525 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x54, 0xdf, 0x6b, 0xd3, 0x50,
0x14, 0x5e, 0xda, 0x24, 0x5d, 0x4e, 0xe7, 0xa8, 0x87, 0x59, 0xb3, 0x4c, 0xb4, 0xe4, 0xc5, 0x3a,
0x24, 0x83, 0x0e, 0x65, 0x13, 0x5f, 0xac, 0xb7, 0x68, 0x71, 0x56, 0x0c, 0x1d, 0xa2, 0x6f, 0xd9,
0x76, 0x56, 0x02, 0x6d, 0x13, 0x93, 0xdb, 0x41, 0xfe, 0x68, 0xc1, 0x57, 0xdf, 0x24, 0xf7, 0x26,
0x69, 0xda, 0x66, 0xea, 0x9e, 0x7d, 0x4b, 0xee, 0xf7, 0xe3, 0x9c, 0x7b, 0xce, 0xc7, 0x85, 0xd6,
0x24, 0x0a, 0x2f, 0x63, 0x8a, 0x6e, 0x28, 0x72, 0xc2, 0x28, 0xe0, 0x01, 0xc2, 0xf2, 0xc4, 0x7a,
0x32, 0x09, 0x82, 0xc9, 0x94, 0x8e, 0x04, 0x72, 0xb1, 0xb8, 0x3e, 0xe2, 0xfe, 0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xc1, 0x32, 0x33,
0xd6, 0xc3, 0xca, 0x73, 0xa1, 0xee, 0x83, 0x51, 0xac, 0x05, 0xcd, 0x0d, 0x5e, 0x96, 0x0d, 0x6b,
0xff, 0x16, 0x24, 0xf5, 0xe8, 0xef, 0x7c, 0x2b, 0xbd, 0xd7, 0x17, 0xba, 0xe8, 0xfb, 0xf8, 0x77,
0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0x63, 0x06, 0xc6, 0xd6, 0x05, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -377,12 +614,12 @@ const _ = grpc.SupportPackageIsVersion4
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type GrpcClient interface {
Create(ctx context.Context, in *Event, opts ...grpc.CallOption) (*EventID, error)
Update(ctx context.Context, in *EventWthID, opts ...grpc.CallOption) (*empty.Empty, error)
Delete(ctx context.Context, in *EventID, opts ...grpc.CallOption) (*empty.Empty, error)
List(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*EventList, error)
GetByID(ctx context.Context, in *EventID, opts ...grpc.CallOption) (*EventList, error)
GetByDate(ctx context.Context, in *Date, opts ...grpc.CallOption) (*EventList, error)
Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*CreateRsp, error)
Update(ctx context.Context, in *UpdateReq, opts ...grpc.CallOption) (*empty.Empty, error)
Delete(ctx context.Context, in *DeleteReq, opts ...grpc.CallOption) (*empty.Empty, error)
List(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ListResp, error)
GetByID(ctx context.Context, in *GetByIDReq, opts ...grpc.CallOption) (*GetByIDResp, error)
GetByDate(ctx context.Context, in *GetByDateReq, opts ...grpc.CallOption) (*GetByDateResp, error)
}
type grpcClient struct {
@ -393,8 +630,8 @@ func NewGrpcClient(cc *grpc.ClientConn) GrpcClient {
return &grpcClient{cc}
}
func (c *grpcClient) Create(ctx context.Context, in *Event, opts ...grpc.CallOption) (*EventID, error) {
out := new(EventID)
func (c *grpcClient) Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*CreateRsp, error) {
out := new(CreateRsp)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/Create", in, out, opts...)
if err != nil {
return nil, err
@ -402,7 +639,7 @@ func (c *grpcClient) Create(ctx context.Context, in *Event, opts ...grpc.CallOpt
return out, nil
}
func (c *grpcClient) Update(ctx context.Context, in *EventWthID, opts ...grpc.CallOption) (*empty.Empty, error) {
func (c *grpcClient) Update(ctx context.Context, in *UpdateReq, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/Update", in, out, opts...)
if err != nil {
@ -411,7 +648,7 @@ func (c *grpcClient) Update(ctx context.Context, in *EventWthID, opts ...grpc.Ca
return out, nil
}
func (c *grpcClient) Delete(ctx context.Context, in *EventID, opts ...grpc.CallOption) (*empty.Empty, error) {
func (c *grpcClient) Delete(ctx context.Context, in *DeleteReq, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/Delete", in, out, opts...)
if err != nil {
@ -420,8 +657,8 @@ func (c *grpcClient) Delete(ctx context.Context, in *EventID, opts ...grpc.CallO
return out, nil
}
func (c *grpcClient) List(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*EventList, error) {
out := new(EventList)
func (c *grpcClient) List(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ListResp, error) {
out := new(ListResp)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/List", in, out, opts...)
if err != nil {
return nil, err
@ -429,8 +666,8 @@ func (c *grpcClient) List(ctx context.Context, in *empty.Empty, opts ...grpc.Cal
return out, nil
}
func (c *grpcClient) GetByID(ctx context.Context, in *EventID, opts ...grpc.CallOption) (*EventList, error) {
out := new(EventList)
func (c *grpcClient) GetByID(ctx context.Context, in *GetByIDReq, opts ...grpc.CallOption) (*GetByIDResp, error) {
out := new(GetByIDResp)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/GetByID", in, out, opts...)
if err != nil {
return nil, err
@ -438,8 +675,8 @@ func (c *grpcClient) GetByID(ctx context.Context, in *EventID, opts ...grpc.Call
return out, nil
}
func (c *grpcClient) GetByDate(ctx context.Context, in *Date, opts ...grpc.CallOption) (*EventList, error) {
out := new(EventList)
func (c *grpcClient) GetByDate(ctx context.Context, in *GetByDateReq, opts ...grpc.CallOption) (*GetByDateResp, error) {
out := new(GetByDateResp)
err := c.cc.Invoke(ctx, "/grpcserver.grpc/GetByDate", in, out, opts...)
if err != nil {
return nil, err
@ -449,34 +686,34 @@ func (c *grpcClient) GetByDate(ctx context.Context, in *Date, opts ...grpc.CallO
// GrpcServer is the server API for Grpc service.
type GrpcServer interface {
Create(context.Context, *Event) (*EventID, error)
Update(context.Context, *EventWthID) (*empty.Empty, error)
Delete(context.Context, *EventID) (*empty.Empty, error)
List(context.Context, *empty.Empty) (*EventList, error)
GetByID(context.Context, *EventID) (*EventList, error)
GetByDate(context.Context, *Date) (*EventList, error)
Create(context.Context, *CreateReq) (*CreateRsp, error)
Update(context.Context, *UpdateReq) (*empty.Empty, error)
Delete(context.Context, *DeleteReq) (*empty.Empty, error)
List(context.Context, *empty.Empty) (*ListResp, error)
GetByID(context.Context, *GetByIDReq) (*GetByIDResp, error)
GetByDate(context.Context, *GetByDateReq) (*GetByDateResp, error)
}
// UnimplementedGrpcServer can be embedded to have forward compatible implementations.
type UnimplementedGrpcServer struct {
}
func (*UnimplementedGrpcServer) Create(ctx context.Context, req *Event) (*EventID, error) {
func (*UnimplementedGrpcServer) Create(ctx context.Context, req *CreateReq) (*CreateRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
}
func (*UnimplementedGrpcServer) Update(ctx context.Context, req *EventWthID) (*empty.Empty, error) {
func (*UnimplementedGrpcServer) Update(ctx context.Context, req *UpdateReq) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (*UnimplementedGrpcServer) Delete(ctx context.Context, req *EventID) (*empty.Empty, error) {
func (*UnimplementedGrpcServer) Delete(ctx context.Context, req *DeleteReq) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
}
func (*UnimplementedGrpcServer) List(ctx context.Context, req *empty.Empty) (*EventList, error) {
func (*UnimplementedGrpcServer) List(ctx context.Context, req *empty.Empty) (*ListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
}
func (*UnimplementedGrpcServer) GetByID(ctx context.Context, req *EventID) (*EventList, error) {
func (*UnimplementedGrpcServer) GetByID(ctx context.Context, req *GetByIDReq) (*GetByIDResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetByID not implemented")
}
func (*UnimplementedGrpcServer) GetByDate(ctx context.Context, req *Date) (*EventList, error) {
func (*UnimplementedGrpcServer) GetByDate(ctx context.Context, req *GetByDateReq) (*GetByDateResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetByDate not implemented")
}
@ -485,7 +722,7 @@ func RegisterGrpcServer(s *grpc.Server, srv GrpcServer) {
}
func _Grpc_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Event)
in := new(CreateReq)
if err := dec(in); err != nil {
return nil, err
}
@ -497,13 +734,13 @@ func _Grpc_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa
FullMethod: "/grpcserver.grpc/Create",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GrpcServer).Create(ctx, req.(*Event))
return srv.(GrpcServer).Create(ctx, req.(*CreateReq))
}
return interceptor(ctx, in, info, handler)
}
func _Grpc_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EventWthID)
in := new(UpdateReq)
if err := dec(in); err != nil {
return nil, err
}
@ -515,13 +752,13 @@ func _Grpc_Update_Handler(srv interface{}, ctx context.Context, dec func(interfa
FullMethod: "/grpcserver.grpc/Update",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GrpcServer).Update(ctx, req.(*EventWthID))
return srv.(GrpcServer).Update(ctx, req.(*UpdateReq))
}
return interceptor(ctx, in, info, handler)
}
func _Grpc_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EventID)
in := new(DeleteReq)
if err := dec(in); err != nil {
return nil, err
}
@ -533,7 +770,7 @@ func _Grpc_Delete_Handler(srv interface{}, ctx context.Context, dec func(interfa
FullMethod: "/grpcserver.grpc/Delete",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GrpcServer).Delete(ctx, req.(*EventID))
return srv.(GrpcServer).Delete(ctx, req.(*DeleteReq))
}
return interceptor(ctx, in, info, handler)
}
@ -557,7 +794,7 @@ func _Grpc_List_Handler(srv interface{}, ctx context.Context, dec func(interface
}
func _Grpc_GetByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EventID)
in := new(GetByIDReq)
if err := dec(in); err != nil {
return nil, err
}
@ -569,13 +806,13 @@ func _Grpc_GetByID_Handler(srv interface{}, ctx context.Context, dec func(interf
FullMethod: "/grpcserver.grpc/GetByID",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GrpcServer).GetByID(ctx, req.(*EventID))
return srv.(GrpcServer).GetByID(ctx, req.(*GetByIDReq))
}
return interceptor(ctx, in, info, handler)
}
func _Grpc_GetByDate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Date)
in := new(GetByDateReq)
if err := dec(in); err != nil {
return nil, err
}
@ -587,7 +824,7 @@ func _Grpc_GetByDate_Handler(srv interface{}, ctx context.Context, dec func(inte
FullMethod: "/grpcserver.grpc/GetByDate",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GrpcServer).GetByDate(ctx, req.(*Date))
return srv.(GrpcServer).GetByDate(ctx, req.(*GetByDateReq))
}
return interceptor(ctx, in, info, handler)
}

View File

@ -2,7 +2,8 @@ package grpcserver
import (
"context"
"errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/golang/protobuf/ptypes/empty"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
@ -13,56 +14,74 @@ type Service struct {
App app.App
}
func (s Service) Create(ctx context.Context, e *Event) (*EventID, error) {
var res EventID
ce, err := pbevent2event(e)
func (s Service) Create(ctx context.Context, e *CreateReq) (*CreateRsp, error) {
var res CreateRsp
ce, err := s.buildStorageEvent(e)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "inconvertible")
}
t, err := s.App.Storage.Create(ce)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "storage error: can't create event")
}
res.ID = int64(t)
return &res, nil
}
func (s Service) Update(ctx context.Context, e *EventWthID) (*empty.Empty, error) {
cid, ce, err := pbeventWitID2eventAndID(e)
func (s Service) Update(ctx context.Context, e *UpdateReq) (*empty.Empty, error) {
cid, ce, err := s.buildStorageEventAndID(e)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "inconvertible")
}
return nil, s.App.Storage.Update(cid, ce)
if s.App.Storage.Update(cid, ce)!= nil {
return nil, status.Errorf(codes.Internal, "storage error: can't update event")
}
return nil, nil
}
func (s Service) Delete(ctx context.Context, e *EventID) (*empty.Empty, error) {
return nil, s.App.Storage.Delete(event.ID(e.ID))
func (s Service) Delete(ctx context.Context, e *DeleteReq) (*empty.Empty, error) {
if s.App.Storage.Delete(event.ID(e.ID)) != nil {
return nil, status.Errorf(codes.Internal, "storage error: can't update event")
}
return nil, nil
}
func (s Service) List(ctx context.Context, e *empty.Empty) (*EventList, error) {
func (s Service) List(ctx context.Context, e *empty.Empty) (*ListResp, error) {
tmp, err := s.App.Storage.List()
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
}
return evtMap2pbEventList(tmp)
l,err := s.buildEventList(tmp)
if err != nil {
return nil, status.Errorf(codes.Internal, "inconvertible")
}
return &ListResp{Events: l},nil
}
func (s Service) GetByID(ctx context.Context, e *EventID) (*EventList, error) {
func (s Service) GetByID(ctx context.Context, e *GetByIDReq) (*GetByIDResp, error) {
tmp, ok := s.App.Storage.GetByID(event.ID(e.ID))
if !ok {
return nil, errors.New("event not found")
return nil, status.Errorf(codes.NotFound, "event not found")
}
return evtMap2pbEventList(map[event.ID]event.Event{event.ID(e.ID): tmp})
l,err := s.buildEventList(map[event.ID]event.Event{event.ID(e.ID): tmp})
if err != nil {
return nil, status.Errorf(codes.Internal, "inconvertible")
}
return &GetByIDResp{Events: l},nil
}
func (s Service) GetByDate(ctx context.Context, e *Date) (*EventList, error) {
d, r, err := pbDate2Time(e)
func (s Service) GetByDate(ctx context.Context, e *GetByDateReq) (*GetByDateResp, error) {
d, r, err := s.buildTimeAndRange(e)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "inconvertible")
}
tmp, err := s.App.Storage.GetByDate(d, r)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "storage error: can't get list of events")
}
return evtMap2pbEventList(tmp)
l,err := s.buildEventList(tmp)
if err != nil {
return nil, status.Errorf(codes.Internal, "inconvertible")
}
return &GetByDateResp{Events: l},nil
}

View File

@ -0,0 +1,49 @@
package grpcserver
import (
"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/require"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
"testing"
"time"
)
var conf = config.Config{Server: config.Server{ Address: "localhost", Port: "50511" }, Grpc: config.Server{Address: "localhost", Port: "50512"}, Logger: config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false}, Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
var storeConf = store.Config(conf.Storage)
func TestService(t *testing.T) {
log, err := logger.New(conf)
require.NoError(t,err, "can't create logger")
srv := Service{App: *app.New(log, store.NewStore(storeConf))}
tm, _ := time.Parse("02.01.2006", "01.02.2003")
cdate, err := ptypes.TimestampProto(tm)
require.NoError(t,err, "can't convert time to proto")
// Create
step1, err := srv.Create(nil, &CreateReq{Title: "Test event", Date: cdate, Latency: ptypes.DurationProto(time.Hour*24), Note: "First gen", UserID: 1111, NotifyTime: ptypes.DurationProto(time.Minute*5)})
require.NoError(t,err, "can,t create event")
require.NotEqual(t,step1.ID,0, "message ID may not be a \"0\"")
// GetByID
step2, err := srv.GetByID(nil,&GetByIDReq{ID: step1.ID})
require.NoError(t,err, "can't get event by id")
require.Equal(t, 1, len(step2.Events), "length of slice in responce must be a \"1\"")
require.Equal(t, &Event{ID: 1,Title: "Test event", Date: cdate, Latency: ptypes.DurationProto(time.Hour*24), Note: "First gen", UserID: 1111, NotifyTime: ptypes.DurationProto(time.Minute*5)},step2.Events[0], "request contains invalid data")
// Update
_, err = srv.Update(nil,&UpdateReq{ID: step1.ID, Event: &Event{Title: "Updated event", Date: cdate, Latency: ptypes.DurationProto(time.Hour*48), Note: "Updated gen", UserID: 2222, NotifyTime: ptypes.DurationProto(time.Minute*10)}})
require.NoError(t,err, "can't update event")
// List
step3, err := srv.List(nil, nil)
require.NoError(t,err, "problem with list")
require.Equal(t, 1, len(step3.Events), "length of slice in responce must be a \"1\"")
require.Equal(t, &Event{ID: 1,Title: "Updated event", Date: cdate, Latency: ptypes.DurationProto(time.Hour*48), Note: "Updated gen", UserID: 2222, NotifyTime: ptypes.DurationProto(time.Minute*10)},step3.Events[0], "request contains invalid data")
// GetByDate
step4, err := srv.GetByDate(nil,&GetByDateReq{Date: cdate, Range: 1})
require.NoError(t,err, "problem with GetByDate")
require.Equal(t, 1, len(step4.Events), "length of slice in responce must be a \"1\"")
require.Equal(t, &Event{ID: 1,Title: "Updated event", Date: cdate, Latency: ptypes.DurationProto(time.Hour*48), Note: "Updated gen", UserID: 2222, NotifyTime: ptypes.DurationProto(time.Minute*10)},step4.Events[0], "request contains invalid data")
// Delete
// List
}