-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: JSONデータを返却するだけのシンプルなシリアライザに変更する
- Loading branch information
Showing
21 changed files
with
309 additions
and
168 deletions.
There are no files selected for viewing
This file contains 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
20 changes: 20 additions & 0 deletions
20
volumes/backend/app/serializers/api/products/base_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Api | ||
module Products | ||
class BaseSerializer | ||
def render_json | ||
normalize_json | ||
end | ||
|
||
private | ||
|
||
# @override | ||
def json | ||
raise NotImplementedError, "#{self.class.name}##{__method__} is not defined." | ||
end | ||
|
||
def normalize_json | ||
json.is_a?(Hash) ? json.with_indifferent_access : json | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
volumes/backend/app/serializers/api/products/category_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Api | ||
module Products | ||
class CategorySerializer < BaseSerializer | ||
def initialize(category) | ||
@category = category | ||
end | ||
|
||
private | ||
|
||
def json | ||
@category.as_json | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/iosys_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class IosysCrawlSettingSerializer < BaseSerializer | ||
def initialize(iosys_crawl_setting) | ||
@iosys_crawl_setting = iosys_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
iosys_crawl_setting_json.merge( | ||
{ | ||
iosys_crawl_setting_exclude_keywords: iosys_crawl_setting_exclude_keywords_json, | ||
iosys_crawl_setting_required_keywords: iosys_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def iosys_crawl_setting_json | ||
@iosys_crawl_setting.as_json | ||
end | ||
|
||
def iosys_crawl_setting_exclude_keywords_json | ||
@iosys_crawl_setting.iosys_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def iosys_crawl_setting_required_keywords_json | ||
@iosys_crawl_setting.iosys_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/janpara_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class JanparaCrawlSettingSerializer < BaseSerializer | ||
def initialize(janpara_crawl_setting) | ||
@janpara_crawl_setting = janpara_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
janpara_crawl_setting_json.merge( | ||
{ | ||
janpara_crawl_setting_exclude_keywords: janpara_crawl_setting_exclude_keywords_json, | ||
janpara_crawl_setting_required_keywords: janpara_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def janpara_crawl_setting_json | ||
@janpara_crawl_setting.as_json | ||
end | ||
|
||
def janpara_crawl_setting_exclude_keywords_json | ||
@janpara_crawl_setting.janpara_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def janpara_crawl_setting_required_keywords_json | ||
@janpara_crawl_setting.janpara_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/mercari_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class MercariCrawlSettingSerializer < BaseSerializer | ||
def initialize(mercari_crawl_setting) | ||
@mercari_crawl_setting = mercari_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
mercari_crawl_setting_json.merge( | ||
{ | ||
mercari_crawl_setting_exclude_keywords: mercari_crawl_setting_exclude_keywords_json, | ||
mercari_crawl_setting_required_keywords: mercari_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def mercari_crawl_setting_json | ||
@mercari_crawl_setting.as_json | ||
end | ||
|
||
def mercari_crawl_setting_exclude_keywords_json | ||
@mercari_crawl_setting.mercari_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def mercari_crawl_setting_required_keywords_json | ||
@mercari_crawl_setting.mercari_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/pc_koubou_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class PcKoubouCrawlSettingSerializer < BaseSerializer | ||
def initialize(pc_koubou_crawl_setting) | ||
@pc_koubou_crawl_setting = pc_koubou_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
pc_koubou_crawl_setting_json.merge( | ||
{ | ||
pc_koubou_crawl_setting_exclude_keywords: pc_koubou_crawl_setting_exclude_keywords_json, | ||
pc_koubou_crawl_setting_required_keywords: pc_koubou_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def pc_koubou_crawl_setting_json | ||
@pc_koubou_crawl_setting.as_json | ||
end | ||
|
||
def pc_koubou_crawl_setting_exclude_keywords_json | ||
@pc_koubou_crawl_setting.pc_koubou_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def pc_koubou_crawl_setting_required_keywords_json | ||
@pc_koubou_crawl_setting.pc_koubou_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
57 changes: 57 additions & 0 deletions
57
volumes/backend/app/serializers/api/products/product_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Api | ||
module Products | ||
class ProductSerializer < BaseSerializer | ||
def initialize(product) | ||
@product = product | ||
end | ||
|
||
private | ||
|
||
def json | ||
product_json.merge( | ||
{ | ||
yahoo_auction_crawl_setting: yahoo_auction_crawl_setting_json, | ||
mercari_crawl_setting: mercari_crawl_setting_json, | ||
janpara_crawl_setting: janpara_crawl_setting_json, | ||
iosys_crawl_setting: iosys_crawl_setting_json, | ||
pc_koubou_crawl_setting: pc_koubou_crawl_setting_json, | ||
used_sofmap_crawl_setting: used_sofmap_crawl_setting_json, | ||
category: category_json | ||
} | ||
) | ||
end | ||
|
||
def product_json | ||
@product.as_json | ||
end | ||
|
||
def yahoo_auction_crawl_setting_json | ||
YahooAuctionCrawlSettingSerializer.new(@product.yahoo_auction_crawl_setting).render_json | ||
end | ||
|
||
def mercari_crawl_setting_json | ||
MercariCrawlSettingSerializer.new(@product.mercari_crawl_setting).render_json | ||
end | ||
|
||
def janpara_crawl_setting_json | ||
JanparaCrawlSettingSerializer.new(@product.janpara_crawl_setting).render_json | ||
end | ||
|
||
def iosys_crawl_setting_json | ||
IosysCrawlSettingSerializer.new(@product.iosys_crawl_setting).render_json | ||
end | ||
|
||
def pc_koubou_crawl_setting_json | ||
PcKoubouCrawlSettingSerializer.new(@product.pc_koubou_crawl_setting).render_json | ||
end | ||
|
||
def used_sofmap_crawl_setting_json | ||
UsedSofmapCrawlSettingSerializer.new(@product.used_sofmap_crawl_setting).render_json | ||
end | ||
|
||
def category_json | ||
CategorySerializer.new(@product.category).render_json | ||
end | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
volumes/backend/app/serializers/api/products/products_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Api | ||
module Products | ||
class ProductsSerializer < BaseSerializer | ||
def initialize(products) | ||
@products = products | ||
end | ||
|
||
private | ||
|
||
def json | ||
{ | ||
products: products_json | ||
} | ||
end | ||
|
||
def products_json | ||
@products.map do |product| | ||
ProductSerializer.new(product).render_json | ||
end | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/used_sofmap_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class UsedSofmapCrawlSettingSerializer < BaseSerializer | ||
def initialize(used_sofmap_crawl_setting) | ||
@used_sofmap_crawl_setting = used_sofmap_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
used_sofmap_crawl_setting_json.merge( | ||
{ | ||
used_sofmap_crawl_setting_exclude_keywords: used_sofmap_crawl_setting_exclude_keywords_json, | ||
used_sofmap_crawl_setting_required_keywords: used_sofmap_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def used_sofmap_crawl_setting_json | ||
@used_sofmap_crawl_setting.as_json | ||
end | ||
|
||
def used_sofmap_crawl_setting_exclude_keywords_json | ||
@used_sofmap_crawl_setting.used_sofmap_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def used_sofmap_crawl_setting_required_keywords_json | ||
@used_sofmap_crawl_setting.used_sofmap_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
volumes/backend/app/serializers/api/products/yahoo_auction_crawl_setting_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module Products | ||
class YahooAuctionCrawlSettingSerializer < BaseSerializer | ||
def initialize(yahoo_auction_crawl_setting) | ||
@yahoo_auction_crawl_setting = yahoo_auction_crawl_setting | ||
end | ||
|
||
private | ||
|
||
def json | ||
yahoo_auction_crawl_setting_json.merge( | ||
{ | ||
yahoo_auction_crawl_setting_exclude_keywords: yahoo_auction_crawl_setting_exclude_keywords_json, | ||
yahoo_auction_crawl_setting_required_keywords: yahoo_auction_crawl_setting_required_keywords_json | ||
} | ||
) | ||
end | ||
|
||
def yahoo_auction_crawl_setting_json | ||
@yahoo_auction_crawl_setting.as_json | ||
end | ||
|
||
def yahoo_auction_crawl_setting_exclude_keywords_json | ||
@yahoo_auction_crawl_setting.yahoo_auction_crawl_setting_exclude_keywords.map(&:as_json) | ||
end | ||
|
||
def yahoo_auction_crawl_setting_required_keywords_json | ||
@yahoo_auction_crawl_setting.yahoo_auction_crawl_setting_required_keywords.map(&:as_json) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
volumes/backend/app/serializers/iosys_crawl_setting_serializer.rb
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
volumes/backend/app/serializers/janpara_crawl_setting_serializer.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.