Skip to content

Comments

feat: アクティビティ統計エンドポイントの追加#245

Merged
newt239 merged 6 commits intomasterfrom
feat/activity-stat
Jan 10, 2026
Merged

feat: アクティビティ統計エンドポイントの追加#245
newt239 merged 6 commits intomasterfrom
feat/activity-stat

Conversation

@newt239
Copy link
Member

@newt239 newt239 commented Dec 29, 2025

概要

  • アクティビティ機能に3つの統計エンドポイントを追加しました
    • 場所の現在在室中ユーザー一覧取得
    • 場所の訪問履歴取得(日/週/月単位)
    • ユーザーの入室記録一覧取得

変更内容

追加エンドポイント

  1. GET /activity/place/{place}/current - 現在在室中のユーザー一覧
  2. GET /activity/place/{place}/history - 場所の訪問履歴(期間指定可能)
  3. GET /activity/user/{userId}/records - ユーザーの入室記録一覧(ページネーション対応)

実装ファイル

SQLクエリ

OpenAPI仕様

テストプラン

以下のcurlコマンドで各エンドポイントをテストできます。

1. 現在在室中のユーザー一覧取得

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/current" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果:

{
  "users": [
    {
      "userId": "9bca677f-dfe5-11f0-a248-724daa63eb6e",
      "username": "山田太郎",
      "shortIntroduction": "よろしくお願いします",
      "iconUrl": "https://example.com/icon.jpg",
      "checkedInAt": "2025-12-29T10:30:00+09:00"
    }
  ]
}

空の場合:

{
  "users": []
}

2. 場所の訪問履歴取得(日単位)

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/history?period=day&date=2025-12-29" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果:

{
  "users": [
    {
      "userId": "9bca677f-dfe5-11f0-a248-724daa63eb6e",
      "username": "山田太郎",
      "shortIntroduction": "よろしくお願いします",
      "iconUrl": "https://example.com/icon.jpg",
      "checkInCount": 3
    }
  ]
}

3. 場所の訪問履歴取得(週単位)

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/history?period=week&date=2025-12-29" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 指定日を含む週の1週間前の月曜00:00:00 ~ 指定日を含む週の日曜23:59:59の期間の訪問履歴

4. 場所の訪問履歴取得(月単位)

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/history?period=month&date=2025-12-29" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 指定日の1か月前の1日00:00:00 ~ 指定日を含む月の月末23:59:59の期間の訪問履歴

エラーケース(不正なperiod値):

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/history?period=year&date=2025-12-29" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 400 Bad Request - "periodはday、week、monthのいずれかである必要があります"

エラーケース(不正な日付形式):

curl -X GET "http://localhost:8000/activity/place/omiya-bushitsu/history?period=day&date=2025/12/29" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 400 Bad Request - "日付の形式が不正です"

5. ユーザーの入室記録一覧取得(基本)

curl -X GET "http://localhost:8000/activity/user/${USER_ID}/records" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果:

{
  "records": [
    {
      "recordId": "abc123...",
      "place": "omiya-bushitsu",
      "checkedInAt": "2025-12-29T10:00:00+09:00",
      "checkedOutAt": "2025-12-29T18:00:00+09:00",
      "initialCheckedInAt": "2025-12-29T10:00:00+09:00",
      "initialCheckedOutAt": "2025-12-29T18:00:00+09:00"
    }
  ],
  "total": 42,
  "offset": 0,
  "limit": 50
}

6. ユーザーの入室記録一覧取得(場所フィルタ付き)

curl -X GET "http://localhost:8000/activity/user/${USER_ID}/records?place=omiya-bushitsu" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 指定した場所の記録のみが返される

7. ユーザーの入室記録一覧取得(ページネーション)

curl -X GET "http://localhost:8000/activity/user/${USER_ID}/records?offset=10&limit=20" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果:

{
  "records": [...],
  "total": 42,
  "offset": 10,
  "limit": 20
}

8. ユーザーの入室記録一覧取得(複数パラメータ組み合わせ)

curl -X GET "http://localhost:8000/activity/user/${USER_ID}/records?place=omiya-bushitsu&offset=0&limit=10" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果: 指定した場所の記録が、ページネーション付きで返される

9. 在室中のレコード(checkedOutAtがnull)

