From 6b9829f656491a120955b83e82ccaae46a9ced79 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Tue, 17 Aug 2021 19:26:27 +1000 Subject: [PATCH 1/6] =?UTF-8?q?Race=20List=20--=20racing.proto:=20?= =?UTF-8?q?=E2=80=A2=20Defined=20enum=20`Status`=20which=20reflects=20if?= =?UTF-8?q?=20a=20race=20is=20open=20or=20closed.=20races.go:=20=E2=80=A2?= =?UTF-8?q?=20If=20the=20advertised=20start=20time=20is=20in=20the=20past,?= =?UTF-8?q?=20the=20race=20will=20be=20marked=20as=20"CLOSED",=20else,=20t?= =?UTF-8?q?he=20race=20will=20indicate=20an=20"OPEN"=20status.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/proto/racing/racing.pb.go | 113 ++++++++++++++++++++++++------- api/proto/racing/racing.proto | 5 ++ racing/db/races.go | 8 +++ racing/proto/racing/racing.pb.go | 111 +++++++++++++++++++++++------- racing/proto/racing/racing.proto | 5 ++ 5 files changed, 193 insertions(+), 49 deletions(-) diff --git a/api/proto/racing/racing.pb.go b/api/proto/racing/racing.pb.go index 9105676..d60096a 100644 --- a/api/proto/racing/racing.pb.go +++ b/api/proto/racing/racing.pb.go @@ -22,6 +22,52 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type Race_Status int32 + +const ( + Race_CLOSED Race_Status = 0 + Race_OPEN Race_Status = 1 +) + +// Enum value maps for Race_Status. +var ( + Race_Status_name = map[int32]string{ + 0: "CLOSED", + 1: "OPEN", + } + Race_Status_value = map[string]int32{ + "CLOSED": 0, + "OPEN": 1, + } +) + +func (x Race_Status) Enum() *Race_Status { + p := new(Race_Status) + *p = x + return p +} + +func (x Race_Status) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Race_Status) Descriptor() protoreflect.EnumDescriptor { + return file_racing_racing_proto_enumTypes[0].Descriptor() +} + +func (Race_Status) Type() protoreflect.EnumType { + return &file_racing_racing_proto_enumTypes[0] +} + +func (x Race_Status) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Race_Status.Descriptor instead. +func (Race_Status) EnumDescriptor() ([]byte, []int) { + return file_racing_racing_proto_rawDescGZIP(), []int{3, 0} +} + // Request for ListRaces call. type ListRacesRequest struct { state protoimpl.MessageState @@ -200,6 +246,7 @@ type Race struct { Visible bool `protobuf:"varint,5,opt,name=visible,proto3" json:"visible,omitempty"` // AdvertisedStartTime is the time the race is advertised to run. AdvertisedStartTime *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=advertised_start_time,json=advertisedStartTime,proto3" json:"advertised_start_time,omitempty"` + Status Race_Status `protobuf:"varint,7,opt,name=status,proto3,enum=racing.Race_Status" json:"status,omitempty"` } func (x *Race) Reset() { @@ -276,6 +323,13 @@ func (x *Race) GetAdvertisedStartTime() *timestamppb.Timestamp { return nil } +func (x *Race) GetStatus() Race_Status { + if x != nil { + return x.Status + } + return Race_CLOSED +} + var File_racing_racing_proto protoreflect.FileDescriptor var file_racing_racing_proto_rawDesc = []byte{ @@ -302,7 +356,7 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x73, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x69, 0x73, - 0x69, 0x62, 0x6c, 0x65, 0x22, 0xcb, 0x01, 0x0a, 0x04, 0x52, 0x61, 0x63, 0x65, 0x12, 0x0e, 0x0a, + 0x69, 0x62, 0x6c, 0x65, 0x22, 0x98, 0x02, 0x0a, 0x04, 0x52, 0x61, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, @@ -315,14 +369,19 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x13, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, - 0x6d, 0x65, 0x32, 0x65, 0x0a, 0x06, 0x52, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x12, 0x5b, 0x0a, 0x09, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x63, 0x69, - 0x6e, 0x67, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x69, 0x73, - 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x22, 0x0e, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x73, 0x74, - 0x2d, 0x72, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x01, 0x2a, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, - 0x63, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, + 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, + 0x1e, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x4c, 0x4f, + 0x53, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x01, 0x32, + 0x65, 0x0a, 0x06, 0x52, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x12, 0x5b, 0x0a, 0x09, 0x4c, 0x69, 0x73, + 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x19, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, + 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x13, 0x22, 0x0e, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x2d, 0x72, 0x61, + 0x63, 0x65, 0x73, 0x3a, 0x01, 0x2a, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, 0x63, 0x69, 0x6e, + 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -337,25 +396,28 @@ func file_racing_racing_proto_rawDescGZIP() []byte { return file_racing_racing_proto_rawDescData } +var file_racing_racing_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_racing_racing_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_racing_racing_proto_goTypes = []interface{}{ - (*ListRacesRequest)(nil), // 0: racing.ListRacesRequest - (*ListRacesResponse)(nil), // 1: racing.ListRacesResponse - (*ListRacesRequestFilter)(nil), // 2: racing.ListRacesRequestFilter - (*Race)(nil), // 3: racing.Race - (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp + (Race_Status)(0), // 0: racing.Race.Status + (*ListRacesRequest)(nil), // 1: racing.ListRacesRequest + (*ListRacesResponse)(nil), // 2: racing.ListRacesResponse + (*ListRacesRequestFilter)(nil), // 3: racing.ListRacesRequestFilter + (*Race)(nil), // 4: racing.Race + (*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp } var file_racing_racing_proto_depIdxs = []int32{ - 2, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter - 3, // 1: racing.ListRacesResponse.races:type_name -> racing.Race - 4, // 2: racing.Race.advertised_start_time:type_name -> google.protobuf.Timestamp - 0, // 3: racing.Racing.ListRaces:input_type -> racing.ListRacesRequest - 1, // 4: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse - 4, // [4:5] is the sub-list for method output_type - 3, // [3:4] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 3, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter + 4, // 1: racing.ListRacesResponse.races:type_name -> racing.Race + 5, // 2: racing.Race.advertised_start_time:type_name -> google.protobuf.Timestamp + 0, // 3: racing.Race.status:type_name -> racing.Race.Status + 1, // 4: racing.Racing.ListRaces:input_type -> racing.ListRacesRequest + 2, // 5: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse + 5, // [5:6] is the sub-list for method output_type + 4, // [4:5] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_racing_racing_proto_init() } @@ -420,13 +482,14 @@ func file_racing_racing_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_racing_racing_proto_rawDesc, - NumEnums: 0, + NumEnums: 1, NumMessages: 4, NumExtensions: 0, NumServices: 1, }, GoTypes: file_racing_racing_proto_goTypes, DependencyIndexes: file_racing_racing_proto_depIdxs, + EnumInfos: file_racing_racing_proto_enumTypes, MessageInfos: file_racing_racing_proto_msgTypes, }.Build() File_racing_racing_proto = out.File diff --git a/api/proto/racing/racing.proto b/api/proto/racing/racing.proto index 091068d..6f3210b 100644 --- a/api/proto/racing/racing.proto +++ b/api/proto/racing/racing.proto @@ -48,4 +48,9 @@ message Race { bool visible = 5; // AdvertisedStartTime is the time the race is advertised to run. google.protobuf.Timestamp advertised_start_time = 6; + enum Status { + CLOSED = 0; + OPEN = 1; + } + Status status = 7; } diff --git a/racing/db/races.go b/racing/db/races.go index 5589d84..48658e5 100644 --- a/racing/db/races.go +++ b/racing/db/races.go @@ -187,6 +187,14 @@ func (m *racesRepo) scanRaces( return nil, err } + if advertisedStart.Before(time.Now()) { + // All races that have an `advertised_start_time` in the past should + // reflect `CLOSED` + // Note that this depends on the system having the correct time. + race.Status = racing.Race_CLOSED + } else { + race.Status = racing.Race_OPEN + } race.AdvertisedStartTime = ts races = append(races, &race) diff --git a/racing/proto/racing/racing.pb.go b/racing/proto/racing/racing.pb.go index a2b9a68..02495d3 100644 --- a/racing/proto/racing/racing.pb.go +++ b/racing/proto/racing/racing.pb.go @@ -21,6 +21,52 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type Race_Status int32 + +const ( + Race_CLOSED Race_Status = 0 + Race_OPEN Race_Status = 1 +) + +// Enum value maps for Race_Status. +var ( + Race_Status_name = map[int32]string{ + 0: "CLOSED", + 1: "OPEN", + } + Race_Status_value = map[string]int32{ + "CLOSED": 0, + "OPEN": 1, + } +) + +func (x Race_Status) Enum() *Race_Status { + p := new(Race_Status) + *p = x + return p +} + +func (x Race_Status) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Race_Status) Descriptor() protoreflect.EnumDescriptor { + return file_racing_racing_proto_enumTypes[0].Descriptor() +} + +func (Race_Status) Type() protoreflect.EnumType { + return &file_racing_racing_proto_enumTypes[0] +} + +func (x Race_Status) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Race_Status.Descriptor instead. +func (Race_Status) EnumDescriptor() ([]byte, []int) { + return file_racing_racing_proto_rawDescGZIP(), []int{3, 0} +} + type ListRacesRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -198,6 +244,7 @@ type Race struct { Visible bool `protobuf:"varint,5,opt,name=visible,proto3" json:"visible,omitempty"` // AdvertisedStartTime is the time the race is advertised to run. AdvertisedStartTime *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=advertised_start_time,json=advertisedStartTime,proto3" json:"advertised_start_time,omitempty"` + Status Race_Status `protobuf:"varint,7,opt,name=status,proto3,enum=racing.Race_Status" json:"status,omitempty"` } func (x *Race) Reset() { @@ -274,6 +321,13 @@ func (x *Race) GetAdvertisedStartTime() *timestamppb.Timestamp { return nil } +func (x *Race) GetStatus() Race_Status { + if x != nil { + return x.Status + } + return Race_CLOSED +} + var File_racing_racing_proto protoreflect.FileDescriptor var file_racing_racing_proto_rawDesc = []byte{ @@ -298,7 +352,7 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x0a, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x73, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, - 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x22, 0xcb, 0x01, 0x0a, 0x04, 0x52, 0x61, 0x63, 0x65, 0x12, + 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x22, 0x98, 0x02, 0x0a, 0x04, 0x52, 0x61, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x12, 0x12, @@ -311,13 +365,18 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x13, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74, - 0x54, 0x69, 0x6d, 0x65, 0x32, 0x4c, 0x0a, 0x06, 0x52, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x12, 0x42, - 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x12, 0x18, 0x2e, 0x72, 0x61, - 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x4c, - 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, + 0x63, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x22, 0x1e, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0a, 0x0a, 0x06, 0x43, + 0x4c, 0x4f, 0x53, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4f, 0x50, 0x45, 0x4e, 0x10, + 0x01, 0x32, 0x4c, 0x0a, 0x06, 0x52, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x12, 0x42, 0x0a, 0x09, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, + 0x67, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -332,25 +391,28 @@ func file_racing_racing_proto_rawDescGZIP() []byte { return file_racing_racing_proto_rawDescData } +var file_racing_racing_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_racing_racing_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_racing_racing_proto_goTypes = []interface{}{ - (*ListRacesRequest)(nil), // 0: racing.ListRacesRequest - (*ListRacesResponse)(nil), // 1: racing.ListRacesResponse - (*ListRacesRequestFilter)(nil), // 2: racing.ListRacesRequestFilter - (*Race)(nil), // 3: racing.Race - (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp + (Race_Status)(0), // 0: racing.Race.Status + (*ListRacesRequest)(nil), // 1: racing.ListRacesRequest + (*ListRacesResponse)(nil), // 2: racing.ListRacesResponse + (*ListRacesRequestFilter)(nil), // 3: racing.ListRacesRequestFilter + (*Race)(nil), // 4: racing.Race + (*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp } var file_racing_racing_proto_depIdxs = []int32{ - 2, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter - 3, // 1: racing.ListRacesResponse.races:type_name -> racing.Race - 4, // 2: racing.Race.advertised_start_time:type_name -> google.protobuf.Timestamp - 0, // 3: racing.Racing.ListRaces:input_type -> racing.ListRacesRequest - 1, // 4: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse - 4, // [4:5] is the sub-list for method output_type - 3, // [3:4] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 3, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter + 4, // 1: racing.ListRacesResponse.races:type_name -> racing.Race + 5, // 2: racing.Race.advertised_start_time:type_name -> google.protobuf.Timestamp + 0, // 3: racing.Race.status:type_name -> racing.Race.Status + 1, // 4: racing.Racing.ListRaces:input_type -> racing.ListRacesRequest + 2, // 5: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse + 5, // [5:6] is the sub-list for method output_type + 4, // [4:5] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_racing_racing_proto_init() } @@ -415,13 +477,14 @@ func file_racing_racing_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_racing_racing_proto_rawDesc, - NumEnums: 0, + NumEnums: 1, NumMessages: 4, NumExtensions: 0, NumServices: 1, }, GoTypes: file_racing_racing_proto_goTypes, DependencyIndexes: file_racing_racing_proto_depIdxs, + EnumInfos: file_racing_racing_proto_enumTypes, MessageInfos: file_racing_racing_proto_msgTypes, }.Build() File_racing_racing_proto = out.File diff --git a/racing/proto/racing/racing.proto b/racing/proto/racing/racing.proto index addcf09..562c9af 100644 --- a/racing/proto/racing/racing.proto +++ b/racing/proto/racing/racing.proto @@ -44,5 +44,10 @@ message Race { bool visible = 5; // AdvertisedStartTime is the time the race is advertised to run. google.protobuf.Timestamp advertised_start_time = 6; + enum Status { + CLOSED = 0; + OPEN = 1; + } + Status status = 7; } From f3c296d72381ed2d8692f77fc8f8ec9da068b930 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Wed, 18 Aug 2021 14:14:33 +1000 Subject: [PATCH 2/6] =?UTF-8?q?racing.proto:=20=E2=80=A2=20Describe=20purp?= =?UTF-8?q?ose=20of=20`status`=20response=20field.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/proto/racing/racing.proto | 2 ++ racing/proto/racing/racing.proto | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api/proto/racing/racing.proto b/api/proto/racing/racing.proto index 2cc2a95..3075bf7 100644 --- a/api/proto/racing/racing.proto +++ b/api/proto/racing/racing.proto @@ -54,5 +54,7 @@ message Race { CLOSED = 0; OPEN = 1; } + // Status reflects whether the Race is open or closed, based off the + // advertised start time being in the past. Status status = 7; } diff --git a/racing/proto/racing/racing.proto b/racing/proto/racing/racing.proto index 1eab7e9..892a858 100644 --- a/racing/proto/racing/racing.proto +++ b/racing/proto/racing/racing.proto @@ -50,6 +50,8 @@ message Race { CLOSED = 0; OPEN = 1; } + // Status reflects whether the Race is open or closed, based off the + // advertised start time being in the past. Status status = 7; } From 356a19ac67caaf2acf6716a73634dea475f45ac2 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 21:18:50 +1000 Subject: [PATCH 3/6] =?UTF-8?q?races=5Ftest:=20=E2=80=A2=20Added=20test=20?= =?UTF-8?q?case=20for=20status=20flag=20when=20returning=20race.=20races.g?= =?UTF-8?q?o:=20=E2=80=A2=20Obey=20guidelines=20for=20error=20messages=20(?= =?UTF-8?q?lowercase,=20no=20fullstops).=20go.mod:=20=E2=80=A2=20Bump=20go?= =?UTF-8?q?=20version.=20db.go:=20=E2=80=A2=20Remove=20deprecated=20packag?= =?UTF-8?q?e=20`ptypes.TimestampProto`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/go.mod | 12 +++++++++- racing/db/db.go | 6 ++--- racing/db/races.go | 13 ++++------ racing/db/races_test.go | 53 +++++++++++++++++++++++++++++++++++++---- racing/go.mod | 10 +++++++- 5 files changed, 76 insertions(+), 18 deletions(-) diff --git a/api/go.mod b/api/go.mod index dccf52d..0a6cc74 100644 --- a/api/go.mod +++ b/api/go.mod @@ -1,6 +1,6 @@ module github.com/ashleyjlive/entain/api -go 1.16 +go 1.17 require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 @@ -13,3 +13,13 @@ require ( gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) + +require ( + github.com/ghodss/yaml v1.0.0 // indirect + github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/magefile/mage v1.10.0 // indirect + golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect + golang.org/x/text v0.3.5 // indirect +) diff --git a/racing/db/db.go b/racing/db/db.go index 272fdf3..df7e257 100644 --- a/racing/db/db.go +++ b/racing/db/db.go @@ -6,6 +6,7 @@ import ( "github.com/ashleyjlive/entain/racing/proto/racing" "github.com/golang/protobuf/ptypes" + "google.golang.org/protobuf/types/known/timestamppb" "syreclabs.com/go/faker" ) @@ -58,10 +59,7 @@ func (r *racesRepo) listAll() ([]*racing.Race, error) { return nil, err } - ts, err := ptypes.TimestampProto(advertisedStart) - if err != nil { - return nil, err - } + ts := timestamppb.New(advertisedStart) race.AdvertisedStartTime = ts diff --git a/racing/db/races.go b/racing/db/races.go index ac7f7a1..d40a342 100644 --- a/racing/db/races.go +++ b/racing/db/races.go @@ -8,8 +8,8 @@ import ( "time" "unicode" - "github.com/golang/protobuf/ptypes" _ "github.com/mattn/go-sqlite3" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/ashleyjlive/entain/racing/proto/racing" ) @@ -148,16 +148,16 @@ func toOrderBySql(input string) (*string, error) { words := strings.Fields(str) wordCount := len(words) if wordCount > 2 || wordCount < 1 { - return nil, errors.New("Invalid order by term count.") + return nil, errors.New("invalid order by term count") } sortField := words[0] if strings.IndexFunc(sortField, isUnsafeColumnChar) != -1 { - return nil, errors.New("Invalid column name.") + return nil, errors.New("invalid column name") } if wordCount == 2 { sort := words[1] if !(strings.EqualFold(sort, "asc") || strings.EqualFold(sort, "desc")) { - return nil, errors.New("Invalid order by dir parameter.") + return nil, errors.New("invalid order by dir parameter") } sortField += " " + sort } @@ -197,10 +197,7 @@ func (m *racesRepo) scanRaces( return nil, err } - ts, err := ptypes.TimestampProto(advertisedStart) - if err != nil { - return nil, err - } + ts := timestamppb.New(advertisedStart) if advertisedStart.Before(time.Now()) { // All races that have an `advertised_start_time` in the past should diff --git a/racing/db/races_test.go b/racing/db/races_test.go index 1e3a1d5..c710dd4 100644 --- a/racing/db/races_test.go +++ b/racing/db/races_test.go @@ -10,8 +10,9 @@ import ( "github.com/ashleyjlive/entain/racing/db" "github.com/ashleyjlive/entain/racing/proto/racing" - "github.com/golang/protobuf/ptypes" "syreclabs.com/go/faker" + + "google.golang.org/protobuf/types/known/timestamppb" ) func TestRepo(t *testing.T) { @@ -183,7 +184,7 @@ func TestOrderBy(t *testing.T) { racesRepo := db.NewRacesRepo(racingDB) _ = racesRepo.Init() - tm1, _ := ptypes.TimestampProto(time.Now().AddDate(0, 0, 2)) + tm1 := timestamppb.New(time.Now().AddDate(0, 0, 2)) race1 := racing.Race{Id: int64(1), MeetingId: int64(5), Name: "Test1", Number: int64(5), @@ -192,7 +193,7 @@ func TestOrderBy(t *testing.T) { if err != nil { t.Fatalf("Failed to insert first race %v.", err) } - tm2, _ := ptypes.TimestampProto(time.Now().AddDate(0, 0, 2)) + tm2 := timestamppb.New(time.Now().AddDate(0, 0, -2)) race2 := racing.Race{Id: int64(5), MeetingId: int64(3), Name: "Test2", Number: int64(9), @@ -259,6 +260,50 @@ func TestOrderBy(t *testing.T) { } } +func TestStatusField(t *testing.T) { + racingDB, err := GetTestDB("db", "TestStatusField") + if err != nil { + t.Fatalf("Failed to open testdb %v", err) + } + racesRepo := db.NewRacesRepo(racingDB) + _ = racesRepo.Init() + + tm1 := timestamppb.New(time.Now().AddDate(0, 0, 2)) + race1 := + racing.Race{Id: int64(1), MeetingId: int64(5), + Name: "Test1", Number: int64(5), + Visible: true, AdvertisedStartTime: tm1} + err = racesRepo.InsertRace(&race1) + if err != nil { + t.Fatalf("Failed to insert first race %v.", err) + } + tm2 := timestamppb.New(time.Now().AddDate(0, 0, -2)) + race2 := + racing.Race{Id: int64(5), MeetingId: int64(3), + Name: "Test2", Number: int64(9), + Visible: false, AdvertisedStartTime: tm2} + err = racesRepo.InsertRace(&race2) + if err != nil { + t.Fatalf("Failed to insert second race %v.", err) + } + + // Test case + rq := racing.ListRacesRequest{} + rsp, err := racesRepo.List(&rq) + if err != nil { + t.Fatalf("Unable to retrieve races list.") + } + if len(rsp) != 2 { + t.Fatalf("Returned incorrect amount of races.") + } + if rsp[0].Status != racing.Race_CLOSED { + t.Fatalf("Returned invalid status flag for closed event %v.", rsp[0].Id) + } + if rsp[1].Status != racing.Race_OPEN { + t.Fatalf("Returned invalid status flag for open event %v.", rsp[1].Id) + } +} + // Helpers // func GetRaces() []*racing.Race { @@ -270,7 +315,7 @@ func GetRaces() []*racing.Race { name := faker.Team().Name() number, _ := strconv.Atoi(faker.Number().Between(1, 12)) visible := randBool() - tm, _ := ptypes.TimestampProto( + tm := timestamppb.New( faker.Time().Between( time.Now().AddDate(0, 0, -1), time.Now().AddDate(0, 0, 2))) race := diff --git a/racing/go.mod b/racing/go.mod index 63cca47..e0f69d0 100644 --- a/racing/go.mod +++ b/racing/go.mod @@ -1,6 +1,6 @@ module github.com/ashleyjlive/entain/racing -go 1.16 +go 1.17 require ( github.com/golang/protobuf v1.5.2 @@ -17,3 +17,11 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect syreclabs.com/go/faker v1.2.3 ) + +require ( + github.com/ghodss/yaml v1.0.0 // indirect + github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect + github.com/magefile/mage v1.10.0 // indirect + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect + golang.org/x/text v0.3.5 // indirect +) From 26a80a1b6f59b3bb2d2ea91e544d67ae76036fce Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 23:30:49 +1000 Subject: [PATCH 4/6] =?UTF-8?q?racing/proto/README.md:=20=E2=80=A2=20Detai?= =?UTF-8?q?l=20the=20introduced=20status=20flag.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/proto/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/racing/proto/README.md b/racing/proto/README.md index f6821c7..e7d0c5e 100644 --- a/racing/proto/README.md +++ b/racing/proto/README.md @@ -23,4 +23,5 @@ This defines the protobuf message types for the racing API. - The unique identifier for the races meeting (int64). - The name of the race (string). - The visibility of the race (bool). -- The advertised start time of the race (Timestamp). \ No newline at end of file +- The advertised start time of the race (Timestamp). +- A status flag indicating if the event is `OPEN` or `CLOSED` - this is based off the advertised start time with the systems current time. \ No newline at end of file From 248d2814785fdd42a231fa55692aa1030a8e44a7 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 23:43:53 +1000 Subject: [PATCH 5/6] =?UTF-8?q?racing/db/races=5Ftest:=20=E2=80=A2=20Fixed?= =?UTF-8?q?=20invalid=20testType=20of=20"db"=20for=20races=5Ftest.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/db/races_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/racing/db/races_test.go b/racing/db/races_test.go index c710dd4..bddcb7a 100644 --- a/racing/db/races_test.go +++ b/racing/db/races_test.go @@ -146,7 +146,7 @@ func TestFetchAllEmpty(t *testing.T) { } func TestFetchAll(t *testing.T) { - racingDB, err := GetTestDB("db", "TestPopulateAndFetchRepo") + racingDB, err := GetTestDB("races", "TestPopulateAndFetchRepo") if err != nil { t.Fatalf("Failed to open testdb %v", err) } @@ -177,7 +177,7 @@ func TestFetchAll(t *testing.T) { } func TestOrderBy(t *testing.T) { - racingDB, err := GetTestDB("db", "TestOrderBy") + racingDB, err := GetTestDB("races", "TestOrderBy") if err != nil { t.Fatalf("Failed to open testdb %v", err) } @@ -261,7 +261,7 @@ func TestOrderBy(t *testing.T) { } func TestStatusField(t *testing.T) { - racingDB, err := GetTestDB("db", "TestStatusField") + racingDB, err := GetTestDB("races", "TestStatusField") if err != nil { t.Fatalf("Failed to open testdb %v", err) } From adc9c45c7d1566bc83f9202d124f4c831da360fd Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Fri, 20 Aug 2021 00:18:08 +1000 Subject: [PATCH 6/6] =?UTF-8?q?races=5Ftest.go:=20=E2=80=A2=20Fixed=20comp?= =?UTF-8?q?ilation=20error=20due=20to=20changes=20to=20`racesRepo.Init()`?= =?UTF-8?q?=20changes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/db/races_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/racing/db/races_test.go b/racing/db/races_test.go index 03a401d..864ee11 100644 --- a/racing/db/races_test.go +++ b/racing/db/races_test.go @@ -266,7 +266,7 @@ func TestStatusField(t *testing.T) { t.Fatalf("Failed to open testdb %v", err) } racesRepo := db.NewRacesRepo(racingDB) - _ = racesRepo.Init() + _ = racesRepo.Init(false) tm1 := timestamppb.New(time.Now().AddDate(0, 0, 2)) race1 :=