commew / timelogger-web

時間記録アプリ
https://timmew.commew.net
MIT License
2 stars 0 forks source link

✨ #52 タスク計測関連のAPIの設計を実施 #74

Closed stkzk3110 closed 1 year ago

stkzk3110 commented 1 year ago

issueURL

https://github.com/commew/timelogger-web/issues/52

この PR で対応する範囲 / この PR で対応しない範囲

Storybook の URL、 スクリーンショット

UIの変更はないため、対象外。

変更点概要

サンプルリクエスト・レスポンス

タスク記録を開始する

正常系

curl --request POST \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=201, example=ExampleSuccess' \
  --header 'Request-Id: ' \
  --data '{
  "taskCategoryId": 1
}'

201 Created

{
  "id": 1,
  "status": "recording",
  "startAt": "2019-08-24T14:15:22Z",
  "taskCategoryId": 1
}

異常系(認証エラー)

curl --request POST \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=401, example=ExampleUnAuthenticated' \
  --header 'Request-Id: ' \
  --data '{
  "taskCategoryId": 1
}'

401 Unauthorized

{
  "type": "UNAUTHENTICATED",
  "title": "Basic Authentication parameters are incorrect."
}
curl --request POST \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=422, example=ExampleValidationError' \
  --header 'Request-Id: ' \
  --data '{
  "taskCategoryId": 1
}'

422 Unprocessable Entity

{
  "type": "UNPROCESSABLE_ENTITY",
  "title": "Unprocessable Entity.",
  "invalidParams": [
    {
      "name": "taskCategoryId",
      "reason": "taskCategoryId is required."
    }
  ]
}
curl --request POST \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=500, example=ExampleInternalServerError' \
  --header 'Request-Id: ' \
  --data '{
  "taskCategoryId": 1
}'

500 Internal Server Error

{
  "type": "INTERNAL_SERVER_ERROR",
  "title": "Internal Server Error."
}

タスクの記録を停止する

正常系

curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/stop \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=200, example=ExampleSuccess' \
  --header 'Request-Id: '

200 OK

{
  "id": 1,
  "status": "pending",
  "startAt": "2019-08-24T14:15:22Z",
  "endAt": "2019-08-24T16:15:22Z",
  "duration": 7200,
  "taskCategoryId": 1
}
curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/stop \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=401, example=ExampleUnAuthenticated' \
  --header 'Request-Id: '

401 Unauthorized

{
  "type": "UNAUTHENTICATED",
  "title": "Basic Authentication parameters are incorrect."
}
curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/stop \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=500, example=ExampleInternalServerError' \
  --header 'Request-Id: '

500 Internal Server Error

{
  "type": "INTERNAL_SERVER_ERROR",
  "title": "Internal Server Error."
}

タスクの記録を終了する

正常系

curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/complete \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=200, example=ExampleSuccess' \
  --header 'Request-Id: '

200 OK

{
  "id": 1,
  "status": "completed",
  "startAt": "2019-08-24T14:15:22Z",
  "endAt": "2019-08-24T18:15:22Z",
  "duration": 14400,
  "taskCategoryId": 1
}
curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/complete \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=401, example=ExampleUnAuthenticated' \
  --header 'Request-Id: '

401 Unauthorized

{
  "type": "UNAUTHENTICATED",
  "title": "Basic Authentication parameters are incorrect."
}
curl --request PATCH \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/1/complete \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Content-Type: application/json' \
  --header 'Prefer: code=500, example=ExampleInternalServerError' \
  --header 'Request-Id: '

500 Internal Server Error

{
  "type": "INTERNAL_SERVER_ERROR",
  "title": "Internal Server Error."
}

記録中のタスク一覧を取得する

正常系

curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/recording \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=200, example=ExampleSuccess' \
  --header 'Request-Id: '

200 OK

{
  "tasks": [
    {
      "id": 1,
      "status": "recording",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    },
    {
      "id": 2,
      "status": "recording",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    },
    {
      "id": 3,
      "status": "recording",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    }
  ]
}
curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/recording \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=401, example=ExampleUnAuthenticated' \
  --header 'Request-Id: '

401 Unauthorized

{
  "type": "UNAUTHENTICATED",
  "title": "Basic Authentication parameters are incorrect."
}
curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/recording \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=500, example=ExampleInternalServerError' \
  --header 'Request-Id: '

500 Internal Server Error

{
  "type": "INTERNAL_SERVER_ERROR",
  "title": "Internal Server Error."
}

停止中のタスク一覧を取得する

正常系

curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/pending \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=200, example=ExampleSuccess' \
  --header 'Request-Id: '

200 OK

{
  "tasks": [
    {
      "id": 1,
      "status": "pending",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    },
    {
      "id": 2,
      "status": "pending",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    },
    {
      "id": 3,
      "status": "pending",
      "startAt": "2019-08-24T14:15:22Z",
      "endAt": "2019-08-24T18:15:22Z",
      "duration": 14400,
      "taskCategoryId": 1
    }
  ]
}
curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/pending \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=401, example=ExampleUnAuthenticated' \
  --header 'Request-Id: '

401 Unauthorized

{
  "type": "UNAUTHENTICATED",
  "title": "Basic Authentication parameters are incorrect."
}
curl --request GET \
  --url https://stoplight.io/mocks/cube3110/timmew/84330/tasks/pending \
  --header 'Accept: application/json' \
  --header 'Authorization: YWRtaW5Vc2VyOnBhc3N3b3JkMTIzNA==' \
  --header 'Prefer: code=500, example=ExampleInternalServerError' \
  --header 'Request-Id: '

500 Internal Server Error

{
  "type": "INTERNAL_SERVER_ERROR",
  "title": "Internal Server Error."
}

レビュアーに重点的にチェックして欲しい点

コメントしている点と全体的に以下をみていただけると🙏

補足情報

[optional]

何か補足情報があれば記載。

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
timelogger-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2023 1:36am
keitakn commented 1 year ago

@HAYASHI-Masayuki

コメントありがとうございます!

コメント以外にも一つだけ、「停止」状態からの再開をどう表現するのかが気になりました。 Issueの方では対応範囲外となっていますが、コメントした型回りと、再開の仕様だけははっきりしていないとバックエンドの>実装時に困りそうなので、この辺ご検討いただけるととても助かります!

ごめんなさい、これは本来 https://github.com/commew/timelogger-web/issues/52 の完了の定義に含めるべきでしたが、私がissueを作成した段階で漏れてしまっていたようです。

これ以上同じPR内で処理を追加するとごちゃごちゃして後で見た時に分かりにくくなってしまうので https://github.com/commew/timelogger-web/issues/79 というissueを作成しました!

@stkzk3110 @c501306014

こちらのPRがマージされた後で https://github.com/commew/timelogger-web/issues/79 のご対応お願いしても良いでしょうか:pray:?