# 現在在室中のユーザーのレコードを取得した場合
curl -X GET "http://localhost:8000/activity/user/${USER_ID}/records" \
  -H "Authorization: Bearer ${TOKEN}"

期待される結果:

{
  "records": [
    {
      "recordId": "abc123...",
      "place": "omiya-bushitsu",
      "checkedInAt": "2025-12-29T10:00:00+09:00",
      "checkedOutAt": null,
      "initialCheckedInAt": "2025-12-29T10:00:00+09:00",
      "initialCheckedOutAt": null
    }
  ],
  "total": 1,
  "offset": 0,
  "limit": 50
}

補足情報

  • デフォルト値: offset=0, limit=50
  • checkedOutAtinitialCheckedOutAtは在室中の場合nullになります
  • initialCheckedInAtinitialCheckedOutAtは編集前の元の時刻を保持します
  • 編集されていない場合はcheckedInAt/checkedOutAtと同じ値になります

🤖 Generated with Claude Code

newt239 and others added 2 commits December 29, 2025 22:28
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 29, 2025 13:29
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 29, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
spec-core 8b08cc5 Commit Preview URL

Branch Preview URL
Jan 03 2026, 09:37 AM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

このPRは、アクティビティ機能に3つの統計エンドポイントを追加しています。現在在室中のユーザー一覧、場所の訪問履歴(日/週/月単位)、およびユーザーの入室記録一覧を取得できる機能が実装されています。

主な変更点:

  • 3つの新規GETエンドポイントの追加(current users、place history、user records)
  • 対応するSQLクエリ、APIハンドラ、OpenAPI仕様の実装
  • ページネーション機能を含むユーザー入室記録取得API

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
pkg/db/sql/activity/select_current_users.sql 現在在室中のユーザーを取得するSQLクエリ(ROW_NUMBER()を使用した最新レコードの抽出)
pkg/db/sql/activity/select_place_history.sql 指定期間内の場所訪問履歴を集計するSQLクエリ
pkg/db/sql/activity/select_user_records.sql ユーザーの入室記録をページネーション対応で取得するSQLクエリ
pkg/db/sql/activity/select_user_records_count.sql ユーザーの入室記録の総数を取得するSQLクエリ
pkg/activity/get_activity_place_place_current.go 現在在室中のユーザー一覧取得の実装
pkg/activity/get_activity_place_place_history.go 場所の訪問履歴取得と日付範囲計算ロジックの実装
pkg/activity/get_activity_user_user_id_records.go ユーザー入室記録一覧取得の実装(ページネーション対応)
pkg/api/server/get_activity_place_place_current.go 現在在室中のユーザー一覧エンドポイントのハンドラ
pkg/api/server/get_activity_place_place_history.go 場所の訪問履歴エンドポイントのハンドラ
pkg/api/server/get_activity_user_user_id_records.go ユーザー入室記録エンドポイントのハンドラ
pkg/api/server.gen.go 3つの新規エンドポイントのルーティング設定を追加
pkg/api/models.gen.go 新規エンドポイントのリクエスト/レスポンスモデルを定義
pkg/api/spec.gen.go OpenAPI仕様の生成コード更新
document/paths/activity_place_place_current.yml 現在在室中のユーザー一覧エンドポイントのOpenAPI定義
document/paths/activity_place_place_history.yml 場所の訪問履歴エンドポイントのOpenAPI定義
document/paths/activity_user_user_id_records.yml ユーザー入室記録エンドポイントのOpenAPI定義
document/schemas/*.yml 各エンドポイントのレスポンススキーマ定義
document/paths.yml 新規エンドポイントのパス登録
document/schemas.yml 新規スキーマの登録
document/bundle.gen.yml OpenAPI仕様バンドル更新

@newt239 newt239 changed the title アクティビティ統計エンドポイントの追加 feat: アクティビティ統計エンドポイントの追加 Jan 3, 2026
@newt239 newt239 requested a review from saka-naname January 3, 2026 09:40
Copy link
Contributor

@saka-naname saka-naname left a comment

Choose a reason for hiding this comment

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

LGTMeow

@newt239 newt239 merged commit 8bbffce into master Jan 10, 2026
3 checks passed
@newt239 newt239 deleted the feat/activity-stat branch January 10, 2026 05:03
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