-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizations.ex
109 lines (77 loc) · 2.18 KB
/
organizations.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
defmodule Fly.Organizations do
@moduledoc """
The Organizations context.
This context was generated using:
```
mix phx.gen.context Organizations Organization organizations name:string stripe_customer_id:string
```
"""
import Ecto.Query, warn: false
alias Fly.Repo
alias Fly.Organizations.Organization
@doc """
Returns the list of organizations.
## Examples
iex> list_organizations()
[%Organization{}, ...]
"""
def list_organizations do
Repo.all(Organization)
end
@doc """
Gets a single organization.
Raises `Ecto.NoResultsError` if the Organization does not exist.
## Examples
iex> get_organization!(123)
%Organization{}
iex> get_organization!(456)
** (Ecto.NoResultsError)
"""
def get_organization!(id), do: Repo.get!(Organization, id)
@doc """
Creates a organization.
## Examples
iex> create_organization(%{field: value})
{:ok, %Organization{}}
iex> create_organization(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_organization(attrs \\ %{}) do
%Organization{}
|> Organization.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a organization.
## Examples
iex> update_organization(organization, %{field: new_value})
{:ok, %Organization{}}
iex> update_organization(organization, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_organization(%Organization{} = organization, attrs) do
organization
|> Organization.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a organization.
## Examples
iex> delete_organization(organization)
{:ok, %Organization{}}
iex> delete_organization(organization)
{:error, %Ecto.Changeset{}}
"""
def delete_organization(%Organization{} = organization) do
Repo.delete(organization)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking organization changes.
## Examples
iex> change_organization(organization)
%Ecto.Changeset{data: %Organization{}}
"""
def change_organization(%Organization{} = organization, attrs \\ %{}) do
Organization.changeset(organization, attrs)
end
end