-
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.
- Loading branch information
Showing
34 changed files
with
253 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,5 @@ erl_crash.dump | |
/tmp/ | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
peach_backend-*.tar | ||
peach-*.tar | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# PeachBackend | ||
# Peach | ||
|
||
To start your Phoenix server: | ||
|
||
|
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
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
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
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
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
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
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
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,26 @@ | ||
defmodule Peach.Event do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
@derive Jason.Encoder | ||
schema "events" do | ||
field :name, :string | ||
field :date, :naive_datetime | ||
field :description, :string | ||
field :location, :string | ||
field :cover, :string | ||
field :onchain, :boolean, default: false | ||
|
||
has_many :ticket_tiers, Peach.TicketTier | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(event, attrs) do | ||
event | ||
|> cast(attrs, [:name, :description, :location, :date, :cover]) | ||
|> cast_assoc(:ticket_tiers, with: &Peach.TicketTier.changeset/2) | ||
|> validate_required([:name, :description, :location, :date, :cover]) | ||
end | ||
end |
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,14 @@ | ||
defmodule Events do | ||
alias Peach.Repo | ||
alias Peach.Event | ||
alias Peach.TicketTier | ||
|
||
@doc """ | ||
Creates an event with the given attributes. | ||
""" | ||
def create_event(event \\ %{}) do | ||
%Event{} | ||
|> Event.changeset(event) | ||
|> Repo.insert() | ||
end | ||
end |
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,3 @@ | ||
defmodule Peach.Mailer do | ||
use Swoosh.Mailer, otp_app: :peach | ||
end |
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,5 @@ | ||
defmodule Peach.Repo do | ||
use Ecto.Repo, | ||
otp_app: :peach, | ||
adapter: Ecto.Adapters.Postgres | ||
end |
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 @@ | ||
defmodule Peach.Ticket do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "tickets" do | ||
field :owner, :string | ||
field :balance, :integer | ||
field :tier_id, :id | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(ticket, attrs) do | ||
ticket | ||
|> cast(attrs, [:owner, :balance, :tier_id]) | ||
|> validate_required([:owner, :balance, :tier_id]) | ||
|> validate_length(:owner, max: 66) | ||
end | ||
end |
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,22 @@ | ||
defmodule Peach.TicketTier do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
@derive Jason.Encoder | ||
schema "ticket_tiers" do | ||
field :name, :string | ||
field :description, :string | ||
field :max_supply, :integer | ||
|
||
belongs_to :event, Peach.Event | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(ticket_tier, attrs) do | ||
ticket_tier | ||
|> cast(attrs, [:name, :description, :max_supply]) | ||
|> validate_required([:name, :description, :max_supply]) | ||
end | ||
end |
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
2 changes: 1 addition & 1 deletion
2
...ela_backend_web/controllers/error_json.ex → ...d/lib/peach_web/controllers/error_json.ex
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
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,17 @@ | ||
defmodule PeachWeb.EventController do | ||
use PeachWeb, :controller | ||
|
||
def create(conn, %{"event" => event_params}) do | ||
case Events.create_event(event_params) do | ||
{:ok, event} -> | ||
conn | ||
|> put_status(:created) | ||
|> json(%{message: "Event created successfully", event: event.name}) | ||
|
||
{:error, changeset} -> | ||
conn | ||
|> put_status(:unprocessable_entity) | ||
|> json(%{errors: changeset}) | ||
end | ||
end | ||
end |
Oops, something went wrong.