Skip to content

Commit

Permalink
Merge pull request #132 from Ratnesh-Team/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ratnesh-maurya authored Oct 21, 2024
2 parents fafab0d + 8f74a94 commit a12d9e7
Show file tree
Hide file tree
Showing 8 changed files with 1,556 additions and 103 deletions.
43 changes: 28 additions & 15 deletions Backend/controllers/NMK_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

// GetNMK is a handler to get all NMK codes.
// GetNMK is a handler to retrieve all NMK codes.
// It fetches all NMK codes from the repository and returns them as a response.
// @Summary Get all NMK codes
// @Description Get all NMK codes
// @Summary Retrieve all NMK codes
// @Description Fetch all NMK codes, with optional filtering based on query parameters such as email, role, and NMK code.
// @Tags NMK
// @Accept json
// @Produce json
// @Success 200 {object} models.NMK
// @Param Authorization header string true "Bearer token"
// @Param email query string false "Filter by user email"
// @Param role query string false "Filter by role; requires superadmin privileges to access unverified NMK codes"
// @Param NMK_Code query string false "Filter by NMK Code"
// @Success 200 {array} models.NMK "Successfully retrieved NMK codes"
// @Failure 400 {object} map[string]interface{} "Invalid NMK code"
// @Failure 401 {object} map[string]interface{} "Unauthorized access"
// @Failure 500 {object} map[string]interface{} "Failed to fetch NMK codes"
// @Router /NMK [get]
func GetNMK(nmkRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
Expand Down Expand Up @@ -91,15 +98,18 @@ func GetNMK(nmkRepo repository.MongoRepository) gin.HandlerFunc {
}
}

// AddNMK adds a new NMK code.
// AddNMK adds a new NMK code to the repository.
// @Summary Add a new NMK code
// @Description Add a new NMK code to the repository
// @Description Creates a new NMK code in the repository. The new NMK code is initially marked as unverified.
// @Tags NMK
// @Accept json
// @Produce json
// @Param nmk body models.NMK true "New NMK Code"
// @Success 200 {object} models.NMK
// @Router /NMK [post]
// @Param Authorization header string true "Bearer token"
// @Param nmk body models.NMK true "New NMK Code details"
// @Success 201 {object} models.NMK "Successfully added NMK code"
// @Failure 400 {object} map[string]interface{} "Failed to bind NMK data"
// @Failure 500 {object} map[string]interface{} "Failed to insert NMK data"
// @Router /addNMK [post]
func AddNMK(nmkRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var nmk models.NMK
Expand Down Expand Up @@ -131,15 +141,18 @@ func AddNMK(nmkRepo repository.MongoRepository) gin.HandlerFunc {
}
}

