maxmannen
maxmannen
AEAsh Elixir
Created by maxmannen on 3/13/2023 in #support
Filter function do not work...What am I missing? (Returns empty)
defmodule Ampldev.Syllabuses.GySeCourse do
# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

attributes do
attribute :code, :string do
primary_key? true
allow_nil? false
end

attribute :name, :string do
allow_nil? false
end

attribute :central_content, {:array, :string}
end

actions do
defaults [:read]

read :search_course_name do
argument :name, :string do
end

filter expr(contains(^arg(:name), name))
end
end

code_interface do
define_for Ampldev.Syllabuses
define :search_course_name, args: [:string]
end
end
defmodule Ampldev.Syllabuses.GySeCourse do
# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

attributes do
attribute :code, :string do
primary_key? true
allow_nil? false
end

attribute :name, :string do
allow_nil? false
end

attribute :central_content, {:array, :string}
end

actions do
defaults [:read]

read :search_course_name do
argument :name, :string do
end

filter expr(contains(^arg(:name), name))
end
end

code_interface do
define_for Ampldev.Syllabuses
define :search_course_name, args: [:string]
end
end
18 replies
AEAsh Elixir
Created by maxmannen on 2/7/2023 in #support
Problem with override image
Do not get this to work - the standard Ash image is still there... also, is there it a spec of all the overrides?
sign_in_route overrides: [
AmplDevWeb.AuthOverrides,
AshAuthentication.Phoenix.Overrides.Default
]

defmodule AmplDevWeb.AuthOverrides do

@moduledoc "UI overrides for authentication views"
use AshAuthentication.Phoenix.Overrides

override AshAuthentication.Phoenix.SignInLive do
set :image_url, "./priv/images/ampl.png"

end
end
sign_in_route overrides: [
AmplDevWeb.AuthOverrides,
AshAuthentication.Phoenix.Overrides.Default
]

defmodule AmplDevWeb.AuthOverrides do

@moduledoc "UI overrides for authentication views"
use AshAuthentication.Phoenix.Overrides

override AshAuthentication.Phoenix.SignInLive do
set :image_url, "./priv/images/ampl.png"

end
end
6 replies
AEAsh Elixir
Created by maxmannen on 1/23/2023 in #support
Can´t get json-api to work when passing arguments.
My api is working with no arguments but I can´t understand how to do it with passing arguments.
defmodule AshDatastore.Documents.Syllabus do

use Ash.Resource,
data_layer: Ash.DataLayer.Ets, extensions: [AshJsonApi.Resource]
json_api do
type "syllabus"
routes do
base "/syllabuses"
get(:get_syllabus_documents, route: "/by_type/:country_code/:school_type/:document_type")
index :read
end
end
actions do
defaults [:read, :create]
code_interface do
define_for AshDatastore.Documents
define :get_syllabus_documents, args: [:country_code, :school_type, :document_type]
end
read :get_syllabus_documents do
argument :country_code, :string
argument :school_type, :string
argument :document_type, :string
filter expr(country_code== ^arg(:country_code) and school_type == ^arg(:school_type) and document_type==^arg(:document_type))
end
end

attributes do
uuid_primary_key :id
attribute :country_code, :string
attribute :school_type, :string
attribute :document_type, :string
attribute :content_map, :map
end
end
defmodule AshDatastore.Documents.Syllabus do

use Ash.Resource,
data_layer: Ash.DataLayer.Ets, extensions: [AshJsonApi.Resource]
json_api do
type "syllabus"
routes do
base "/syllabuses"
get(:get_syllabus_documents, route: "/by_type/:country_code/:school_type/:document_type")
index :read
end
end
actions do
defaults [:read, :create]
code_interface do
define_for AshDatastore.Documents
define :get_syllabus_documents, args: [:country_code, :school_type, :document_type]
end
read :get_syllabus_documents do
argument :country_code, :string
argument :school_type, :string
argument :document_type, :string
filter expr(country_code== ^arg(:country_code) and school_type == ^arg(:school_type) and document_type==^arg(:document_type))
end
end

attributes do
uuid_primary_key :id
attribute :country_code, :string
attribute :school_type, :string
attribute :document_type, :string
attribute :content_map, :map
end
end
I run this (with singel or dubbelbrackets- same result): http://localhost:4000/api/json/documents/syllabuses/by_type/"se"/"gy"/"courses" and get this: ``` { "errors": [ { "code": "NotFound", "detail": "No syllabus record found with country_code: "se", document_type: "courses", school_type: "gy"`", "id": "1db6e507-92e1-4683-a133-517993305779", "status": "404", "title": "Entity Not Found" } ], "jsonapi": { "version": "1.0" } } ```
21 replies