Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gurukul schema #136

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/dbservice/batches.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Dbservice.Batches do
@moduledoc """
The Groups context.
The Batches context.
"""

import Ecto.Query, warn: false
Expand All @@ -12,19 +12,19 @@ defmodule Dbservice.Batches do
@doc """
Returns the list of batch.
## Examples
iex> list_group()
[%Group{}, ...]
iex> list_batch()
[%Batch{}, ...]
"""
def list_batch do
Repo.all(Batch)
end

@doc """
Gets a single batch.
Raises `Ecto.NoResultsError` if the Group does not exist.
Raises `Ecto.NoResultsError` if the batch does not exist.
## Examples
iex> get_batch!(123)
%Group{}
%Batch{}
iex> get_batch!(456)
** (Ecto.NoResultsError)
"""
Expand All @@ -34,7 +34,7 @@ defmodule Dbservice.Batches do
Creates a batch.
## Examples
iex> create_batch(%{field: value})
{:ok, %Group{}}
{:ok, %Batch{}}
iex> create_batch(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
Expand All @@ -49,7 +49,7 @@ defmodule Dbservice.Batches do
Updates a batch.
## Examples
iex> update_batch(batch, %{field: new_value})
{:ok, %Group{}}
{:ok, %Batch{}}
iex> update_batch(batch, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
Expand All @@ -63,7 +63,7 @@ defmodule Dbservice.Batches do
Deletes a batch.
## Examples
iex> delete_batch(batch)
{:ok, %GroupUser{}}
{:ok, %Batch{}}
iex> delete_batch(batch)
{:error, %Ecto.Changeset{}}
"""
Expand All @@ -72,10 +72,10 @@ defmodule Dbservice.Batches do
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking group changes.
Returns an `%Ecto.Changeset{}` for tracking batch changes.
## Examples
iex> change_batch(batch)
%Ecto.Changeset{data: %Groupuser{}}
%Ecto.Changeset{data: %Batch{}}
"""
def change_batch(%Batch{} = batch, attrs \\ %{}) do
Batch.changeset(batch, attrs)
Expand Down
81 changes: 81 additions & 0 deletions lib/dbservice/chapters.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
defmodule Dbservice.Chapters do
@moduledoc """
The Chapters context.
"""

import Ecto.Query, warn: false
alias Dbservice.Repo

alias Dbservice.Chapters.Chapter

@doc """
Returns the list of chapter.
## Examples
iex> list_chapter()
[%Chapter{}, ...]
"""
def list_chapter do
Repo.all(Chapter)
end

@doc """
Gets a single chapter.
Raises `Ecto.NoResultsError` if the chapter does not exist.
## Examples
iex> get_chapter!(123)
%Chapter{}
iex> get_chapter!(456)
** (Ecto.NoResultsError)
"""
def get_chapter!(id), do: Repo.get!(Chapter, id)

@doc """
Creates a chapter.
## Examples
iex> create_chapter(%{field: value})
{:ok, %Chapter{}}
iex> create_chapter(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_chapter(attrs \\ %{}) do
%Chapter{}
|> Chapter.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a chapter.
## Examples
iex> update_chapter(chapter, %{field: new_value})
{:ok, %Chapter{}}
iex> update_chapter(chapter, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_chapter(%Chapter{} = chapter, attrs) do
chapter
|> Chapter.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a chapter.
## Examples
iex> delete_chapter(chapter)
{:ok, %Chapter{}}
iex> delete_chapter(chapter)
{:error, %Ecto.Changeset{}}
"""
def delete_chapter(%Chapter{} = chapter) do
Repo.delete(chapter)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking chapter changes.
## Examples
iex> change_chapter(chapter)
%Ecto.Changeset{data: %Chapter{}}
"""
def change_chapter(%Chapter{} = chapter, attrs \\ %{}) do
Chapter.changeset(chapter, attrs)
end
end
40 changes: 40 additions & 0 deletions lib/dbservice/chapters/chapter.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Dbservice.Chapters.Chapter do
@moduledoc false

use Ecto.Schema
import Ecto.Changeset

alias Dbservice.Grades.Grade
alias Dbservice.Subjects.Subject
alias Dbservice.Tags.Tag
alias Dbservice.Topics.Topic
alias Dbservice.Resources.Resource
alias Dbservice.Curriculums.Curriculum

schema "chapter" do
field(:name, :string)
field(:code, :string)

timestamps()

has_many(:topic, Topic)
has_many(:resource, Resource)
belongs_to(:grade, Grade)
belongs_to(:subject, Subject)
belongs_to(:tag, Tag)
belongs_to(:curriculum, Curriculum)
end

@doc false
def changeset(chapter, attrs) do
chapter
|> cast(attrs, [
:name,
:code,
:grade_id,
:subject_id,
:tag_id,
:curriculum_id
])
end
end
81 changes: 81 additions & 0 deletions lib/dbservice/concepts.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
defmodule Dbservice.Concepts do
@moduledoc """
The Concepts context.
"""

import Ecto.Query, warn: false
alias Dbservice.Repo

alias Dbservice.Concepts.Concept

@doc """
Returns the list of concept.
## Examples
iex> list_concept()
[%Concept{}, ...]
"""
def list_concept do
Repo.all(Concept)
end

@doc """
Gets a single concept.
Raises `Ecto.NoResultsError` if the concept does not exist.
## Examples
iex> get_concept!(123)
%Concept{}
iex> get_concept!(456)
** (Ecto.NoResultsError)
"""
def get_concept!(id), do: Repo.get!(Concept, id)

@doc """
Creates a concept.
## Examples
iex> create_concept(%{field: value})
{:ok, %Concept{}}
iex> create_concept(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_concept(attrs \\ %{}) do
%Concept{}
|> Concept.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a concept.
## Examples
iex> update_concept(concept, %{field: new_value})
{:ok, %Concept{}}
iex> update_concept(concept, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_concept(%Concept{} = concept, attrs) do
concept
|> Concept.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a concept.
## Examples
iex> delete_concept(concept)
{:ok, %Concept{}}
iex> delete_concept(concept)
{:error, %Ecto.Changeset{}}
"""
def delete_concept(%Concept{} = concept) do
Repo.delete(concept)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking concept changes.
## Examples
iex> change_concept(concept)
%Ecto.Changeset{data: %Concept{}}
"""
def change_concept(%Concept{} = concept, attrs \\ %{}) do
Concept.changeset(concept, attrs)
end
end
32 changes: 32 additions & 0 deletions lib/dbservice/concepts/concept.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule Dbservice.Concepts.Concept do
@moduledoc false

use Ecto.Schema
import Ecto.Changeset

alias Dbservice.Topics.Topic
alias Dbservice.Tags.Tag
alias Dbservice.LearningObjectives.LearningObjective
alias Dbservice.Resources.Resource

schema "concept" do
field(:name, :string)

timestamps()

has_many(:learning_objective, LearningObjective)
has_many(:resource, Resource)
belongs_to(:topic, Topic)
belongs_to(:tag, Tag)
end

@doc false
def changeset(concept, attrs) do
concept
|> cast(attrs, [
:name,
:topic_id,
:tag_id
])
end
end
81 changes: 81 additions & 0 deletions lib/dbservice/curriculums.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
defmodule Dbservice.Curriculums do
@moduledoc """
The Curriculums context.
"""

import Ecto.Query, warn: false
alias Dbservice.Repo

alias Dbservice.Curriculums.Curriculum

@doc """
Returns the list of curriculum.
## Examples
iex> list_curriculum()
[%Curriculum{}, ...]
"""
def list_curriculum do
Repo.all(Curriculum)
end

@doc """
Gets a single curriculum.
Raises `Ecto.NoResultsError` if the curriculum does not exist.
## Examples
iex> get_curriculum!(123)
%Curriculum{}
iex> get_curriculum!(456)
** (Ecto.NoResultsError)
"""
def get_curriculum!(id), do: Repo.get!(Curriculum, id)

@doc """
Creates a curriculum.
## Examples
iex> create_curriculum(%{field: value})
{:ok, %Curriculum{}}
iex> create_curriculum(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_curriculum(attrs \\ %{}) do
%Curriculum{}
|> Curriculum.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a curriculum.
## Examples
iex> update_curriculum(curriculum, %{field: new_value})
{:ok, %Curriculum{}}
iex> update_curriculum(curriculum, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_curriculum(%Curriculum{} = curriculum, attrs) do
curriculum
|> Curriculum.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a curriculum.
## Examples
iex> delete_curriculum(curriculum)
{:ok, %Curriculum{}}
iex> delete_curriculum(curriculum)
{:error, %Ecto.Changeset{}}
"""
def delete_curriculum(%Curriculum{} = curriculum) do
Repo.delete(curriculum)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking curriculum changes.
## Examples
iex> change_curriculum(curriculum)
%Ecto.Changeset{data: %Curriculum{}}
"""
def change_curriculum(%Curriculum{} = curriculum, attrs \\ %{}) do
Curriculum.changeset(curriculum, attrs)
end
end
Loading
Loading