Skip to content

Commit

Permalink
Merge pull request #249 from ueckoken/add-connect-handler
Browse files Browse the repository at this point in the history
Add connect handler
  • Loading branch information
csenet authored Nov 21, 2023
2 parents 212248c + 81cec08 commit 6c254a2
Show file tree
Hide file tree
Showing 26 changed files with 3,000 additions and 126 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/create-proto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
# - name: Set up Node in ats
# uses: actions/setup-node@v4
# with:
# node-version: 20
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
working-directory: ./frontend/dashboard
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --immutable
working-directory: ./frontend/dashboard
- name: Set up Go
uses: actions/setup-go@v4
with:
Expand Down
136 changes: 68 additions & 68 deletions backend/spec/state/v1/statev1connect/state.connect.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion backend/state-manager/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog/v2"
"github.com/joho/godotenv"
"github.com/rs/cors"
"github.com/ueckoken/plarail2023/backend/spec/state/v1/statev1connect"
connectHandler "github.com/ueckoken/plarail2023/backend/state-manager/pkg/connect"
"github.com/ueckoken/plarail2023/backend/state-manager/pkg/db"
Expand Down Expand Up @@ -145,7 +146,7 @@ func main() {

srv := &http.Server{
Addr: net.JoinHostPort("0.0.0.0", "8080"),
Handler: h2c.NewHandler(r, &http2.Server{}),
Handler: cors.Default().Handler(h2c.NewHandler(r, &http2.Server{})),
ReadHeaderTimeout: 60 * time.Second,
BaseContext: func(net.Listener) context.Context { return ctx },
}
Expand Down
28 changes: 28 additions & 0 deletions frontend/dashboard/app/test/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";
import {createPromiseClient} from "@connectrpc/connect";
import {StateManagerService} from "@/proto/state/v1/state_connectweb";
import {createConnectTransport} from "@bufbuild/connect-web";
import {GetBlockStatesRequest} from "@/proto/state/v1/block_pb";

export default function Test() {

const transport = createConnectTransport(
{
// baseUrl: process.env.NEXT_PUBLIC_API_ENDPOINT!,
baseUrl: "http://localhost:8080",
});
const sendData = () => {
(async () => {
const client = createPromiseClient(StateManagerService, transport);
const res = await client.getBlockStates(new GetBlockStatesRequest({}));
console.log(res);
})();
}

return (
<div>
<h1>Test</h1>
<button onClick={sendData}>Test</button>
</div>
)
}
22 changes: 15 additions & 7 deletions frontend/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
"lint": "next lint"
},
"dependencies": {
"@bufbuild/connect-web": "^0.13.0",
"@bufbuild/protobuf": "^1.4.2",
"@connectrpc/connect": "^1.1.3",
"@connectrpc/connect-web": "^1.1.3",
"next": "14.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"next": "14.0.3"
"react-dom": "18.2.0"
},
"devDependencies": {
"typescript": "5.3.2",
"@types/node": "20.9.3",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.16"
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-connect-web": "^0.11.0",
"@bufbuild/protoc-gen-es": "^1.4.2",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"@types/node": "20.9.2",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"typescript": "5.2.2"
},
"files": [
".next/standalone",
".next/static",
"public"
]
}
}
163 changes: 163 additions & 0 deletions frontend/dashboard/proto/state/v1/block_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//
//Block Proto
//閉塞の状態を扱うプロトコル

// @generated by protoc-gen-es v1.4.2 with parameter "target=dts+js"
// @generated from file state/v1/block.proto (package state.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";

/**
* @generated from enum state.v1.BlockStateEnum
*/
export declare enum BlockStateEnum {
/**
* @generated from enum value: BLOCK_STATE_UNKNOWN = 0;
*/
BLOCK_STATE_UNKNOWN = 0,

/**
* 閉塞が開の状態(列車がいない)
*
* @generated from enum value: BLOCK_STATE_OPEN = 1;
*/
BLOCK_STATE_OPEN = 1,

/**
* 閉塞が閉の状態(列車がいない)
*
* @generated from enum value: BLOCK_STATE_CLOSE = 2;
*/
BLOCK_STATE_CLOSE = 2,
}

/**
* 閉塞の状態
*
* @generated from message state.v1.BlockState
*/
export declare class BlockState extends Message<BlockState> {
/**
* 閉塞のID
*
* @generated from field: string block_id = 1;
*/
blockId: string;

/**
* 閉塞の状態
*
* @generated from field: state.v1.BlockStateEnum state = 2;
*/
state: BlockStateEnum;

constructor(data?: PartialMessage<BlockState>);

static readonly runtime: typeof proto3;
static readonly typeName = "state.v1.BlockState";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): BlockState;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): BlockState;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): BlockState;

static equals(a: BlockState | PlainMessage<BlockState> | undefined, b: BlockState | PlainMessage<BlockState> | undefined): boolean;
}

/**
*
* GetBlockStates : 閉塞の状態を取得するAPI
*
* @generated from message state.v1.GetBlockStatesRequest
*/
export declare class GetBlockStatesRequest extends Message<GetBlockStatesRequest> {
constructor(data?: PartialMessage<GetBlockStatesRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "state.v1.GetBlockStatesRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetBlockStatesRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): GetBlockStatesRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): GetBlockStatesRequest;

static equals(a: GetBlockStatesRequest | PlainMessage<GetBlockStatesRequest> | undefined, b: GetBlockStatesRequest | PlainMessage<GetBlockStatesRequest> | undefined): boolean;
}

/**
* @generated from message state.v1.GetBlockStatesResponse
*/
export declare class GetBlockStatesResponse extends Message<GetBlockStatesResponse> {
/**
* @generated from field: repeated state.v1.BlockState states = 1;
*/
states: BlockState[];

constructor(data?: PartialMessage<GetBlockStatesResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "state.v1.GetBlockStatesResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetBlockStatesResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): GetBlockStatesResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): GetBlockStatesResponse;

static equals(a: GetBlockStatesResponse | PlainMessage<GetBlockStatesResponse> | undefined, b: GetBlockStatesResponse | PlainMessage<GetBlockStatesResponse> | undefined): boolean;
}

/**
*
* UpdateBLockState: 閉塞の状態を更新するAPI
*
* @generated from message state.v1.UpdateBlockStateRequest
*/
export declare class UpdateBlockStateRequest extends Message<UpdateBlockStateRequest> {
/**
* @generated from field: state.v1.BlockState state = 1;
*/
state?: BlockState;

constructor(data?: PartialMessage<UpdateBlockStateRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "state.v1.UpdateBlockStateRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): UpdateBlockStateRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): UpdateBlockStateRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): UpdateBlockStateRequest;

static equals(a: UpdateBlockStateRequest | PlainMessage<UpdateBlockStateRequest> | undefined, b: UpdateBlockStateRequest | PlainMessage<UpdateBlockStateRequest> | undefined): boolean;
}

/**
* @generated from message state.v1.UpdateBlockStateResponse
*/
export declare class UpdateBlockStateResponse extends Message<UpdateBlockStateResponse> {
constructor(data?: PartialMessage<UpdateBlockStateResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "state.v1.UpdateBlockStateResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): UpdateBlockStateResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): UpdateBlockStateResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): UpdateBlockStateResponse;

static equals(a: UpdateBlockStateResponse | PlainMessage<UpdateBlockStateResponse> | undefined, b: UpdateBlockStateResponse | PlainMessage<UpdateBlockStateResponse> | undefined): boolean;
}

78 changes: 78 additions & 0 deletions frontend/dashboard/proto/state/v1/block_pb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
//Block Proto
//閉塞の状態を扱うプロトコル

// @generated by protoc-gen-es v1.4.2 with parameter "target=dts+js"
// @generated from file state/v1/block.proto (package state.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { proto3 } from "@bufbuild/protobuf";

/**
* @generated from enum state.v1.BlockStateEnum
*/
export const BlockStateEnum = proto3.makeEnum(
"state.v1.BlockStateEnum",
[
{no: 0, name: "BLOCK_STATE_UNKNOWN"},
{no: 1, name: "BLOCK_STATE_OPEN"},
{no: 2, name: "BLOCK_STATE_CLOSE"},
],
);

/**
* 閉塞の状態
*
* @generated from message state.v1.BlockState
*/
export const BlockState = proto3.makeMessageType(
"state.v1.BlockState",
() => [
{ no: 1, name: "block_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "state", kind: "enum", T: proto3.getEnumType(BlockStateEnum) },
],
);

/**
*
* GetBlockStates : 閉塞の状態を取得するAPI
*
* @generated from message state.v1.GetBlockStatesRequest
*/
export const GetBlockStatesRequest = proto3.makeMessageType(
"state.v1.GetBlockStatesRequest",
[],
);

/**
* @generated from message state.v1.GetBlockStatesResponse
*/
export const GetBlockStatesResponse = proto3.makeMessageType(
"state.v1.GetBlockStatesResponse",
() => [
{ no: 1, name: "states", kind: "message", T: BlockState, repeated: true },
],
);

/**
*
* UpdateBLockState: 閉塞の状態を更新するAPI
*
* @generated from message state.v1.UpdateBlockStateRequest
*/
export const UpdateBlockStateRequest = proto3.makeMessageType(
"state.v1.UpdateBlockStateRequest",
() => [
{ no: 1, name: "state", kind: "message", T: BlockState },
],
);

/**
* @generated from message state.v1.UpdateBlockStateResponse
*/
export const UpdateBlockStateResponse = proto3.makeMessageType(
"state.v1.UpdateBlockStateResponse",
[],
);

Loading

0 comments on commit 6c254a2

Please sign in to comment.