Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Krrupa committed Jul 4, 2023
2 parents 6535df3 + 316af22 commit 8825257
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 24 deletions.
2 changes: 2 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ config :phoenix, :stacktrace_depth, 20

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime

config :dbservice, :environment, :dev
2 changes: 2 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ config :logger, level: :info
#
# config :dbservice, DbserviceWeb.Endpoint,
# force_ssl: [hsts: true]

config :dbservice, :environment, :prod
20 changes: 10 additions & 10 deletions lib/dbservice/schools/enrollment_record.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ defmodule Dbservice.Schools.EnrollmentRecord do
alias Dbservice.Groups.Group

schema "enrollment_record" do
field :academic_year, :string
field :grade, :string
field :is_current, :boolean, default: false
field :board_medium, :string
field :date_of_school_enrollment, :date
field :date_of_group_enrollment, :date
field(:academic_year, :string)
field(:grade, :string)
field(:is_current, :boolean, default: false)
field(:board_medium, :string)
field(:date_of_school_enrollment, :date)
field(:date_of_group_enrollment, :date)

belongs_to :student, Student
belongs_to :school, School
belongs_to :group, Group
belongs_to(:student, Student)
belongs_to(:school, School)
belongs_to(:group, Group)

timestamps()
end
Expand All @@ -38,7 +38,7 @@ defmodule Dbservice.Schools.EnrollmentRecord do
:date_of_group_enrollment,
:group_id
])
|> validate_required([:student_id, :school_id])
|> validate_required([:student_id])
|> validate_date_of_school_enrollment
end

Expand Down
25 changes: 22 additions & 3 deletions lib/dbservice_web/controllers/enrollment_record_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule DbserviceWeb.EnrollmentRecordController do
alias Dbservice.Schools
alias Dbservice.Schools.EnrollmentRecord

action_fallback DbserviceWeb.FallbackController
action_fallback(DbserviceWeb.FallbackController)

use PhoenixSwagger

Expand All @@ -21,22 +21,41 @@ defmodule DbserviceWeb.EnrollmentRecordController do

swagger_path :index do
get("/api/enrollment-record")

parameters do
params(:query, :string, "The academic year of the student's enrollment",
required: false,
name: "academic_year"
)

params(:query, :string, "The grade of the student's enrollment",
required: false,
name: "grade"
)

params(:query, :string, "The board medium of the student's enrollment",
required: false,
name: "board_medium"
)
end

response(200, "OK", Schema.ref(:EnrollmentRecords))
end

def index(conn, params) do
query =
from m in EnrollmentRecord,
from(m in EnrollmentRecord,
order_by: [asc: m.id],
offset: ^params["offset"],
limit: ^params["limit"]
)

query =
Enum.reduce(params, query, fn {key, value}, acc ->
case String.to_existing_atom(key) do
:offset -> acc
:limit -> acc
atom -> from u in acc, where: field(u, ^atom) == ^value
atom -> from(u in acc, where: field(u, ^atom) == ^value)
end
end)

Expand Down
2 changes: 1 addition & 1 deletion lib/dbservice_web/controllers/session_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule DbserviceWeb.SessionController do
end

swagger_path :index do
get("/api/session?session_id=c714-e1d4-5a42-0f9f-36b3")
get("/api/session")

parameters do
params(:query, :string, "The id the session",
Expand Down
14 changes: 13 additions & 1 deletion lib/dbservice_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule DbserviceWeb.Router do
use DbserviceWeb, :router
use PhoenixSwagger

import Dotenvy

pipeline :api do
plug(:accepts, ["json"])
end
Expand Down Expand Up @@ -36,11 +38,21 @@ defmodule DbserviceWeb.Router do
resources("/group-user", GroupUserController)

def swagger_info do
source(["config/.env", "config/.env"])

host =
if Application.get_env(:dbservice, :environment) == :dev do
"localhost:4000"
else
env!("PHX_HOST", :string!)
end

%{
info: %{
version: "1.0",
title: "DB Service application"
}
},
host: host
}
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/dbservice_web/swagger_schemas/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ defmodule DbserviceWeb.SwaggerSchema.Session do
form_schema_id(:string, "Id for the form schema")
type(:string, "Type of session")
auth_type(:string, "Authentication methods used for session")
activate_signup(:boolean, "Is sign up allowed for this session")
id_generation(:boolean, "Is ID being generated for this session")
redirection(:boolean, "Is the session redirecting to some other platform")
pop_up_form(:boolean, "Is the session showing a pop up form")
activate_signup(:string, "Is sign up allowed for this session")
id_generation(:string, "Is ID being generated for this session")
redirection(:string, "Is the session redirecting to some other platform")
pop_up_form(:string, "Is the session showing a pop up form")
number_of_fields_in_pop_form(:string, "Number of fields in the pop form")
end

example(%{
Expand Down
8 changes: 5 additions & 3 deletions lib/dbservice_web/swagger_schemas/session_occurence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ defmodule DbserviceWeb.SwaggerSchema.SessionOccurence do
description("A session occurrence for a session")

properties do
session_id(:integer, "Session ID")
session_id(:string, "ID of the session")
start_time(:timestamp, "Session occurrence start time")
end_time(:timestamp, "Session occurrence finish time")
session_fk(:integer, "The primary key for session's table")
end

example(%{
session_id: 1,
session_id: "DelhiStudents_B01_44725_unv-nkyh-hnb",
start_time: "2022-02-02T11:00:00Z",
end_time: "2022-02-02T11:30:00Z"
end_time: "2022-02-02T11:30:00Z",
session_fk: 1
})
end
}
Expand Down
5 changes: 3 additions & 2 deletions lib/dbservice_web/swagger_schemas/student.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ defmodule DbserviceWeb.SwaggerSchema.Student do
father_profession(:string, "Father's profession")
mother_profession(:String, "Mother's profession")
mother_education_level(:string, "Mother's education level")
has_internet_access(:boolean, "If the family has internet access")
time_of_device_availability(:string, "Time of device availability for a student")
has_internet_access(:string, "If the family has internet access")
primary_smartphone_owner(:string, "Primary smartphone owner")
primary_smartphone_owner_profession(:string, "Profession of primary smartphone owner")
end
Expand All @@ -45,7 +46,7 @@ defmodule DbserviceWeb.SwaggerSchema.Student do
mother_profession: "Housewife",
mother_education_level: "UG",
time_of_device_availability: "2022-10-07",
has_internet_access: true,
has_internet_access: "Yes",
primary_smartphone_owner: "Father",
primary_smartphone_owner_profession: "Employed"
})
Expand Down

0 comments on commit 8825257

Please sign in to comment.