Category の CRUD API を追加 - #123
Closed
oda-takuya-0123 wants to merge 2 commits into
Closed
Conversation
DRF の ModelViewSet で Category の一覧・取得・作成・更新・削除を実装。 serializer に企業単位の一意制約と親カテゴリの整合性検証を追加した。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
api アプリにマイグレーションが存在せず、migrate では categories / companies テーブルが作成されない状態だったため、 既存のモデル定義から初期マイグレーションを生成した。 モデルの定義自体は変更していない。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Category モデルの CRUD API を実装し、あわせて API のテストを追加しました。
エンドポイント
/api/categories//api/categories//api/categories/{id}//api/categories/{id}//api/categories/{id}//api/categories/{id}/認証は不要との指示のため、パーミッション設定は行っていません。
対応内容
validate()で追加した整合性チェックは2点です一覧の並び順を
(company, name)にしていますCategory.MetaのindexesおよびUniqueConstraintがいずれも(company, name)であるため、インデックスに沿った並び順であり、かつ一意制約により順序が一意に定まります。api/views/__init__.pyを追加していますmodels/serializers/testsの各ディレクトリには__init__.pyが存在する一方、viewsにのみ存在しませんでした。既存の構成に合わせるための追加です。テスト
正常系
id)が書き込みで無視されることparent_categoryが null になること(on_delete=SET_NULLの担保)異常系
今回スコープ外とした事項
companyを作成後は変更不可とするのが有効ですが、更新可能なフィールドの範囲は仕様確認が必要と判断し、本 PR では対応していません。