Skip to content

Commit

Permalink
Add proper documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Aug 5, 2023
1 parent 1d9331d commit 40d6902
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 90 deletions.
75 changes: 69 additions & 6 deletions lib/atomic/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,36 @@ defmodule Atomic.Accounts do
|> Repo.insert()
end

@doc """
List all users.
## Examples
iex > list_users()
{:ok, [%User{}]}
iex > list_users()
{:error, %Ecto.Changeset{}}
"""
def list_users do
User
|> Repo.all()
end

@doc """
Gets a course by id.
Raises `Ecto.NoResultsError` if the Course does not exist.
## Examples
iex> get_course(123)
%Course{}
iex> get_course(456)
** (Ecto.NoResultsError)
"""
def get_course(id) do
Repo.get(Course, id)
end
Expand Down Expand Up @@ -417,29 +442,59 @@ defmodule Atomic.Accounts do
end
end

@doc """
Updates the user picture.
## Examples
iex> update_user_picture(user, %{profile_picture: ...})
{:ok, %User{}}
iex> update_user_picture(user, %{profile_picture: ...})
{:error, %Ecto.Changeset{}}
"""
def update_user_picture(%User{} = user, attrs \\ %{}) do
user
|> User.picture_changeset(attrs)
|> Repo.update()
end

@doc """
Updates the user.
## Examples
iex> update_user(user, %{field: value})
{:ok, %User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_user(%User{} = user, attrs \\ %{}) do
user
|> User.changeset(attrs)
|> Repo.update()
end

def change_user(%User{} = user, attrs \\ %{}) do
user
|> User.changeset(attrs)
end
@doc """
Gets a list of courses.
## Examples
iex> list_courses()
{:ok,[%Course{}]}
iex> list_courses()
{:error, %Ecto.Changeset{}}
"""
def list_courses do
Repo.all(Course)
end

@doc """
Creates a course
Creates a course.
## Examples
Expand All @@ -457,7 +512,15 @@ defmodule Atomic.Accounts do
end

@doc """
Gets the user's organizations
Gets an user organizations.
## Examples
iex> get_user_organizations(user)
{:ok,[%Organization{}]}
iex> get_user_organizations(user)
{:error, %Ecto.Changeset{}}
"""
def get_user_organizations(user) do
Repo.all(Ecto.assoc(user, :organizations))
Expand Down
4 changes: 4 additions & 0 deletions lib/atomic/accounts/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ defmodule Atomic.Accounts.Course do
timestamps()
end

@doc """
A changeset for a course.
"""
def changeset(course, attrs) do
course
|> cast(attrs, @required_fields)
Expand Down
3 changes: 3 additions & 0 deletions lib/atomic/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ defmodule Atomic.Accounts.User do
|> cast_attachments(attrs, [:profile_picture])
end

@doc """
A user changeset for updating the user.
"""
def changeset(user, attrs) do
user
|> cast(attrs, @required_fields ++ @optional_fields)
Expand Down
Loading

0 comments on commit 40d6902

Please sign in to comment.