diff --git a/Backend/controllers/NMK_controllers.go b/Backend/controllers/NMK_controllers.go index 2993759..a9c06cd 100644 --- a/Backend/controllers/NMK_controllers.go +++ b/Backend/controllers/NMK_controllers.go @@ -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) { @@ -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 @@ -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() diff --git a/Backend/controllers/auth_controller.go b/Backend/controllers/auth_controller.go index 770e4a8..a1b17f2 100644 --- a/Backend/controllers/auth_controller.go +++ b/Backend/controllers/auth_controller.go @@ -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 @@ -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 diff --git a/Backend/controllers/doctor_controller.go b/Backend/controllers/doctor_controller.go index f8be539..0f71291 100644 --- a/Backend/controllers/doctor_controller.go +++ b/Backend/controllers/doctor_controller.go @@ -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 @@ -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) { diff --git a/Backend/controllers/home_remedies.go b/Backend/controllers/home_remedies.go index 4523f76..69ce88e 100644 --- a/Backend/controllers/home_remedies.go +++ b/Backend/controllers/home_remedies.go @@ -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 diff --git a/Backend/controllers/user_controllers.go b/Backend/controllers/user_controllers.go index 9001907..25590ac 100644 --- a/Backend/controllers/user_controllers.go +++ b/Backend/controllers/user_controllers.go @@ -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) { @@ -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 diff --git a/Backend/docs/docs.go b/Backend/docs/docs.go index 3d5d8c6..a4093f2 100644 --- a/Backend/docs/docs.go +++ b/Backend/docs/docs.go @@ -15,9 +15,9 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/Homeremedies": { + "/NMK": { "get": { - "description": "Get all Homeremedies details", + "description": "Fetch all NMK codes, with optional filtering based on query parameters such as email, role, and NMK code.", "consumes": [ "application/json" ], @@ -25,22 +25,73 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Homeremedies" + "NMK" + ], + "summary": "Retrieve all NMK codes", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Filter by user email", + "name": "email", + "in": "query" + }, + { + "type": "string", + "description": "Filter by role; requires superadmin privileges to access unverified NMK codes", + "name": "role", + "in": "query" + }, + { + "type": "string", + "description": "Filter by NMK Code", + "name": "NMK_Code", + "in": "query" + } ], - "summary": "Get all Homeremedies details", "responses": { "200": { - "description": "OK", + "description": "Successfully retrieved NMK codes", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.NMK" + } + } + }, + "400": { + "description": "Invalid NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to fetch NMK codes", "schema": { - "$ref": "#/definitions/models.Homeremedies" + "type": "object", + "additionalProperties": true } } } } }, - "/NMK": { - "get": { - "description": "Get all NMK codes", + "/NMK/approve": { + "post": { + "description": "Approves an NMK code, setting its IsVerified status to true.", "consumes": [ "application/json" ], @@ -50,20 +101,212 @@ const docTemplate = `{ "tags": [ "NMK" ], - "summary": "Get all NMK codes", + "summary": "Approve an existing NMK code by ID", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "ID of the NMK code to approve", + "name": "id", + "in": "path", + "required": true + } + ], "responses": { "200": { - "description": "OK", + "description": "Successfully approved NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Invalid NMK code ID", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to approve NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/addDoctor": { + "post": { + "description": "Add a new doctor to the system with the details provided in the request body.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Doctors" + ], + "summary": "Add a new doctor", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Doctor data", + "name": "doctor", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.DoctorData" + } + } + ], + "responses": { + "201": { + "description": "Successfully added doctor", + "schema": { + "$ref": "#/definitions/models.DoctorData" + } + }, + "400": { + "description": "Failed to parse request body", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Failed to insert doctor", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/addNMK": { + "post": { + "description": "Creates a new NMK code in the repository. The new NMK code is initially marked as unverified.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NMK" + ], + "summary": "Add a new NMK code", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "New NMK Code details", + "name": "nmk", + "in": "body", + "required": true, "schema": { "$ref": "#/definitions/models.NMK" } } + ], + "responses": { + "201": { + "description": "Successfully added NMK code", + "schema": { + "$ref": "#/definitions/models.NMK" + } + }, + "400": { + "description": "Failed to bind NMK data", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to insert NMK data", + "schema": { + "type": "object", + "additionalProperties": true + } + } } } }, - "/doctors": { + "/addPatient": { + "post": { + "description": "Add a new patient by binding the request data and inserting into the repository", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Add a new patient", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "User data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.User" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Failed to bind user data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Error inserting user", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/doctor": { "get": { - "description": "Get all doctors", + "description": "Retrieve all doctors, with filtering options based on query parameters.", "consumes": [ "application/json" ], @@ -73,12 +316,210 @@ const docTemplate = `{ "tags": [ "Doctors" ], - "summary": "Get all doctors", + "summary": "Retrieve all doctors", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "enum": [ + "superadmin", + "admin", + "user" + ], + "type": "string", + "description": "Role", + "name": "role", + "in": "query" + }, + { + "type": "string", + "description": "Doctor Code", + "name": "Doctor_Code", + "in": "query" + } + ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.DoctorData" + "type": "array", + "items": { + "$ref": "#/definitions/models.DoctorData" + } + } + }, + "500": { + "description": "Failed to fetch doctors", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/home-remedies": { + "get": { + "description": "Fetch all Homeremedies details, with optional filtering based on query parameters.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Homeremedies" + ], + "summary": "Retrieve all Homeremedies details", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Homeremedies ID", + "name": "id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Successfully retrieved Homeremedies details", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Homeremedies" + } + } + }, + "400": { + "description": "Invalid value for 'id'", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Failed to fetch Homeremedies details", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/signIn": { + "post": { + "description": "Verify a user's email and password. If verified, a JWT token is generated and returned.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "Verify user credentials", + "parameters": [ + { + "description": "User sign-in details", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.SignIn" + } + } + ], + "responses": { + "200": { + "description": "User verified successfully, token returned", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Bad request, invalid input data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized, invalid email or password", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/signUp": { + "post": { + "description": "Register a new user by providing email, password, and other required fields. It checks if the email already exists before adding the user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "Register a new user", + "parameters": [ + { + "description": "User signup details", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.SignUp" + } + } + ], + "responses": { + "200": { + "description": "User registered successfully", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Bad request, invalid input data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "409": { + "description": "Conflict, email already exists", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" } } } @@ -86,7 +527,7 @@ const docTemplate = `{ }, "/users": { "get": { - "description": "Get users based on query parameters", + "description": "Fetch users by passing optional query parameters to filter results", "consumes": [ "application/json" ], @@ -96,38 +537,66 @@ const docTemplate = `{ "tags": [ "User" ], - "summary": "Get users", + "summary": "Retrieve users based on filters", "parameters": [ { "type": "string", - "description": "Addiction Type", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Filter by Addiction Type", "name": "Addiction_Type", "in": "query" }, { "type": "string", - "description": "Nasha Mukti Centre Code", + "description": "Filter by Nasha Mukti Centre Code", "name": "Nasha_Mukti_Centre_Code", "in": "query" }, { "type": "integer", - "description": "Employment Status", + "description": "Filter by Employment Status (integer)", "name": "Employment_Status", "in": "query" }, { "type": "boolean", - "description": "Is Treatment Completed", + "description": "Filter by Treatment Completion status (boolean)", "name": "Is_Treatment_Completed", "in": "query" } ], "responses": { "200": { - "description": "OK", + "description": "List of users", "schema": { - "$ref": "#/definitions/models.User" + "type": "array", + "items": { + "$ref": "#/definitions/models.User" + } + } + }, + "400": { + "description": "Bad request, invalid query parameters", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" } } } @@ -249,6 +718,40 @@ const docTemplate = `{ } } }, + "models.SignIn": { + "type": "object", + "properties": { + "Email": { + "type": "string" + }, + "Password": { + "type": "string" + } + } + }, + "models.SignUp": { + "type": "object", + "properties": { + "Email": { + "type": "string" + }, + "Password": { + "type": "string" + }, + "Role": { + "type": "string" + }, + "Username": { + "type": "string" + }, + "_id": { + "type": "string" + }, + "un": { + "type": "string" + } + } + }, "models.User": { "type": "object", "properties": { @@ -310,6 +813,16 @@ const docTemplate = `{ "type": "string" } } + }, + "responses.ApplicationResponse": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string" + }, + "status": {} + } } } }` diff --git a/Backend/docs/swagger.json b/Backend/docs/swagger.json index fe08600..800881c 100644 --- a/Backend/docs/swagger.json +++ b/Backend/docs/swagger.json @@ -4,9 +4,9 @@ "contact": {} }, "paths": { - "/Homeremedies": { + "/NMK": { "get": { - "description": "Get all Homeremedies details", + "description": "Fetch all NMK codes, with optional filtering based on query parameters such as email, role, and NMK code.", "consumes": [ "application/json" ], @@ -14,22 +14,73 @@ "application/json" ], "tags": [ - "Homeremedies" + "NMK" + ], + "summary": "Retrieve all NMK codes", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Filter by user email", + "name": "email", + "in": "query" + }, + { + "type": "string", + "description": "Filter by role; requires superadmin privileges to access unverified NMK codes", + "name": "role", + "in": "query" + }, + { + "type": "string", + "description": "Filter by NMK Code", + "name": "NMK_Code", + "in": "query" + } ], - "summary": "Get all Homeremedies details", "responses": { "200": { - "description": "OK", + "description": "Successfully retrieved NMK codes", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.NMK" + } + } + }, + "400": { + "description": "Invalid NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to fetch NMK codes", "schema": { - "$ref": "#/definitions/models.Homeremedies" + "type": "object", + "additionalProperties": true } } } } }, - "/NMK": { - "get": { - "description": "Get all NMK codes", + "/NMK/approve": { + "post": { + "description": "Approves an NMK code, setting its IsVerified status to true.", "consumes": [ "application/json" ], @@ -39,20 +90,212 @@ "tags": [ "NMK" ], - "summary": "Get all NMK codes", + "summary": "Approve an existing NMK code by ID", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "ID of the NMK code to approve", + "name": "id", + "in": "path", + "required": true + } + ], "responses": { "200": { - "description": "OK", + "description": "Successfully approved NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Invalid NMK code ID", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to approve NMK code", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/addDoctor": { + "post": { + "description": "Add a new doctor to the system with the details provided in the request body.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Doctors" + ], + "summary": "Add a new doctor", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Doctor data", + "name": "doctor", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.DoctorData" + } + } + ], + "responses": { + "201": { + "description": "Successfully added doctor", + "schema": { + "$ref": "#/definitions/models.DoctorData" + } + }, + "400": { + "description": "Failed to parse request body", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Failed to insert doctor", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/addNMK": { + "post": { + "description": "Creates a new NMK code in the repository. The new NMK code is initially marked as unverified.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NMK" + ], + "summary": "Add a new NMK code", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "New NMK Code details", + "name": "nmk", + "in": "body", + "required": true, "schema": { "$ref": "#/definitions/models.NMK" } } + ], + "responses": { + "201": { + "description": "Successfully added NMK code", + "schema": { + "$ref": "#/definitions/models.NMK" + } + }, + "400": { + "description": "Failed to bind NMK data", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Failed to insert NMK data", + "schema": { + "type": "object", + "additionalProperties": true + } + } } } }, - "/doctors": { + "/addPatient": { + "post": { + "description": "Add a new patient by binding the request data and inserting into the repository", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Add a new patient", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "User data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.User" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Failed to bind user data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Error inserting user", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/doctor": { "get": { - "description": "Get all doctors", + "description": "Retrieve all doctors, with filtering options based on query parameters.", "consumes": [ "application/json" ], @@ -62,12 +305,210 @@ "tags": [ "Doctors" ], - "summary": "Get all doctors", + "summary": "Retrieve all doctors", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "enum": [ + "superadmin", + "admin", + "user" + ], + "type": "string", + "description": "Role", + "name": "role", + "in": "query" + }, + { + "type": "string", + "description": "Doctor Code", + "name": "Doctor_Code", + "in": "query" + } + ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.DoctorData" + "type": "array", + "items": { + "$ref": "#/definitions/models.DoctorData" + } + } + }, + "500": { + "description": "Failed to fetch doctors", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/home-remedies": { + "get": { + "description": "Fetch all Homeremedies details, with optional filtering based on query parameters.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Homeremedies" + ], + "summary": "Retrieve all Homeremedies details", + "parameters": [ + { + "type": "string", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Homeremedies ID", + "name": "id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Successfully retrieved Homeremedies details", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Homeremedies" + } + } + }, + "400": { + "description": "Invalid value for 'id'", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Failed to fetch Homeremedies details", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/signIn": { + "post": { + "description": "Verify a user's email and password. If verified, a JWT token is generated and returned.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "Verify user credentials", + "parameters": [ + { + "description": "User sign-in details", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.SignIn" + } + } + ], + "responses": { + "200": { + "description": "User verified successfully, token returned", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Bad request, invalid input data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized, invalid email or password", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + } + } + } + }, + "/signUp": { + "post": { + "description": "Register a new user by providing email, password, and other required fields. It checks if the email already exists before adding the user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Auth" + ], + "summary": "Register a new user", + "parameters": [ + { + "description": "User signup details", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.SignUp" + } + } + ], + "responses": { + "200": { + "description": "User registered successfully", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "400": { + "description": "Bad request, invalid input data", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "409": { + "description": "Conflict, email already exists", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" } } } @@ -75,7 +516,7 @@ }, "/users": { "get": { - "description": "Get users based on query parameters", + "description": "Fetch users by passing optional query parameters to filter results", "consumes": [ "application/json" ], @@ -85,38 +526,66 @@ "tags": [ "User" ], - "summary": "Get users", + "summary": "Retrieve users based on filters", "parameters": [ { "type": "string", - "description": "Addiction Type", + "description": "Bearer token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Filter by Addiction Type", "name": "Addiction_Type", "in": "query" }, { "type": "string", - "description": "Nasha Mukti Centre Code", + "description": "Filter by Nasha Mukti Centre Code", "name": "Nasha_Mukti_Centre_Code", "in": "query" }, { "type": "integer", - "description": "Employment Status", + "description": "Filter by Employment Status (integer)", "name": "Employment_Status", "in": "query" }, { "type": "boolean", - "description": "Is Treatment Completed", + "description": "Filter by Treatment Completion status (boolean)", "name": "Is_Treatment_Completed", "in": "query" } ], "responses": { "200": { - "description": "OK", + "description": "List of users", "schema": { - "$ref": "#/definitions/models.User" + "type": "array", + "items": { + "$ref": "#/definitions/models.User" + } + } + }, + "400": { + "description": "Bad request, invalid query parameters", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "401": { + "description": "Unauthorized access", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/responses.ApplicationResponse" } } } @@ -238,6 +707,40 @@ } } }, + "models.SignIn": { + "type": "object", + "properties": { + "Email": { + "type": "string" + }, + "Password": { + "type": "string" + } + } + }, + "models.SignUp": { + "type": "object", + "properties": { + "Email": { + "type": "string" + }, + "Password": { + "type": "string" + }, + "Role": { + "type": "string" + }, + "Username": { + "type": "string" + }, + "_id": { + "type": "string" + }, + "un": { + "type": "string" + } + } + }, "models.User": { "type": "object", "properties": { @@ -299,6 +802,16 @@ "type": "string" } } + }, + "responses.ApplicationResponse": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string" + }, + "status": {} + } } } } \ No newline at end of file diff --git a/Backend/docs/swagger.yaml b/Backend/docs/swagger.yaml index e22a1ec..174caf7 100644 --- a/Backend/docs/swagger.yaml +++ b/Backend/docs/swagger.yaml @@ -74,6 +74,28 @@ definitions: State: type: string type: object + models.SignIn: + properties: + Email: + type: string + Password: + type: string + type: object + models.SignUp: + properties: + _id: + type: string + Email: + type: string + Password: + type: string + Role: + type: string + Username: + type: string + un: + type: string + type: object models.User: properties: _id: @@ -115,73 +137,388 @@ definitions: Under_Treatment: type: boolean type: object + responses.ApplicationResponse: + properties: + data: {} + message: + type: string + status: {} + type: object info: contact: {} paths: - /Homeremedies: + /NMK: get: consumes: - application/json - description: Get all Homeremedies details + description: Fetch all NMK codes, with optional filtering based on query parameters + such as email, role, and NMK code. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: Filter by user email + in: query + name: email + type: string + - description: Filter by role; requires superadmin privileges to access unverified + NMK codes + in: query + name: role + type: string + - description: Filter by NMK Code + in: query + name: NMK_Code + type: string produces: - application/json responses: "200": - description: OK + description: Successfully retrieved NMK codes + schema: + items: + $ref: '#/definitions/models.NMK' + type: array + "400": + description: Invalid NMK code schema: - $ref: '#/definitions/models.Homeremedies' - summary: Get all Homeremedies details + additionalProperties: true + type: object + "401": + description: Unauthorized access + schema: + additionalProperties: true + type: object + "500": + description: Failed to fetch NMK codes + schema: + additionalProperties: true + type: object + summary: Retrieve all NMK codes tags: - - Homeremedies - /NMK: - get: + - NMK + /NMK/approve: + post: consumes: - application/json - description: Get all NMK codes + description: Approves an NMK code, setting its IsVerified status to true. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: ID of the NMK code to approve + in: path + name: id + required: true + type: string produces: - application/json responses: "200": - description: OK + description: Successfully approved NMK code + schema: + additionalProperties: true + type: object + "400": + description: Invalid NMK code ID + schema: + additionalProperties: true + type: object + "500": + description: Failed to approve NMK code + schema: + additionalProperties: true + type: object + summary: Approve an existing NMK code by ID + tags: + - NMK + /addDoctor: + post: + consumes: + - application/json + description: Add a new doctor to the system with the details provided in the + request body. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: Doctor data + in: body + name: doctor + required: true + schema: + $ref: '#/definitions/models.DoctorData' + produces: + - application/json + responses: + "201": + description: Successfully added doctor + schema: + $ref: '#/definitions/models.DoctorData' + "400": + description: Failed to parse request body + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Failed to insert doctor + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Add a new doctor + tags: + - Doctors + /addNMK: + post: + consumes: + - application/json + description: Creates a new NMK code in the repository. The new NMK code is initially + marked as unverified. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: New NMK Code details + in: body + name: nmk + required: true + schema: + $ref: '#/definitions/models.NMK' + produces: + - application/json + responses: + "201": + description: Successfully added NMK code schema: $ref: '#/definitions/models.NMK' - summary: Get all NMK codes + "400": + description: Failed to bind NMK data + schema: + additionalProperties: true + type: object + "500": + description: Failed to insert NMK data + schema: + additionalProperties: true + type: object + summary: Add a new NMK code tags: - NMK - /doctors: + /addPatient: + post: + consumes: + - application/json + description: Add a new patient by binding the request data and inserting into + the repository + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: User data + in: body + name: user + required: true + schema: + $ref: '#/definitions/models.User' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "400": + description: Failed to bind user data + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Error inserting user + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Add a new patient + tags: + - User + /doctor: get: consumes: - application/json - description: Get all doctors + description: Retrieve all doctors, with filtering options based on query parameters. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: Role + enum: + - superadmin + - admin + - user + in: query + name: role + type: string + - description: Doctor Code + in: query + name: Doctor_Code + type: string produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/models.DoctorData' - summary: Get all doctors + items: + $ref: '#/definitions/models.DoctorData' + type: array + "500": + description: Failed to fetch doctors + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Retrieve all doctors tags: - Doctors + /home-remedies: + get: + consumes: + - application/json + description: Fetch all Homeremedies details, with optional filtering based on + query parameters. + parameters: + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: Homeremedies ID + in: query + name: id + type: integer + produces: + - application/json + responses: + "200": + description: Successfully retrieved Homeremedies details + schema: + items: + $ref: '#/definitions/models.Homeremedies' + type: array + "400": + description: Invalid value for 'id' + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "401": + description: Unauthorized access + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Failed to fetch Homeremedies details + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Retrieve all Homeremedies details + tags: + - Homeremedies + /signIn: + post: + consumes: + - application/json + description: Verify a user's email and password. If verified, a JWT token is + generated and returned. + parameters: + - description: User sign-in details + in: body + name: user + required: true + schema: + $ref: '#/definitions/models.SignIn' + produces: + - application/json + responses: + "200": + description: User verified successfully, token returned + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "400": + description: Bad request, invalid input data + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "401": + description: Unauthorized, invalid email or password + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Internal server error + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Verify user credentials + tags: + - Auth + /signUp: + post: + consumes: + - application/json + description: Register a new user by providing email, password, and other required + fields. It checks if the email already exists before adding the user. + parameters: + - description: User signup details + in: body + name: user + required: true + schema: + $ref: '#/definitions/models.SignUp' + produces: + - application/json + responses: + "200": + description: User registered successfully + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "400": + description: Bad request, invalid input data + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "409": + description: Conflict, email already exists + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Internal server error + schema: + $ref: '#/definitions/responses.ApplicationResponse' + summary: Register a new user + tags: + - Auth /users: get: consumes: - application/json - description: Get users based on query parameters + description: Fetch users by passing optional query parameters to filter results parameters: - - description: Addiction Type + - description: Bearer token + in: header + name: Authorization + required: true + type: string + - description: Filter by Addiction Type in: query name: Addiction_Type type: string - - description: Nasha Mukti Centre Code + - description: Filter by Nasha Mukti Centre Code in: query name: Nasha_Mukti_Centre_Code type: string - - description: Employment Status + - description: Filter by Employment Status (integer) in: query name: Employment_Status type: integer - - description: Is Treatment Completed + - description: Filter by Treatment Completion status (boolean) in: query name: Is_Treatment_Completed type: boolean @@ -189,10 +526,24 @@ paths: - application/json responses: "200": - description: OK + description: List of users + schema: + items: + $ref: '#/definitions/models.User' + type: array + "400": + description: Bad request, invalid query parameters + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "401": + description: Unauthorized access + schema: + $ref: '#/definitions/responses.ApplicationResponse' + "500": + description: Internal server error schema: - $ref: '#/definitions/models.User' - summary: Get users + $ref: '#/definitions/responses.ApplicationResponse' + summary: Retrieve users based on filters tags: - User swagger: "2.0"