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

Feat/backend/api/v1 #17

Merged
merged 28 commits into from
Mar 28, 2024
Merged

Feat/backend/api/v1 #17

merged 28 commits into from
Mar 28, 2024

Conversation

KinjiKawaguchi
Copy link
Member

@KinjiKawaguchi KinjiKawaguchi commented Mar 23, 2024

やったこと

  • 動作するAPIを作った

やらないこと

  • APIが正しいレスポンスコードを返すようにする
  • エラーメッセージの整備

@h-takeyeah
Copy link
Collaborator

Go詳しくないのでメモがてらテーブルを貼っておきます、すみません

Score:
	+------------+-----------+--------+----------+----------+---------+---------------+-----------+-----------------------------+------------+---------+
	|   Field    |   Type    | Unique | Optional | Nillable | Default | UpdateDefault | Immutable |          StructTag          | Validators | Comment |
	+------------+-----------+--------+----------+----------+---------+---------------+-----------+-----------------------------+------------+---------+
	| id         | uuid.UUID | true   | false    | false    | true    | false         | false     | json:"id,omitempty"         |          0 |         |
	| keystrokes | int       | false  | false    | false    | false   | false         | false     | json:"keystrokes,omitempty" |          0 |         |
	| accuracy   | float64   | false  | false    | false    | false   | false         | false     | json:"accuracy,omitempty"   |          0 |         |
	| created_at | time.Time | false  | false    | false    | true    | false         | true      | json:"created_at,omitempty" |          0 |         |
	+------------+-----------+--------+----------+----------+---------+---------------+-----------+-----------------------------+------------+---------+
	+------+------+---------+---------+----------+--------+----------+---------+
	| Edge | Type | Inverse | BackRef | Relation | Unique | Optional | Comment |
	+------+------+---------+---------+----------+--------+----------+---------+
	| user | User | true    | scores  | M2O      | true   | false    |         |
	+------+------+---------+---------+----------+--------+----------+---------+
	
User:
	+----------------+-----------+--------+----------+----------+---------+---------------+-----------+---------------------------------+------------+---------+
	|     Field      |   Type    | Unique | Optional | Nillable | Default | UpdateDefault | Immutable |            StructTag            | Validators | Comment |
	+----------------+-----------+--------+----------+----------+---------+---------------+-----------+---------------------------------+------------+---------+
	| id             | uuid.UUID | true   | false    | false    | true    | false         | false     | json:"id,omitempty"             |          0 |         |
	| student_number | string    | true   | false    | false    | false   | false         | false     | json:"student_number,omitempty" |          1 |         |
	| handle_name    | string    | false  | false    | false    | false   | false         | false     | json:"handle_name,omitempty"    |          2 |         |
	| created_at     | time.Time | false  | false    | false    | true    | false         | true      | json:"created_at,omitempty"     |          0 |         |
	| updated_at     | time.Time | false  | false    | false    | true    | true          | false     | json:"updated_at,omitempty"     |          0 |         |
	+----------------+-----------+--------+----------+----------+---------+---------------+-----------+---------------------------------+------------+---------+
	+--------+-------+---------+---------+----------+--------+----------+---------+
	|  Edge  | Type  | Inverse | BackRef | Relation | Unique | Optional | Comment |
	+--------+-------+---------+---------+----------+--------+----------+---------+
	| scores | Score | false   |         | O2M      | false  | true     |         |
	+--------+-------+---------+---------+----------+--------+----------+---------+
	

https://entgo.io/docs/code-gen/#schema-description を参考に以下のコマンドで生成しました。

# typing-server/ ディレクトリで
go run -mod=mod entgo.io/ent/cmd/ent describe ./domain/repository/ent/schema 

@h-takeyeah
Copy link
Collaborator

PRのテンプレートを作ったのならあえて破壊する理由がない限り、沿った方がよいと思う

@h-takeyeah
Copy link
Collaborator

OpenAPIからドキュメントを作るとこんな感じになります。これも併用しつつレビューします

https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/su-its/typing/feat/backend/api/v1/typing-server/openapi.yaml

Copy link
Collaborator

@h-takeyeah h-takeyeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おつかれさまです

typing-server/openapi.yaml Show resolved Hide resolved
type: number
format: float
required: true
description: 正確性
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正確性という言葉だけでなく計算方法も示してあげる方が親切かと。例えば正確性 (ミスタイプ数 / キーストローク数)、など。これ書くならむしろ計算方法だけの方がいいかもですけどその辺は読みやすいように書いてください。

(杞憂だと思いますがfloatの丸め誤差がないと思うけど少し気になる&ミスタイプ数があればGo側で計算できるから、accuracyの代わりにミスタイプ数を送れば整数で送れて_HAPPY_かもしれません)

typing-server/openapi.yaml Show resolved Hide resolved
@KinjiKawaguchi KinjiKawaguchi changed the title [DO NOT MERGE]Feat/backend/api/v1 Feat/backend/api/v1 Mar 26, 2024
@KinjiKawaguchi KinjiKawaguchi self-assigned this Mar 27, 2024
プログラムで使えるコードを自動生成するときに機械的に命名されて
変なクラス名などになるのを防ぐ目的
Copy link
Collaborator

@h-takeyeah h-takeyeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAPIを見ました

typing-server/openapi.yaml Show resolved Hide resolved
typing-server/openapi.yaml Show resolved Hide resolved
description: 不正なリクエスト
'404':
description: スコアが見つからない
"201":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも作成された Score を返すべきだと思います!根拠は RFC7231 です (これは MDN) https://developer.mozilla.org/ja/docs/Web/HTTP/Status/201

Copy link
Collaborator

@h-takeyeah h-takeyeah Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おまけでそのスコアだとおよそ何位になるかという情報も一緒に返してあげると嬉しいかもね(RESTとは)(これは今後の課題というか半分冗談なので対応しなくてよいです!) 👍

typing-server/openapi.yaml Outdated Show resolved Hide resolved
@h-takeyeah
Copy link
Collaborator

よ~しスピード優先でマージしちゃうぞ~(合意済み)

@h-takeyeah h-takeyeah merged commit 76c47f5 into develop Mar 28, 2024
1 check passed
@h-takeyeah h-takeyeah deleted the feat/backend/api/v1 branch March 28, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants