Skip to content

Instantly share code, notes, and snippets.

@zachdaniel
Created January 15, 2023 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachdaniel/b4ab9354a3d84b5fd4881bcb63f503e5 to your computer and use it in GitHub Desktop.
Save zachdaniel/b4ab9354a3d84b5fd4881bcb63f503e5 to your computer and use it in GitHub Desktop.
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