Created
January 15, 2023 05:51
-
-
Save zachdaniel/b4ab9354a3d84b5fd4881bcb63f503e5 to your computer and use it in GitHub Desktop.
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
defmodule Mochi.Deck do | |
use Ash.Resource, | |
data_layer: AshJsonApiWrapper.DataLayer | |
actions do | |
defaults [:read] | |
end | |
json_api_wrapper do | |
finch Mochi.Finch | |
base_paginator continuation_property("$.bookmark", param: "bookmark") | |
endpoints do | |
base "https://app.mochi.cards/api/decks/" | |
base_entity_path "$.docs" | |
end | |
fields do | |
field :template_id do | |
path ~s($["template-id"]) | |
end | |
end | |
end | |
preparations do | |
prepare Mochi.Preparations.SetAuthenticationHeaders | |
end | |
attributes do | |
attribute :id, :string do | |
primary_key? true | |
allow_nil? false | |
end | |
attribute :name, :string do | |
allow_nil? false | |
end | |
attribute :sort, :integer do | |
allow_nil? false | |
end | |
attribute :template_id, :string | |
end | |
relationships do | |
has_many :cards, Mochi.Card | |
end | |
end | |
defmodule Mochi.Card do | |
use Ash.Resource, | |
data_layer: AshJsonApiWrapper.DataLayer | |
actions do | |
defaults [:read] | |
end | |
json_api_wrapper do | |
finch Mochi.Finch | |
base_paginator continuation_property("$.bookmark", param: "bookmark") | |
endpoints do | |
base "https://app.mochi.cards/api/cards/" | |
base_entity_path "$.docs" | |
end | |
fields do | |
field :template_id do | |
path ~s($["template-id"]) | |
end | |
field :deck_id do | |
path ~s($["deck-id"]) | |
filter_handler {:simple, "deck-id"} | |
end | |
end | |
end | |
preparations do | |
prepare Mochi.Preparations.SetAuthenticationHeaders | |
end | |
attributes do | |
attribute :id, :string do | |
primary_key? true | |
allow_nil? false | |
end | |
attribute :name, :string do | |
allow_nil? false | |
end | |
attribute :sort, :integer do | |
allow_nil? false | |
end | |
attribute :template_id, :string | |
end | |
relationships do | |
belongs_to :deck, Mochi.Deck do | |
attribute_type :string | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment