Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

server: add json api routes and read for seed/tree

+42 -5
+9
config/config.exs
··· 60 60 # Use Jason for JSON parsing in Phoenix 61 61 config :phoenix, :json_library, Jason 62 62 63 + # ash json api 64 + config :mime, :types, %{ 65 + "application/vnd.api+json" => ["json"] 66 + } 67 + 68 + config :mime, :extensions, %{ 69 + "json" => "application/vnd.api+json" 70 + } 71 + 63 72 # Import environment specific config. This must remain at the bottom 64 73 # of this file so it overrides the configuration defined above. 65 74 import_config "#{config_env()}.exs"
+1 -1
lib/sower.ex
··· 1 1 defmodule Sower do 2 - use Ash.Domain 2 + use Ash.Domain, extensions: [AshJsonApi.Domain] 3 3 4 4 resources do 5 5 resource Sower.Inputs.Repository
-1
lib/sower/inputs/repository.ex
··· 24 24 25 25 filter expr(id == ^arg(:id)) 26 26 end 27 - 28 27 end 29 28 30 29 attributes do
+12 -1
lib/sower/seed.ex
··· 1 1 defmodule Sower.Seed do 2 2 use Ash.Resource, 3 3 data_layer: AshPostgres.DataLayer, 4 - domain: Sower 4 + domain: Sower, 5 + extensions: [AshJsonApi.Resource] 5 6 6 7 @derive {Jason.Encoder, only: [:id, :name, :type, :out_path, :branch, :repository_id]} 7 8 ··· 119 120 120 121 identities do 121 122 identity :seed, [:name, :type, :out_path, :branch] 123 + end 124 + 125 + json_api do 126 + type "seed" 127 + 128 + routes do 129 + base "/seeds" 130 + 131 + get :read 132 + end 122 133 end 123 134 124 135 postgres do
+12 -1
lib/sower/tree.ex
··· 1 1 defmodule Sower.Tree do 2 2 use Ash.Resource, 3 3 data_layer: AshPostgres.DataLayer, 4 - domain: Sower 4 + domain: Sower, 5 + extensions: [AshJsonApi.Resource] 5 6 6 7 @types [:nixos, :"home-manager", :"nix-darwin"] 7 8 ··· 60 61 61 62 identities do 62 63 identity :tree, [:name, :type] 64 + end 65 + 66 + json_api do 67 + type "tree" 68 + 69 + routes do 70 + base "/trees" 71 + 72 + get :read 73 + end 63 74 end 64 75 65 76 postgres do
-1
lib/sower_web/controllers/page_html/home.html.heex
··· 3 3 Then he told them many things in parables, saying: “A farmer went out to sow his seed. As he was scattering the seed, some fell along the path, and the birds came and ate it up. Some fell on rocky places, where it did not have much soil. It sprang up quickly, because the soil was shallow. But when the sun came up, the plants were scorched, and they withered because they had no root. Other seed fell among thorns, which grew up and choked the plants. Still other seed fell on good soil, where it produced a crop—a hundred, sixty or thirty times what was sown. Whoever has ears, let them hear.” 4 4 </p> 5 5 </div> 6 -
+6
lib/sower_web/json_api_router.ex
··· 1 + defmodule SowerWeb.JsonApiRouter do 2 + use AshJsonApi.Router, 3 + domains: [Module.concat(["Sower"])], 4 + json_schema: "/json_schema", 5 + open_api: "/open_api" 6 + end
+2
lib/sower_web/router.ex
··· 33 33 get("/seeds", SowerWeb.SeedController, :list) 34 34 get("/seeds/latest", SowerWeb.SeedController, :find_latest) 35 35 post("/seeds", SowerWeb.SeedController, :new) 36 + 37 + forward "/json", SowerWeb.JsonApiRouter 36 38 end 37 39 38 40 # Enable LiveDashboard and Swoosh mailbox preview in development