Add categories endpoint in API (#460)

* Add categories endpoint in API

* FIX eager load parent and subcategories associations

* FIX update specs to match

* Add rswag spec

* FIX openapi spec

* FIX final warns
This commit is contained in:
soky srm
2025-12-17 15:00:01 +01:00
committed by GitHub
parent 9d54719007
commit 7be799fac7
12 changed files with 924 additions and 16 deletions

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
json.id category.id
json.name category.name
json.classification category.classification
json.color category.color
json.icon category.lucide_icon
# Parent information (for subcategories)
if category.parent.present?
json.parent do
json.id category.parent.id
json.name category.parent.name
end
else
json.parent nil
end
# Subcategories count (for parent categories)
json.subcategories_count category.subcategories.size
json.created_at category.created_at.iso8601
json.updated_at category.updated_at.iso8601

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
json.categories @categories do |category|
json.partial! "api/v1/categories/category", category: category
end
json.pagination do
json.page @pagy.page
json.per_page @per_page
json.total_count @pagy.count
json.total_pages @pagy.pages
end

View File

@@ -0,0 +1,3 @@
# frozen_string_literal: true
json.partial! "api/v1/categories/category", category: @category