mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
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:
23
app/views/api/v1/categories/_category.json.jbuilder
Normal file
23
app/views/api/v1/categories/_category.json.jbuilder
Normal 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
|
||||
12
app/views/api/v1/categories/index.json.jbuilder
Normal file
12
app/views/api/v1/categories/index.json.jbuilder
Normal 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
|
||||
3
app/views/api/v1/categories/show.json.jbuilder
Normal file
3
app/views/api/v1/categories/show.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.partial! "api/v1/categories/category", category: @category
|
||||
Reference in New Issue
Block a user