From 7fb73f57ff2729bfa21baafaa325cb3010df8d5f Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Tue, 17 Aug 2021 22:48:40 +1000 Subject: [PATCH 1/7] =?UTF-8?q?Get=20Race=20Request=20--=20racing.proto:?= =?UTF-8?q?=20=E2=80=A2=20Defined=20GetRace=20request=20which=20accepts=20?= =?UTF-8?q?the=20identifier=20of=20the=20race.=20queries.go:=20=E2=80=A2?= =?UTF-8?q?=20Defined=20query=20for=20`getRace`=20requests.=20races.go:=20?= =?UTF-8?q?=E2=80=A2=20Implemented=20`Get`=20function=20which=20returns=20?= =?UTF-8?q?a=20single=20race=20and=20optionally=20an=20error.=20racing.go:?= =?UTF-8?q?=20=E2=80=A2=20Added=20racing=20interface=20and=20implementatio?= =?UTF-8?q?n=20for=20accessing=20racesRepo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/proto/racing/racing.pb.go | 191 ++++++++++++++++++-------- api/proto/racing/racing.pb.gw.go | 99 +++++++++++++ api/proto/racing/racing.proto | 7 + api/proto/racing/racing_grpc.pb.go | 36 +++++ racing/db/queries.go | 12 ++ racing/db/races.go | 25 ++++ racing/proto/racing/racing.pb.go | 187 +++++++++++++++++-------- racing/proto/racing/racing.proto | 5 + racing/proto/racing/racing_grpc.pb.go | 36 +++++ racing/service/racing.go | 9 ++ racing/test/races_test.go | 16 +++ 11 files changed, 502 insertions(+), 121 deletions(-) create mode 100644 racing/test/races_test.go diff --git a/api/proto/racing/racing.pb.go b/api/proto/racing/racing.pb.go index d60096a..dd60288 100644 --- a/api/proto/racing/racing.pb.go +++ b/api/proto/racing/racing.pb.go @@ -65,7 +65,7 @@ func (x Race_Status) Number() protoreflect.EnumNumber { // Deprecated: Use Race_Status.Descriptor instead. func (Race_Status) EnumDescriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{3, 0} + return file_racing_racing_proto_rawDescGZIP(), []int{4, 0} } // Request for ListRaces call. @@ -124,6 +124,53 @@ func (x *ListRacesRequest) GetOrderBy() string { return "" } +type GetRaceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetRaceRequest) Reset() { + *x = GetRaceRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_racing_racing_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRaceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRaceRequest) ProtoMessage() {} + +func (x *GetRaceRequest) ProtoReflect() protoreflect.Message { + mi := &file_racing_racing_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetRaceRequest.ProtoReflect.Descriptor instead. +func (*GetRaceRequest) Descriptor() ([]byte, []int) { + return file_racing_racing_proto_rawDescGZIP(), []int{1} +} + +func (x *GetRaceRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + // Response to ListRaces call. type ListRacesResponse struct { state protoimpl.MessageState @@ -136,7 +183,7 @@ type ListRacesResponse struct { func (x *ListRacesResponse) Reset() { *x = ListRacesResponse{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[1] + mi := &file_racing_racing_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -149,7 +196,7 @@ func (x *ListRacesResponse) String() string { func (*ListRacesResponse) ProtoMessage() {} func (x *ListRacesResponse) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[1] + mi := &file_racing_racing_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -162,7 +209,7 @@ func (x *ListRacesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListRacesResponse.ProtoReflect.Descriptor instead. func (*ListRacesResponse) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{1} + return file_racing_racing_proto_rawDescGZIP(), []int{2} } func (x *ListRacesResponse) GetRaces() []*Race { @@ -185,7 +232,7 @@ type ListRacesRequestFilter struct { func (x *ListRacesRequestFilter) Reset() { *x = ListRacesRequestFilter{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[2] + mi := &file_racing_racing_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -198,7 +245,7 @@ func (x *ListRacesRequestFilter) String() string { func (*ListRacesRequestFilter) ProtoMessage() {} func (x *ListRacesRequestFilter) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[2] + mi := &file_racing_racing_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -211,7 +258,7 @@ func (x *ListRacesRequestFilter) ProtoReflect() protoreflect.Message { // Deprecated: Use ListRacesRequestFilter.ProtoReflect.Descriptor instead. func (*ListRacesRequestFilter) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{2} + return file_racing_racing_proto_rawDescGZIP(), []int{3} } func (x *ListRacesRequestFilter) GetMeetingIds() []int64 { @@ -252,7 +299,7 @@ type Race struct { func (x *Race) Reset() { *x = Race{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[3] + mi := &file_racing_racing_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -265,7 +312,7 @@ func (x *Race) String() string { func (*Race) ProtoMessage() {} func (x *Race) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[3] + mi := &file_racing_racing_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -278,7 +325,7 @@ func (x *Race) ProtoReflect() protoreflect.Message { // Deprecated: Use Race.ProtoReflect.Descriptor instead. func (*Race) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{3} + return file_racing_racing_proto_rawDescGZIP(), []int{4} } func (x *Race) GetId() int64 { @@ -346,42 +393,49 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x52, 0x06, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x88, 0x01, 0x01, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x6f, 0x72, 0x64, - 0x65, 0x72, 0x5f, 0x62, 0x79, 0x22, 0x37, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, - 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x72, 0x61, - 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x72, 0x61, 0x63, 0x69, - 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, 0x52, 0x05, 0x72, 0x61, 0x63, 0x65, 0x73, 0x22, 0x64, - 0x0a, 0x16, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, 0x65, 0x74, - 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, 0x52, 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, 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, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, - 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, - 0x6c, 0x65, 0x12, 0x4e, 0x0a, 0x15, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, - 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 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, 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, + 0x65, 0x72, 0x5f, 0x62, 0x79, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x63, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x37, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, + 0x72, 0x61, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x72, 0x61, + 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, 0x52, 0x05, 0x72, 0x61, 0x63, 0x65, 0x73, + 0x22, 0x64, 0x0a, 0x16, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, + 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, 0x52, + 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, 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, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, + 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, + 0x69, 0x62, 0x6c, 0x65, 0x12, 0x4e, 0x0a, 0x15, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, + 0x65, 0x64, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, + 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, 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, 0xad, 0x01, 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, 0x12, 0x46, 0x0a, 0x07, 0x47, 0x65, 0x74, + 0x52, 0x61, 0x63, 0x65, 0x12, 0x16, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x47, 0x65, + 0x74, 0x52, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x72, + 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x7b, 0x69, 0x64, + 0x7d, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -397,24 +451,27 @@ func file_racing_racing_proto_rawDescGZIP() []byte { } 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_msgTypes = make([]protoimpl.MessageInfo, 5) var file_racing_racing_proto_goTypes = []interface{}{ (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 + (*GetRaceRequest)(nil), // 2: racing.GetRaceRequest + (*ListRacesResponse)(nil), // 3: racing.ListRacesResponse + (*ListRacesRequestFilter)(nil), // 4: racing.ListRacesRequestFilter + (*Race)(nil), // 5: racing.Race + (*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp } var file_racing_racing_proto_depIdxs = []int32{ - 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 + 4, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter + 5, // 1: racing.ListRacesResponse.races:type_name -> racing.Race + 6, // 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 + 2, // 5: racing.Racing.GetRace:input_type -> racing.GetRaceRequest + 3, // 6: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse + 5, // 7: racing.Racing.GetRace:output_type -> racing.Race + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] 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 @@ -439,7 +496,7 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListRacesResponse); i { + switch v := v.(*GetRaceRequest); i { case 0: return &v.state case 1: @@ -451,7 +508,7 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListRacesRequestFilter); i { + switch v := v.(*ListRacesResponse); i { case 0: return &v.state case 1: @@ -463,6 +520,18 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListRacesRequestFilter); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_racing_racing_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Race); i { case 0: return &v.state @@ -476,14 +545,14 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[0].OneofWrappers = []interface{}{} - file_racing_racing_proto_msgTypes[2].OneofWrappers = []interface{}{} + file_racing_racing_proto_msgTypes[3].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_racing_racing_proto_rawDesc, NumEnums: 1, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/api/proto/racing/racing.pb.gw.go b/api/proto/racing/racing.pb.gw.go index 337b288..b579ac4 100644 --- a/api/proto/racing/racing.pb.gw.go +++ b/api/proto/racing/racing.pb.gw.go @@ -65,6 +65,58 @@ func local_request_Racing_ListRaces_0(ctx context.Context, marshaler runtime.Mar } +func request_Racing_GetRace_0(ctx context.Context, marshaler runtime.Marshaler, client RacingClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetRaceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.GetRace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Racing_GetRace_0(ctx context.Context, marshaler runtime.Marshaler, server RacingServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetRaceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.GetRace(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterRacingHandlerServer registers the http handlers for service Racing to "mux". // UnaryRPC :call RacingServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -94,6 +146,29 @@ func RegisterRacingHandlerServer(ctx context.Context, mux *runtime.ServeMux, ser }) + mux.Handle("GET", pattern_Racing_GetRace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/racing.Racing/GetRace", runtime.WithHTTPPathPattern("/v1/race/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Racing_GetRace_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Racing_GetRace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -155,13 +230,37 @@ func RegisterRacingHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli }) + mux.Handle("GET", pattern_Racing_GetRace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/racing.Racing/GetRace", runtime.WithHTTPPathPattern("/v1/race/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Racing_GetRace_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Racing_GetRace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Racing_ListRaces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "list-races"}, "")) + + pattern_Racing_GetRace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "race", "id"}, "")) ) var ( forward_Racing_ListRaces_0 = runtime.ForwardResponseMessage + + forward_Racing_GetRace_0 = runtime.ForwardResponseMessage ) diff --git a/api/proto/racing/racing.proto b/api/proto/racing/racing.proto index 6f3210b..f04ad2a 100644 --- a/api/proto/racing/racing.proto +++ b/api/proto/racing/racing.proto @@ -11,6 +11,9 @@ service Racing { rpc ListRaces(ListRacesRequest) returns (ListRacesResponse) { option (google.api.http) = { post: "/v1/list-races", body: "*" }; } + rpc GetRace(GetRaceRequest) returns (Race) { + option (google.api.http) = { get: "/v1/race/{id}" }; + } } /* Requests/Responses */ @@ -21,6 +24,10 @@ message ListRacesRequest { optional string order_by = 2; } +message GetRaceRequest { + int64 id = 1; +} + // Response to ListRaces call. message ListRacesResponse { repeated Race races = 1; diff --git a/api/proto/racing/racing_grpc.pb.go b/api/proto/racing/racing_grpc.pb.go index 6325105..5d45f70 100644 --- a/api/proto/racing/racing_grpc.pb.go +++ b/api/proto/racing/racing_grpc.pb.go @@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion7 type RacingClient interface { // ListRaces returns a list of all races. ListRaces(ctx context.Context, in *ListRacesRequest, opts ...grpc.CallOption) (*ListRacesResponse, error) + GetRace(ctx context.Context, in *GetRaceRequest, opts ...grpc.CallOption) (*Race, error) } type racingClient struct { @@ -39,12 +40,22 @@ func (c *racingClient) ListRaces(ctx context.Context, in *ListRacesRequest, opts return out, nil } +func (c *racingClient) GetRace(ctx context.Context, in *GetRaceRequest, opts ...grpc.CallOption) (*Race, error) { + out := new(Race) + err := c.cc.Invoke(ctx, "/racing.Racing/GetRace", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // RacingServer is the server API for Racing service. // All implementations must embed UnimplementedRacingServer // for forward compatibility type RacingServer interface { // ListRaces returns a list of all races. ListRaces(context.Context, *ListRacesRequest) (*ListRacesResponse, error) + GetRace(context.Context, *GetRaceRequest) (*Race, error) mustEmbedUnimplementedRacingServer() } @@ -55,6 +66,9 @@ type UnimplementedRacingServer struct { func (UnimplementedRacingServer) ListRaces(context.Context, *ListRacesRequest) (*ListRacesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListRaces not implemented") } +func (UnimplementedRacingServer) GetRace(context.Context, *GetRaceRequest) (*Race, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetRace not implemented") +} func (UnimplementedRacingServer) mustEmbedUnimplementedRacingServer() {} // UnsafeRacingServer may be embedded to opt out of forward compatibility for this service. @@ -86,6 +100,24 @@ func _Racing_ListRaces_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Racing_GetRace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRaceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RacingServer).GetRace(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/racing.Racing/GetRace", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RacingServer).GetRace(ctx, req.(*GetRaceRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Racing_ServiceDesc is the grpc.ServiceDesc for Racing service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -97,6 +129,10 @@ var Racing_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListRaces", Handler: _Racing_ListRaces_Handler, }, + { + MethodName: "GetRace", + Handler: _Racing_GetRace_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "racing/racing.proto", diff --git a/racing/db/queries.go b/racing/db/queries.go index f8bd7a1..e401d8a 100644 --- a/racing/db/queries.go +++ b/racing/db/queries.go @@ -2,6 +2,7 @@ package db const ( racesList = "list" + getRace = "get" ) func getRaceQueries() map[string]string { @@ -16,5 +17,16 @@ func getRaceQueries() map[string]string { advertised_start_time FROM races `, + getRace: ` + SELECT + id, + meeting_id, + name, + number, + visible, + advertised_start_time + FROM races + WHERE id = ? + `, } } diff --git a/racing/db/races.go b/racing/db/races.go index dd02650..fb21a58 100644 --- a/racing/db/races.go +++ b/racing/db/races.go @@ -21,6 +21,7 @@ type RacesRepo interface { // List will return a list of races. List(request *racing.ListRacesRequest) ([]*racing.Race, error) + Get(request *racing.GetRaceRequest) (*racing.Race, error) } type racesRepo struct { @@ -64,6 +65,30 @@ func (r *racesRepo) List(request *racing.ListRacesRequest) ([]*racing.Race, erro return r.scanRaces(rows) } +func (r *racesRepo) Get(request *racing.GetRaceRequest) (*racing.Race, error) { + var ( + query string + args []interface{} + ) + + query = getRaceQueries()[getRace] + + args = append(args, request.Id) + rows, err := r.db.Query(query, args...) + if err != nil { + return nil, err + } + + races, err := r.scanRaces(rows) + if err != nil { + return nil, err + } else if len(races) == 0 { + return nil, sql.ErrNoRows + } else { + return races[0], nil + } +} + func (r *racesRepo) applyFilter(query string, filter *racing.ListRacesRequestFilter) (string, []interface{}) { var ( clauses []string diff --git a/racing/proto/racing/racing.pb.go b/racing/proto/racing/racing.pb.go index 02495d3..7478213 100644 --- a/racing/proto/racing/racing.pb.go +++ b/racing/proto/racing/racing.pb.go @@ -64,7 +64,7 @@ func (x Race_Status) Number() protoreflect.EnumNumber { // Deprecated: Use Race_Status.Descriptor instead. func (Race_Status) EnumDescriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{3, 0} + return file_racing_racing_proto_rawDescGZIP(), []int{4, 0} } type ListRacesRequest struct { @@ -122,6 +122,53 @@ func (x *ListRacesRequest) GetOrderBy() string { return "" } +type GetRaceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetRaceRequest) Reset() { + *x = GetRaceRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_racing_racing_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRaceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRaceRequest) ProtoMessage() {} + +func (x *GetRaceRequest) ProtoReflect() protoreflect.Message { + mi := &file_racing_racing_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetRaceRequest.ProtoReflect.Descriptor instead. +func (*GetRaceRequest) Descriptor() ([]byte, []int) { + return file_racing_racing_proto_rawDescGZIP(), []int{1} +} + +func (x *GetRaceRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + // Response to ListRaces call. type ListRacesResponse struct { state protoimpl.MessageState @@ -134,7 +181,7 @@ type ListRacesResponse struct { func (x *ListRacesResponse) Reset() { *x = ListRacesResponse{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[1] + mi := &file_racing_racing_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -147,7 +194,7 @@ func (x *ListRacesResponse) String() string { func (*ListRacesResponse) ProtoMessage() {} func (x *ListRacesResponse) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[1] + mi := &file_racing_racing_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -160,7 +207,7 @@ func (x *ListRacesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListRacesResponse.ProtoReflect.Descriptor instead. func (*ListRacesResponse) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{1} + return file_racing_racing_proto_rawDescGZIP(), []int{2} } func (x *ListRacesResponse) GetRaces() []*Race { @@ -183,7 +230,7 @@ type ListRacesRequestFilter struct { func (x *ListRacesRequestFilter) Reset() { *x = ListRacesRequestFilter{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[2] + mi := &file_racing_racing_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -196,7 +243,7 @@ func (x *ListRacesRequestFilter) String() string { func (*ListRacesRequestFilter) ProtoMessage() {} func (x *ListRacesRequestFilter) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[2] + mi := &file_racing_racing_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -209,7 +256,7 @@ func (x *ListRacesRequestFilter) ProtoReflect() protoreflect.Message { // Deprecated: Use ListRacesRequestFilter.ProtoReflect.Descriptor instead. func (*ListRacesRequestFilter) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{2} + return file_racing_racing_proto_rawDescGZIP(), []int{3} } func (x *ListRacesRequestFilter) GetMeetingIds() []int64 { @@ -250,7 +297,7 @@ type Race struct { func (x *Race) Reset() { *x = Race{} if protoimpl.UnsafeEnabled { - mi := &file_racing_racing_proto_msgTypes[3] + mi := &file_racing_racing_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -263,7 +310,7 @@ func (x *Race) String() string { func (*Race) ProtoMessage() {} func (x *Race) ProtoReflect() protoreflect.Message { - mi := &file_racing_racing_proto_msgTypes[3] + mi := &file_racing_racing_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -276,7 +323,7 @@ func (x *Race) ProtoReflect() protoreflect.Message { // Deprecated: Use Race.ProtoReflect.Descriptor instead. func (*Race) Descriptor() ([]byte, []int) { - return file_racing_racing_proto_rawDescGZIP(), []int{3} + return file_racing_racing_proto_rawDescGZIP(), []int{4} } func (x *Race) GetId() int64 { @@ -342,41 +389,46 @@ var file_racing_racing_proto_rawDesc = []byte{ 0x65, 0x72, 0x52, 0x06, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x88, 0x01, 0x01, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x6f, - 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x22, 0x37, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x52, - 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, - 0x72, 0x61, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x72, 0x61, - 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, 0x52, 0x05, 0x72, 0x61, 0x63, 0x65, 0x73, - 0x22, 0x64, 0x0a, 0x16, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, - 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, 0x52, - 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, 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, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, - 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, - 0x69, 0x62, 0x6c, 0x65, 0x12, 0x4e, 0x0a, 0x15, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, - 0x65, 0x64, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, - 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, 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, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, + 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x37, 0x0a, 0x11, 0x4c, 0x69, 0x73, + 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, + 0x0a, 0x05, 0x72, 0x61, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, + 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, 0x63, 0x65, 0x52, 0x05, 0x72, 0x61, 0x63, + 0x65, 0x73, 0x22, 0x64, 0x0a, 0x16, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x61, 0x63, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, + 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x03, 0x52, 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, 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, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, + 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, + 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x4e, 0x0a, 0x15, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, + 0x69, 0x73, 0x65, 0x64, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, + 0x06, 0x20, 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, 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, 0x7f, 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, 0x12, 0x31, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x52, 0x61, 0x63, 0x65, 0x12, 0x16, 0x2e, 0x72, + 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x61, + 0x63, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x72, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -392,24 +444,27 @@ func file_racing_racing_proto_rawDescGZIP() []byte { } 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_msgTypes = make([]protoimpl.MessageInfo, 5) var file_racing_racing_proto_goTypes = []interface{}{ (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 + (*GetRaceRequest)(nil), // 2: racing.GetRaceRequest + (*ListRacesResponse)(nil), // 3: racing.ListRacesResponse + (*ListRacesRequestFilter)(nil), // 4: racing.ListRacesRequestFilter + (*Race)(nil), // 5: racing.Race + (*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp } var file_racing_racing_proto_depIdxs = []int32{ - 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 + 4, // 0: racing.ListRacesRequest.filter:type_name -> racing.ListRacesRequestFilter + 5, // 1: racing.ListRacesResponse.races:type_name -> racing.Race + 6, // 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 + 2, // 5: racing.Racing.GetRace:input_type -> racing.GetRaceRequest + 3, // 6: racing.Racing.ListRaces:output_type -> racing.ListRacesResponse + 5, // 7: racing.Racing.GetRace:output_type -> racing.Race + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] 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 @@ -434,7 +489,7 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListRacesResponse); i { + switch v := v.(*GetRaceRequest); i { case 0: return &v.state case 1: @@ -446,7 +501,7 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListRacesRequestFilter); i { + switch v := v.(*ListRacesResponse); i { case 0: return &v.state case 1: @@ -458,6 +513,18 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListRacesRequestFilter); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_racing_racing_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Race); i { case 0: return &v.state @@ -471,14 +538,14 @@ func file_racing_racing_proto_init() { } } file_racing_racing_proto_msgTypes[0].OneofWrappers = []interface{}{} - file_racing_racing_proto_msgTypes[2].OneofWrappers = []interface{}{} + file_racing_racing_proto_msgTypes[3].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_racing_racing_proto_rawDesc, NumEnums: 1, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/racing/proto/racing/racing.proto b/racing/proto/racing/racing.proto index 562c9af..c0974d7 100644 --- a/racing/proto/racing/racing.proto +++ b/racing/proto/racing/racing.proto @@ -8,6 +8,7 @@ import "google/protobuf/timestamp.proto"; service Racing { // ListRaces will return a collection of all races. rpc ListRaces(ListRacesRequest) returns (ListRacesResponse) {} + rpc GetRace(GetRaceRequest) returns (Race) {} } /* Requests/Responses */ @@ -17,6 +18,10 @@ message ListRacesRequest { optional string order_by = 2; } +message GetRaceRequest { + int64 id = 1; +} + // Response to ListRaces call. message ListRacesResponse { repeated Race races = 1; diff --git a/racing/proto/racing/racing_grpc.pb.go b/racing/proto/racing/racing_grpc.pb.go index 44b6818..133c23a 100644 --- a/racing/proto/racing/racing_grpc.pb.go +++ b/racing/proto/racing/racing_grpc.pb.go @@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion7 type RacingClient interface { // ListRaces will return a collection of all races. ListRaces(ctx context.Context, in *ListRacesRequest, opts ...grpc.CallOption) (*ListRacesResponse, error) + GetRace(ctx context.Context, in *GetRaceRequest, opts ...grpc.CallOption) (*Race, error) } type racingClient struct { @@ -39,12 +40,22 @@ func (c *racingClient) ListRaces(ctx context.Context, in *ListRacesRequest, opts return out, nil } +func (c *racingClient) GetRace(ctx context.Context, in *GetRaceRequest, opts ...grpc.CallOption) (*Race, error) { + out := new(Race) + err := c.cc.Invoke(ctx, "/racing.Racing/GetRace", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // RacingServer is the server API for Racing service. // All implementations should embed UnimplementedRacingServer // for forward compatibility type RacingServer interface { // ListRaces will return a collection of all races. ListRaces(context.Context, *ListRacesRequest) (*ListRacesResponse, error) + GetRace(context.Context, *GetRaceRequest) (*Race, error) } // UnimplementedRacingServer should be embedded to have forward compatible implementations. @@ -54,6 +65,9 @@ type UnimplementedRacingServer struct { func (UnimplementedRacingServer) ListRaces(context.Context, *ListRacesRequest) (*ListRacesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListRaces not implemented") } +func (UnimplementedRacingServer) GetRace(context.Context, *GetRaceRequest) (*Race, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetRace not implemented") +} // UnsafeRacingServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to RacingServer will @@ -84,6 +98,24 @@ func _Racing_ListRaces_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Racing_GetRace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRaceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RacingServer).GetRace(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/racing.Racing/GetRace", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RacingServer).GetRace(ctx, req.(*GetRaceRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Racing_ServiceDesc is the grpc.ServiceDesc for Racing service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -95,6 +127,10 @@ var Racing_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListRaces", Handler: _Racing_ListRaces_Handler, }, + { + MethodName: "GetRace", + Handler: _Racing_GetRace_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "racing/racing.proto", diff --git a/racing/service/racing.go b/racing/service/racing.go index 56a2071..5eb8a0e 100644 --- a/racing/service/racing.go +++ b/racing/service/racing.go @@ -9,6 +9,7 @@ import ( type Racing interface { // ListRaces will return a collection of races. ListRaces(ctx context.Context, in *racing.ListRacesRequest) (*racing.ListRacesResponse, error) + GetRace(ctx context.Context, in *racing.GetRaceRequest) (*racing.Race, error) } // racingService implements the Racing interface. @@ -29,3 +30,11 @@ func (s *racingService) ListRaces(ctx context.Context, in *racing.ListRacesReque return &racing.ListRacesResponse{Races: races}, nil } + +func (s *racingService) GetRace(ctx context.Context, in *racing.GetRaceRequest) (*racing.Race, error) { + race, err := s.racesRepo.Get(in) + if err != nil { + return nil, err + } + return race, nil +} diff --git a/racing/test/races_test.go b/racing/test/races_test.go new file mode 100644 index 0000000..cfa7bf4 --- /dev/null +++ b/racing/test/races_test.go @@ -0,0 +1,16 @@ +package db_test + +import ( + "regexp" + "testing" +) + +// TestHelloName calls greetings.Hello with a name, checking +// for a valid return value. +func TestOrderBySingle(t *testing.T) { + out, err := ValidateOrderBy("foo asc") + want := regexp.MustCompile("foo") + if !want.MatchString(out[0]) || err != nil { + t.Fatalf(`validateOrderBy("foo asc") = %q, %v, want match for %#q, nil`, out, err, want) + } +} From 6f30ded7a3b1a0c26aedd9a4ea6e9a9a8ffbc363 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Tue, 17 Aug 2021 22:58:17 +1000 Subject: [PATCH 2/7] =?UTF-8?q?=E2=80=A2=20Removed=20races=5Ftest=20for=20?= =?UTF-8?q?now.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/test/races_test.go | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 racing/test/races_test.go diff --git a/racing/test/races_test.go b/racing/test/races_test.go deleted file mode 100644 index cfa7bf4..0000000 --- a/racing/test/races_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package db_test - -import ( - "regexp" - "testing" -) - -// TestHelloName calls greetings.Hello with a name, checking -// for a valid return value. -func TestOrderBySingle(t *testing.T) { - out, err := ValidateOrderBy("foo asc") - want := regexp.MustCompile("foo") - if !want.MatchString(out[0]) || err != nil { - t.Fatalf(`validateOrderBy("foo asc") = %q, %v, want match for %#q, nil`, out, err, want) - } -} From 99a58de460ff17fda9a6a89f9c4b90389b024349 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Wed, 18 Aug 2021 14:18:18 +1000 Subject: [PATCH 3/7] =?UTF-8?q?racing.proto:=20=E2=80=A2=20Describe=20`id`?= =?UTF-8?q?=20parameter.=20races.go:=20=E2=80=A2=20Describe=20return=20val?= =?UTF-8?q?ue=20for=20Get=20function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/proto/racing/racing.proto | 1 + racing/db/races.go | 2 ++ racing/proto/racing/racing.proto | 1 + racing/service/racing.go | 1 + 4 files changed, 5 insertions(+) diff --git a/api/proto/racing/racing.proto b/api/proto/racing/racing.proto index b06f13a..858150a 100644 --- a/api/proto/racing/racing.proto +++ b/api/proto/racing/racing.proto @@ -26,6 +26,7 @@ message ListRacesRequest { } message GetRaceRequest { + // The unique id of the race. int64 id = 1; } diff --git a/racing/db/races.go b/racing/db/races.go index fb21a58..8140211 100644 --- a/racing/db/races.go +++ b/racing/db/races.go @@ -83,8 +83,10 @@ func (r *racesRepo) Get(request *racing.GetRaceRequest) (*racing.Race, error) { if err != nil { return nil, err } else if len(races) == 0 { + // No race found, return error. return nil, sql.ErrNoRows } else { + // Race found, return single race. return races[0], nil } } diff --git a/racing/proto/racing/racing.proto b/racing/proto/racing/racing.proto index 5338df7..19df48d 100644 --- a/racing/proto/racing/racing.proto +++ b/racing/proto/racing/racing.proto @@ -20,6 +20,7 @@ message ListRacesRequest { } message GetRaceRequest { + // The unique id of the race. int64 id = 1; } diff --git a/racing/service/racing.go b/racing/service/racing.go index 5eb8a0e..af0056f 100644 --- a/racing/service/racing.go +++ b/racing/service/racing.go @@ -31,6 +31,7 @@ func (s *racingService) ListRaces(ctx context.Context, in *racing.ListRacesReque return &racing.ListRacesResponse{Races: races}, nil } +// Retrieves a single race by its identifier, or, returns an error. func (s *racingService) GetRace(ctx context.Context, in *racing.GetRaceRequest) (*racing.Race, error) { race, err := s.racesRepo.Get(in) if err != nil { From 2764989e4cb37bdae63a7956c41f680ca47f1deb Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Wed, 18 Aug 2021 14:20:32 +1000 Subject: [PATCH 4/7] =?UTF-8?q?racing.proto:=20=E2=80=A2=20Provide=20comme?= =?UTF-8?q?nt=20for=20GetRaceRequest=20use=20case.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/proto/racing/racing.proto | 1 + racing/proto/racing/racing.proto | 1 + 2 files changed, 2 insertions(+) diff --git a/api/proto/racing/racing.proto b/api/proto/racing/racing.proto index 858150a..54e9620 100644 --- a/api/proto/racing/racing.proto +++ b/api/proto/racing/racing.proto @@ -25,6 +25,7 @@ message ListRacesRequest { optional string order_by = 2; } +// Request for GetRace call. message GetRaceRequest { // The unique id of the race. int64 id = 1; diff --git a/racing/proto/racing/racing.proto b/racing/proto/racing/racing.proto index 19df48d..cb85579 100644 --- a/racing/proto/racing/racing.proto +++ b/racing/proto/racing/racing.proto @@ -19,6 +19,7 @@ message ListRacesRequest { optional string order_by = 2; } +// Request for GetRace call. message GetRaceRequest { // The unique id of the race. int64 id = 1; From 565df1ac3ad325605d4ceb951a862039fda83204 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 21:31:46 +1000 Subject: [PATCH 5/7] =?UTF-8?q?races=5Ftest:=20=E2=80=A2=20Added=20test=20?= =?UTF-8?q?case=20for=20`Get`=20request.=20races.go:=20=E2=80=A2=20Fixed?= =?UTF-8?q?=20compilation=20error=20due=20to=20bad=20merge.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/db/races.go | 2 ++ racing/db/races_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/racing/db/races.go b/racing/db/races.go index a3b3922..e7f40ac 100644 --- a/racing/db/races.go +++ b/racing/db/races.go @@ -100,6 +100,8 @@ func (r *racesRepo) Get(request *racing.GetRaceRequest) (*racing.Race, error) { // Race found, return single race. return races[0], nil } +} + func (r *racesRepo) ListAll() ([]*racing.Race, error) { return r.listAll() } diff --git a/racing/db/races_test.go b/racing/db/races_test.go index c710dd4..78f6697 100644 --- a/racing/db/races_test.go +++ b/racing/db/races_test.go @@ -304,6 +304,43 @@ func TestStatusField(t *testing.T) { } } +func TestGetRaceRequest(t *testing.T) { + racingDB, err := GetTestDB("db", "TestGetRaceRequest") + 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) + } + + rq := racing.GetRaceRequest{Id: race2.Id} + rsp, err := racesRepo.Get(&rq) + if err != nil { + t.Fatalf("Unable to retrieve individual race %v", rq.Id) + } + if rsp.Name != race2.Name { + t.Fatalf("Invalid race returned %v", rsp.Id) + } +} + // Helpers // func GetRaces() []*racing.Race { From 98641d2b5c12abfdf71b46cea7a73dd6e1e53838 Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 23:33:25 +1000 Subject: [PATCH 6/7] =?UTF-8?q?racing/proto/README.md:=20=E2=80=A2=20Docum?= =?UTF-8?q?ent=20introduction=20of=20`GetRace`=20rpc=20call.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racing/proto/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/racing/proto/README.md b/racing/proto/README.md index e7d0c5e..863afc8 100644 --- a/racing/proto/README.md +++ b/racing/proto/README.md @@ -6,11 +6,15 @@ This defines the protobuf message types for the racing API. **RPCS** - `ListRaces(ListRacesRequest) ListRacesResponse` +- `GetRace(GetRaceRequest) Race` ### ListRacesRequest - Supports a filter parameter of type `ListRacesRequestFilter`. - Supports a order_by parameter of the form defined by [Google API Design](https://cloud.google.com/apis/design/design_patterns#sorting_order). +### GetRaceRequest +- The ID of the race to be retrieved (int64). + ### ListRacesRequestFilter - A list of integer IDs can be supplied to perform a bulk lookup request. (optional) - A category filter can be supplied which finds any races which match the category (optional, case-insensitive). From f197b845cc4d61eada88cb9d160f7816b6eadf5c Mon Sep 17 00:00:00 2001 From: "ASHLEYDESKTOP\\Ashley" Date: Thu, 19 Aug 2021 23:48:47 +1000 Subject: [PATCH 7/7] =?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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/racing/db/races_test.go b/racing/db/races_test.go index 78f6697..ec1ae1b 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) } @@ -305,7 +305,7 @@ func TestStatusField(t *testing.T) { } func TestGetRaceRequest(t *testing.T) { - racingDB, err := GetTestDB("db", "TestGetRaceRequest") + racingDB, err := GetTestDB("races", "TestGetRaceRequest") if err != nil { t.Fatalf("Failed to open testdb %v", err) }