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

verify-student endpoint in student controller #209

Merged
merged 5 commits into from
Aug 14, 2024
Merged

Conversation

Abhinav-3009
Copy link
Collaborator

Overview

Created a new API endpoint for verifying student information. The endpoint allows for the validation of student and user data and group-user record against provided student_id and auth_group_id and other parameters.

Functionality

  1. Accepts a student ID and verification parameters.
  2. Retrieves the student and associated user data.
  3. Verifies the provided parameters against the student and user data.
  4. Retrieves the group-user record using auth_group_id.
  5. Returns response as true if verification parameters matches with data and group-user record exists else return false.

Comment on lines 60 to 72
@doc """
Gets group by child_id and type.
Raises `Ecto.NoResultsError` if the Group does not exist.
## Examples
iex> get_group_by_child_id_and_type(123,"batch")
%Group{}
iex> get_group_by_child_id_and_type(456,"batch")
** (Ecto.NoResultsError)
"""
def get_group_by_child_id_and_type(child_id, type) do
Repo.get_by(Group, child_id: child_id, type: type)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is already defined above where type is hardcoded. Maybe we can reuse that and also pass "batch" as argument where it was used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have done the same in the latest commit.

key == "date_of_birth" ->
user_dob = Map.get(user, String.to_existing_atom(key))
parsed_value = Date.from_iso8601!(value)
Date.compare(user_dob, parsed_value) == :eq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if user_dob and parsed_value are not equal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns false if user_dob and parsed_value are equal, and if any condition is false then the function inside Enum.all() will return false.

@@ -45,16 +45,16 @@ defmodule Dbservice.Groups do
end

@doc """
Gets group by child_id.
Gets group by child_id and type.
Raises `Ecto.NoResultsError` if the Group does not exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment also to say that error will be returned if type is wrong or does not exist

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update the comment.

post("/api/student/verify-student")

parameters do
body(:body, Schema.ref(:VerifyStudentRequest), "The verify student request", required: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the message to read bette. Instead of "The verify student requrest", "parameters needed for student veritication" or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update the message.

example(%{
student_id: "20190240808",
verification_params: %{
auth_group_id: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can't verify with auth group name (PunjabStudents, DelhiStudents, etc?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are getting auth_group_id as query param in the portal-backend from portal-frontend.

end

defp get_student_and_user(student_id) do
case Users.get_student_by_student_id(student_id) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it Users.get_student... and not Students.get_student?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the Ecto query functions for User, Student and Teacher are present in this Users module.

@Bahugunajii Bahugunajii self-requested a review August 14, 2024 08:49
@Bahugunajii Bahugunajii merged commit dea79d8 into main Aug 14, 2024
1 check passed
@Bahugunajii Bahugunajii deleted the verify-student branch August 14, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants