Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2022-10-20 22:40:54 +0900 #217

Merged
merged 14 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added client/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/logo256.ico
Binary file not shown.
Binary file added client/public/ogp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion client/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { FC } from "react";
import Link from "next/link";
import Image from "next/image";

const Header: FC<{}> = () => {
return (
<header>
<h1>調布競馬ポータル</h1>
<h1>
<Image
src="/logo.png"
alt="調布競馬"
height="48px"
width="220.8px"
/>
</h1>
<nav>
<ul>
<li>
Expand Down
3 changes: 3 additions & 0 deletions client/src/pages/horse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const HorsePage: FC<Props> = ({ json }) => {
<>
<Head>
<title>競争馬一覧 | 調布競馬ポータル</title>
<link rel="icon" href="/logo256.ico" />
<meta name="og:image" content="/ogp.png" />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<h2>競争馬一覧</h2>
<ul>
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/horse/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const HorseDetailPage: FC<Props> = ({ json }) => {
<>
<Head>
<title>{`${horse.data!.name} | 調布競馬ポータル`}</title>
<link rel="icon" href="/logo256.ico" />
</Head>
<h2>{horse.data!.name}</h2>
{horse.image ? (
Expand Down
3 changes: 3 additions & 0 deletions client/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const TopPage: FC<{}> = () => {
<>
<Head>
<title>調布競馬ポータル</title>
<link rel="icon" href="/logo256.ico" />
<meta name="og:image" content="/ogp.png" />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<h2>開催情報</h2>
<p>
Expand Down
3 changes: 3 additions & 0 deletions client/src/pages/race.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const RacePage: FC<Props> = ({ json }) => {
<>
<Head>
<title>レース一覧 | 調布競馬ポータル</title>
<link rel="icon" href="/logo256.ico" />
<meta name="og:image" content="/ogp.png" />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<h2>レース一覧</h2>
<table>
Expand Down
3 changes: 3 additions & 0 deletions client/src/pages/race/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const RaceDetailPage: FC<Props> = ({ json }) => {
<>
<Head>
<title>{`${race.data!.name} | 調布競馬ポータル`}</title>
<link rel="icon" href="/logo256.ico" />
<meta name="og:image" content="/ogp.png" />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<h2>{`第${race.data!.order}競争 ${race.data!.name}`}</h2>
<p>{race.description}</p>
Expand Down
5 changes: 4 additions & 1 deletion client/src/pages/special/shinbao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const SpecialPage: FC<{}> = () => {
<>
<Head>
<title>新馬王戦 | 調布競馬ポータル</title>
<link rel="icon" href="/logo256.ico" />
<meta name="og:image" content="/ogp.png" />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<h2>新馬王戦</h2>
<h3>日程</h3>
Expand All @@ -129,7 +132,7 @@ const SpecialPage: FC<{}> = () => {
</tbody>
</table>
<h3>ランキング</h3>
<p>1日目終了時点</p>
<p>2日目終了時点</p>
<table>
<thead>
<tr>
Expand Down
6 changes: 3 additions & 3 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ module github.com/ueckoken/chofu-race-course/go
go 1.19

require (
github.com/bufbuild/connect-go v1.0.0
github.com/bufbuild/connect-go v1.1.0
github.com/caarlos0/env/v6 v6.10.1
github.com/envoyproxy/protoc-gen-validate v0.6.13
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/subcommands v1.2.0
github.com/rs/cors v1.8.2
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b
golang.org/x/net v0.1.0
google.golang.org/protobuf v1.28.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/bufbuild/connect-go v1.0.0 h1:htSflKUT8y1jxhoPhPYTZMrsY3ipUXjjrbcZR5O2cVo=
github.com/bufbuild/connect-go v1.0.0/go.mod h1:9iNvh/NOsfhNBUH5CtvXeVUskQO1xsrEviH7ZArwZ3I=
github.com/bufbuild/connect-go v1.1.0 h1:AUgqqO2ePdOJSpPOep6BPYz5v2moW1Lb8sQh0EeRzQ8=
github.com/bufbuild/connect-go v1.1.0/go.mod h1:9iNvh/NOsfhNBUH5CtvXeVUskQO1xsrEviH7ZArwZ3I=
github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II=
github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -252,6 +254,12 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221017152216-f25eb7ecb193 h1:3Moaxt4TfzNcQH6DWvlYKraN1ozhBXQHcgvXjRGeim0=
golang.org/x/net v0.0.0-20221017152216-f25eb7ecb193/go.mod h1:RpDiru2p0u2F0lLpEoqnP2+7xs0ifAuOcJ442g6GU2s=
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad h1:Zx6wVVDwwNJFWXNIvDi7o952w3/1ckSwYk/7eykRmjM=
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad/go.mod h1:RpDiru2p0u2F0lLpEoqnP2+7xs0ifAuOcJ442g6GU2s=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -320,6 +328,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
158 changes: 149 additions & 9 deletions go/pkg/handler/raceDataService.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package handler

import (
"context"
"errors"
"fmt"

connect_go "github.com/bufbuild/connect-go"
v1 "github.com/ueckoken/chofu-race-course/go/_proto/spec/v1"
"github.com/ueckoken/chofu-race-course/go/_proto/spec/v1/v1connect"

"github.com/ueckoken/chofu-race-course/go/pkg/authorizer"
)

Expand All @@ -20,6 +22,7 @@ type RaceStore interface {
GetAll() (*v1.RaceDetails, error)
GetByID(id uint32) (*v1.RaceDetail, error)
Create(*v1.RaceDetail) error
Update(*v1.RaceDetail) error
}

func NewRaceServer(store DataStore, adminauth authorizer.AdminAuthorizer) (*Race, error) {
Expand Down Expand Up @@ -47,6 +50,7 @@ func (r *Race) RaceData(_ context.Context, req *connect_go.Request[v1.RaceDataRe
}
return connect_go.NewResponse(&v1.RaceDataResponse{Race: rd}), nil
}

func (r *Race) RegisterRace(_ context.Context, req *connect_go.Request[v1.RegisterRaceRequest]) (*connect_go.Response[v1.RegisterRaceResponse], error) {
_, ok, err := r.adminAuth.Verify(req.Msg.GetAdminJwt().GetToken())
if err != nil {
Expand Down Expand Up @@ -78,16 +82,152 @@ func (r *Race) RegisterRace(_ context.Context, req *connect_go.Request[v1.Regist
return connect_go.NewResponse(&v1.RegisterRaceResponse{}), nil
}

func (r *Race) RegisterRaceResult(ctx context.Context, req *connect_go.Request[v1.RegisterRaceResultRequest]) (*connect_go.Response[v1.RegisterRaceResultResponse], error) {
_, ok, err := r.adminAuth.Verify(req.Msg.GetAdminJwt().GetToken())
if err != nil {
return nil, connect_go.NewError(connect_go.CodePermissionDenied, err)
}
if !ok {
return nil, connect_go.NewError(connect_go.CodePermissionDenied, fmt.Errorf("invalid jwt, maybe expired"))
}
if err := req.Msg.ValidateAll(); err != nil {
return nil, connect_go.NewError(connect_go.CodeInvalidArgument, err)
}
if len(req.Msg.GetMembers()) == 0 {
return nil, connect_go.NewError(connect_go.CodeInvalidArgument, fmt.Errorf("members array length 0 is nil"))
}
raceRec, err := r.store.Race.GetByID(req.Msg.GetId())
if err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, err)
}
raceRec.Members = req.Msg.GetMembers()
if err := r.store.Race.Update(raceRec); err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, err)
}

for i, horse := range req.Msg.GetMembers() {
hd, err := r.getFixHorseDetail(horse, raceRec)
if err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, fmt.Errorf("updateHorseDetail failed in `%d`, %w", i, err))
}
if err := r.store.Horse.Update(hd); err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, fmt.Errorf("horse update failed, %w", err))
}
}
return connect_go.NewResponse(&v1.RegisterRaceResultResponse{}), nil
}

func (r *Race) EditRace(ctx context.Context, req *connect_go.Request[v1.EditRaceRequest]) (*connect_go.Response[v1.EditRaceResponse], error) {
_, ok, err := r.adminAuth.Verify(req.Msg.GetAdminJwt().GetToken())
if err != nil {
return nil, connect_go.NewError(connect_go.CodePermissionDenied, err)
}
if !ok {
return nil, connect_go.NewError(connect_go.CodePermissionDenied, fmt.Errorf("invalid jwt, maybe expired"))
}
if err := req.Msg.ValidateAll(); err != nil {
return nil, connect_go.NewError(connect_go.CodeInvalidArgument, err)
}
oldRec, err := r.store.Race.GetByID(req.Msg.GetId())
if err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, err)
}

editFields := findFieldsToEdit(req.Msg)
if editFields&EditRaceRequestName != 0 {
oldRec.Data.Name = req.Msg.GetName()
}
if editFields&EditRaceRequestOrder != 0 {
oldRec.Data.Order = req.Msg.GetOrder()
}
if editFields&EditRaceRequestStart != 0 {
oldRec.Data.Start = req.Msg.GetStart()
}
if editFields&EditRaceRequestDescription != 0 {
oldRec.Description = req.Msg.GetDescription()
}
if editFields&EditRaceRequestMembers != 0 {
oldRec.Members = req.Msg.GetMembers()
}

if err := r.store.Race.Update(oldRec); err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, err)
}
return connect_go.NewResponse(&v1.EditRaceResponse{}), nil
}

type EditRaceRequestField int

const (
EditRaceRequestName EditRaceRequestField = 1 << iota
EditRaceRequestOrder EditRaceRequestField = 1 << iota
EditRaceRequestStart EditRaceRequestField = 1 << iota
EditRaceRequestDescription EditRaceRequestField = 1 << iota
EditRaceRequestMembers EditRaceRequestField = 1 << iota
)

func findFieldsToEdit(req *v1.EditRaceRequest) EditRaceRequestField {
var res EditRaceRequestField
if req.GetName() != "" {
res |= EditRaceRequestName
}
if req.GetOrder() != 0 {
res |= EditRaceRequestOrder
}
if req.GetStart() != nil {
res |= EditRaceRequestStart
}
if req.GetDescription() != "" {
res |= EditRaceRequestDescription
}
if len(req.Members) != 0 {
res |= EditRaceRequestMembers
}
return res
}

func raceDetail2Race(rd *v1.RaceDetail) *v1.Race {
return &v1.Race{
Id: rd.GetData().GetId(),
Name: rd.GetData().GetName(),
Order: rd.GetData().GetOrder(),
Start: rd.GetData().GetStart(),
IsFinished: rd.GetData().GetIsFinished(),
}
}
func raceDetails2Races(rds []*v1.RaceDetail) []*v1.Race {
rs := []*v1.Race{}
for _, rd := range rds {
rs = append(rs, &v1.Race{
Id: rd.GetData().GetId(),
Name: rd.GetData().GetName(),
Order: rd.GetData().GetOrder(),
Start: rd.GetData().GetStart(),
IsFinished: rd.GetData().GetIsFinished(),
})
rs := make([]*v1.Race, len(rds))
for i, rd := range rds {
rs[i] = raceDetail2Race(rd)
}
return rs
}

func (r *Race) getFixHorseDetail(horse *v1.RaceDetail_Member, rd *v1.RaceDetail) (*v1.HorseDetail, error) {
hd, err := r.store.Horse.GetByID(horse.GetHorse().GetId())
if err != nil {
return nil, connect_go.NewError(connect_go.CodeInternal, err)
}
switch o := horse.GetOrder().GetOrderOneof().(type) {
case *v1.RaceOrder_Order:
if o.Order == 1 {
hd.Wins++
}
if 1 <= o.Order && o.Order <= 4 {
hd.Matches++
}
case *v1.RaceOrder_Note:
if o.Note == v1.RaceOrder_NOTE_TYPE_GIVEUP {
hd.Matches++
}
default:
return nil, connect_go.NewError(connect_go.CodeAlreadyExists, errors.New("hoge"))
}
hd.Histories = append(hd.Histories, &v1.HorseDetail_History{
Race: raceDetail2Race(rd),
// このOrderはレースが第nレースかを表現
Order: rd.GetData().GetOrder(),
Result: horse.GetOrder(),
})
return hd, nil
}
2 changes: 1 addition & 1 deletion manifests/manifests/api-server/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
name: database
containers:
- name: api
image: ghcr.io/ueckoken/chofu-race-course-api:7c76d9f-1665538321 # {"$imagepolicy": "flux-system:api"}
image: ghcr.io/ueckoken/chofu-race-course-api:a70d761-1665932138 # {"$imagepolicy": "flux-system:api"}
ports:
- containerPort: 8080
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion manifests/manifests/helm/cert-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
chart: cert-manager
reconcileStrategy: ChartVersion
version: 1.9.1
version: v1.10.0
sourceRef:
kind: HelmRepository
name: jetstack
Expand Down
2 changes: 1 addition & 1 deletion manifests/manifests/nextjs/next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
spec:
containers:
- name: webapp
image: ghcr.io/ueckoken/chofu-race-course-webapp:7c76d9f-1665538321 # {"$imagepolicy": "flux-system:webapp"}
image: ghcr.io/ueckoken/chofu-race-course-webapp:a70d761-1665932134 # {"$imagepolicy": "flux-system:webapp"}
ports:
- containerPort: 3000
---
Expand Down