// ApproveNMK approves an existing NMK code.
// @Summary Approve an existing NMK code by ID.
// @Description Approves an existing NMK code and sets IsVerified to true.
// ApproveNMK approves an existing NMK code by its ID.
// @Summary Approve an existing NMK code by ID
// @Description Approves an NMK code, setting its IsVerified status to true.
// @Tags NMK
// @Accept json
// @Produce json
// @Param id path string true "NMK ID"
// @Success 200 {object} models.NMKApprovalResponse
// @Router /NMK/{id}/approve [post]
// @Param Authorization header string true "Bearer token"
// @Param id path string true "ID of the NMK code to approve"
// @Success 200 {object} map[string]interface{} "Successfully approved NMK code"
// @Failure 400 {object} map[string]interface{} "Invalid NMK code ID"
// @Failure 500 {object} map[string]interface{} "Failed to approve NMK code"
// @Router /NMK/approve [post]
func ApproveNMK(nmkRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
queryParams := c.Request.URL.Query()
Expand Down
27 changes: 26 additions & 1 deletion Backend/controllers/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ import (
)

// AuthController is a controller for authentication

// AddUser registers a new user.
// It checks if the email already exists in the database and if not, hashes the password and stores the user details.
// @Summary Register a new user
// @Description Register a new user by providing email, password, and other required fields. It checks if the email already exists before adding the user.
// @Tags Auth
// @Accept json
// @Produce json
// @Param user body models.SignUp true "User signup details"
// @Success 200 {object} responses.ApplicationResponse "User registered successfully"
// @Failure 400 {object} responses.ApplicationResponse "Bad request, invalid input data"
// @Failure 409 {object} responses.ApplicationResponse "Conflict, email already exists"
// @Failure 500 {object} responses.ApplicationResponse "Internal server error"
// @Router /signUp [post]
func AddUser(authdb repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var user models.SignUp
Expand Down Expand Up @@ -74,6 +86,19 @@ func AddUser(authdb repository.MongoRepository) gin.HandlerFunc {
}
}

// VerifyUser verifies a user's credentials.
// It checks if the provided email and password match an existing user and returns a JWT token upon successful verification.
// @Summary Verify user credentials
// @Description Verify a user's email and password. If verified, a JWT token is generated and returned.
// @Tags Auth
// @Accept json
// @Produce json
// @Param user body models.SignIn true "User sign-in details"
// @Success 200 {object} responses.ApplicationResponse "User verified successfully, token returned"
// @Failure 400 {object} responses.ApplicationResponse "Bad request, invalid input data"
// @Failure 401 {object} responses.ApplicationResponse "Unauthorized, invalid email or password"
// @Failure 500 {object} responses.ApplicationResponse "Internal server error"
// @Router /signIn [post]
func VerifyUser(authdb repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var user models.SignIn
Expand Down
27 changes: 22 additions & 5 deletions Backend/controllers/doctor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

// GetDoctor is a handler to get all doctors.
// GetDoctor is a handler to retrieve all doctors.
// It fetches all doctors from the repository and returns them as a response.
// @Summary Get all doctors
// @Description Get all doctors
// @Summary Retrieve all doctors
// @Description Retrieve all doctors, with filtering options based on query parameters.
// @Tags Doctors
// @Accept json
// @Produce json
// @Success 200 {object} models.DoctorData
// @Router /doctors [get]
// @Param Authorization header string true "Bearer token"
// @Param role query string false "Role" Enums(superadmin, admin, user)
// @Param Doctor_Code query string false "Doctor Code"
// @Success 200 {array} models.DoctorData
// @Failure 500 {object} responses.ApplicationResponse "Failed to fetch doctors"
// @Router /doctor [get]
func GetDoctor(nmkRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var doctorlist []models.DoctorData
Expand Down Expand Up @@ -71,6 +75,19 @@ func GetDoctor(nmkRepo repository.MongoRepository) gin.HandlerFunc {
}

// this is schema
// AddDoctor is a handler to add a new doctor.
// It inserts a new doctor into the repository and returns the created doctor data.
// @Summary Add a new doctor
// @Description Add a new doctor to the system with the details provided in the request body.
// @Tags Doctors
// @Accept json
// @Produce json
// @Param Authorization header string true "Bearer token"
// @Param doctor body models.DoctorData true "Doctor data"
// @Success 201 {object} models.DoctorData "Successfully added doctor"
// @Failure 400 {object} responses.ApplicationResponse "Failed to parse request body"
// @Failure 500 {object} responses.ApplicationResponse "Failed to insert doctor"
// @Router /addDoctor [post]
func AddDoctor(nmkRepo repository.MongoRepository) gin.HandlerFunc {
// fmt.Println("123")
return func(c *gin.Context) {
Expand Down
15 changes: 10 additions & 5 deletions Backend/controllers/home_remedies.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import (
"go.mongodb.org/mongo-driver/bson"
)

// GetHomeremediesDetails is a handler to get all Homeremedies details.
// GetHomeremediesDetails is a handler to retrieve all Homeremedies details.
// It fetches all Homeremedies details from the repository and returns them as a response.
// @Summary Get all Homeremedies details
// @Description Get all Homeremedies details
// @Summary Retrieve all Homeremedies details
// @Description Fetch all Homeremedies details, with optional filtering based on query parameters.
// @Tags Homeremedies
// @Accept json
// @Produce json
// @Success 200 {object} models.Homeremedies
// @Router /Homeremedies [get]
// @Param Authorization header string true "Bearer token"
// @Param id query int false "Homeremedies ID"
// @Success 200 {array} models.Homeremedies "Successfully retrieved Homeremedies details"
// @Failure 400 {object} responses.ApplicationResponse "Invalid value for 'id'"
// @Failure 401 {object} responses.ApplicationResponse "Unauthorized access"
// @Failure 500 {object} responses.ApplicationResponse "Failed to fetch Homeremedies details"
// @Router /home-remedies [get]
func GetHomeremediesDetails(HomeremediesRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var HomeremediesList []models.Homeremedies
Expand Down
32 changes: 24 additions & 8 deletions Backend/controllers/user_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import (

// GetUsers retrieves users based on query parameters.
// It fetches users from the repository based on the query parameters and returns them as a response.
// @Summary Get users
// @Description Get users based on query parameters
// @Summary Retrieve users based on filters
// @Description Fetch users by passing optional query parameters to filter results
// @Tags User
// @Accept json
// @Produce json
// @Param Addiction_Type query string false "Addiction Type"
// @Param Nasha_Mukti_Centre_Code query string false "Nasha Mukti Centre Code"
// @Param Employment_Status query int false "Employment Status"
// @Param Is_Treatment_Completed query bool false "Is Treatment Completed"
// @Success 200 {object} models.User
// @Param Authorization header string true "Bearer token"
// @Param Addiction_Type query string false "Filter by Addiction Type"
// @Param Nasha_Mukti_Centre_Code query string false "Filter by Nasha Mukti Centre Code"
// @Param Employment_Status query int false "Filter by Employment Status (integer)"
// @Param Is_Treatment_Completed query bool false "Filter by Treatment Completion status (boolean)"
// @Success 200 {array} models.User "List of users"
// @Failure 400 {object} responses.ApplicationResponse "Bad request, invalid query parameters"
// @Failure 401 {object} responses.ApplicationResponse "Unauthorized access"
// @Failure 500 {object} responses.ApplicationResponse "Internal server error"
// @Router /users [get]
func GetUsers(userRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
Expand Down Expand Up @@ -122,7 +126,19 @@ func GetUsers(userRepo repository.MongoRepository) gin.HandlerFunc {
}
}


// AddPatient is a handler to add a new patient.
// It binds the request body to the user model and inserts it into the repository.
// @Summary Add a new patient
// @Description Add a new patient by binding the request data and inserting into the repository
// @Tags User
// @Accept json
// @Produce json
// @Param Authorization header string true "Bearer token"
// @Param user body models.User true "User data"
// @Success 200 {object} responses.ApplicationResponse
// @Failure 400 {object} responses.ApplicationResponse "Failed to bind user data"
// @Failure 500 {object} responses.ApplicationResponse "Error inserting user"
// @Router /addPatient [post]
func AddPatient(userRepo repository.MongoRepository) gin.HandlerFunc {
return func(c *gin.Context) {
var user models.User
Expand Down
Loading

0 comments on commit a12d9e7

Please sign in to comment.