From ec5cf9fbd8e58980a85fe49a96e60e042b482ac1 Mon Sep 17 00:00:00 2001 From: Devansh-bit Date: Mon, 18 Dec 2023 10:44:59 +0530 Subject: [PATCH 1/6] docs: /project/ POST --- controllers/project_reg.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/controllers/project_reg.go b/controllers/project_reg.go index 458247a..9d436ec 100644 --- a/controllers/project_reg.go +++ b/controllers/project_reg.go @@ -31,6 +31,25 @@ type RegisterProjectReqFields struct { ReadmeLink string `json:"readme_link"` } +// RegisterProject godoc +// +// @Summary Register a Project +// @Description Register a new project with the provided details. +// @Accept json +// @Produce json +// @Param request body RegisterProjoectReqFields true "Fields required for project registeration" +// @Success 200 {object} utils.HTTPMessage "Success." +// @Failure 401 {object} utils.HTTPMessage "Login username and mentor username do not match." +// @Failure 400 {object} utils.HTTPMessage "Error: Project `project` already exists." +// @Failure 400 {object} utils.HTTPMessage "Error decoding request JSON body." +// @Failure 400 {object} utils.HTTPMessage "Error: Mentor `mentor` does not exist." +// @Failure 400 {object} utils.HTTPMessage "Error: Secondary mentor `secondary_mentor` cannot be same as primary mentor." +// @Failure 500 {object} utils.HTTPMessage "Error fetching mentor `mentor`." +// @Failure 500 {object} utils.HTTPMessage "Error fetching secondary mentor `secondary_mentor`." +// @Failure 500 {object} utils.HTTPMessage "Error adding the project in the database." +// @Failure 500 {object} utils.HTTPMessage "Database error." +// @Security JWT +// @Router /student/form/ [post] func RegisterProject(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db From 56df8d605c2f1240a5fff8bdc064d13406a6aa29 Mon Sep 17 00:00:00 2001 From: Devansh-bit Date: Mon, 18 Dec 2023 10:52:42 +0530 Subject: [PATCH 2/6] docs: /projects/ GET --- controllers/project_fetch.go | 9 +++++++++ controllers/project_reg.go | 2 +- models/projects.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/controllers/project_fetch.go b/controllers/project_fetch.go index 4c16788..9e68ff3 100644 --- a/controllers/project_fetch.go +++ b/controllers/project_fetch.go @@ -55,6 +55,15 @@ func newProject(dbProject *models.Project) Project { } } +// FetchAllProjects godoc +// +// @Summary Fetches all Projects +// @Description Fetches the public details for all the Projects +// @Accept plain +// @Produce json +// @Success 200 {object} []Project "Projects fetched successfully." +// @Failure 500 {object} utils.HTTPMessage "Error fetching projects from the database." +// @Router /project/ [get] func FetchAllProjects(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db diff --git a/controllers/project_reg.go b/controllers/project_reg.go index 9d436ec..3c0a193 100644 --- a/controllers/project_reg.go +++ b/controllers/project_reg.go @@ -49,7 +49,7 @@ type RegisterProjectReqFields struct { // @Failure 500 {object} utils.HTTPMessage "Error adding the project in the database." // @Failure 500 {object} utils.HTTPMessage "Database error." // @Security JWT -// @Router /student/form/ [post] +// @Router /project/ [post] func RegisterProject(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db diff --git a/models/projects.go b/models/projects.go index a4037b6..743c874 100644 --- a/models/projects.go +++ b/models/projects.go @@ -15,7 +15,7 @@ type Project struct { CommChannel string `gorm:"column:comm_channel"` ReadmeLink string `gorm:"column:readme_link"` ProjectStatus bool `gorm:"default:false;column:project_status"` - StatusRemark string `gorm:"default:null;column:status_remark"` + StatusRemark string `gorm:"default:null;column:status_remark"` // for stats LastPullTime int64 `gorm:"column:last_pull_time"` From f6c4a986e4d3ac57af449be593fc3b7ad2db37f5 Mon Sep 17 00:00:00 2001 From: Devansh-bit Date: Mon, 18 Dec 2023 11:07:14 +0530 Subject: [PATCH 3/6] docs: /project/ PUT --- controllers/project_update.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/controllers/project_update.go b/controllers/project_update.go index 6cd5b55..a81ab66 100644 --- a/controllers/project_update.go +++ b/controllers/project_update.go @@ -33,6 +33,28 @@ type UpdateProjectReqFields struct { ReadmeLink string `json:"readme_link"` } +// UpdateProject godoc +// +// @Summary Update Project Details +// @Description Update project details for the provided project ID. +// @Accept json +// @Produce json +// @Param request body UpdateProjectReqFields true "Fields required for Project update." +// @Success 200 {object} utils.HTTPMessage "Project successfully updated." +// @Failure 401 {object} utils.HTTPMessage "Login username and mentor username do not match." +// @Failure 400 {object} utils.HTTPMessage "Error decoding request JSON body." +// @Failure 400 {object} utils.HTTPMessage "Mentor `username` does not exists." +// @Failure 400 {object} utils.HTTPMessage "Invalid Details: Could not update mentor details" +// @Failure 400 {object} utils.HTTPMessage "Error: Project `repo_link` does not exist." +// @Failure 400 {object} utils.HTTPMessage "Error: Mentor `username` does not own the project with ID `id`." +// @Failure 400 {object} utils.HTTPMessage "Error: Secondary mentor `secondary_mentor_username` cannot be same as primary mentor." +// @Failure 500 {object} utils.HTTPMessage "Error updating the project." +// @Failure 500 {object} utils.HTTPMessage "Database error." +// @Failure 500 {object} utils.HTTPMessage "Error fetching secondary mentor `secondary_mentor_username`." +// +// @Security JWT +// +// @Router /project/ [put] func UpdateProject(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db From 0f911fdcbe1542dfbdb2458e694f138a3e6f9123 Mon Sep 17 00:00:00 2001 From: Devansh-bit Date: Mon, 18 Dec 2023 11:14:42 +0530 Subject: [PATCH 4/6] docs: /project/{id} GET --- controllers/mentor.go | 2 +- controllers/project_fetch.go | 14 ++++++++++++++ controllers/project_update.go | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/controllers/mentor.go b/controllers/mentor.go index 57a64d4..1a0141e 100644 --- a/controllers/mentor.go +++ b/controllers/mentor.go @@ -361,7 +361,7 @@ func UpdateMentorDetails(w http.ResponseWriter, r *http.Request) { // @Success 200 {object} models.Mentor "Mentor details fetched successfuly." // @Failure 400 {object} utils.HTTPMessage "Mentor `username` does not exists." // @Security JWT -// @Router /student/form [post] +// @Router /mentor/ [get] func GetMentorDetails(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db diff --git a/controllers/project_fetch.go b/controllers/project_fetch.go index 9e68ff3..925f0a6 100644 --- a/controllers/project_fetch.go +++ b/controllers/project_fetch.go @@ -92,6 +92,20 @@ func FetchAllProjects(w http.ResponseWriter, r *http.Request) { utils.RespondWithJson(r, w, response) } +// FetchProjectDetails godoc +// +// @Summary Fetches Project Details +// @Description Fetches the public details for the Project with the provided ID +// @Accept plain +// @Produce json +// @Param id path int true "Project ID" +// @Success 200 {object} Project "Project fetched successfully." +// @Failure 400 {object} utils.HTTPMessage "Project id not found." +// @Failure 400 {object} utils.HTTPMessage "Error parsing project id." +// @Failure 400 {object} utils.HTTPMessage "Project with id `id` does not exist." +// @Failure 400 {object} utils.HTTPMessage "Error: Mentor `mentor` does not own the project with ID `id`." +// @Failure 500 {object} utils.HTTPMessage "Error fetching project from the database." +// @Router /project/{id} [get] func FetchProjectDetails(w http.ResponseWriter, r *http.Request) { reqParams := mux.Vars(r) diff --git a/controllers/project_update.go b/controllers/project_update.go index a81ab66..b4c4a80 100644 --- a/controllers/project_update.go +++ b/controllers/project_update.go @@ -51,7 +51,7 @@ type UpdateProjectReqFields struct { // @Failure 500 {object} utils.HTTPMessage "Error updating the project." // @Failure 500 {object} utils.HTTPMessage "Database error." // @Failure 500 {object} utils.HTTPMessage "Error fetching secondary mentor `secondary_mentor_username`." -// +// // @Security JWT // // @Router /project/ [put] From f36d8df1be1a35c7faabc9aea370451906c15a49 Mon Sep 17 00:00:00 2001 From: Devansh-bit Date: Mon, 18 Dec 2023 11:24:14 +0530 Subject: [PATCH 5/6] docs: /stats/overall/ GET, /stats/students/ GET, /stats/projects/ GET --- controllers/project_fetch.go | 3 +++ controllers/stats_overall.go | 10 ++++++++++ controllers/stats_project.go | 10 ++++++++++ controllers/stats_student.go | 10 ++++++++++ 4 files changed, 33 insertions(+) diff --git a/controllers/project_fetch.go b/controllers/project_fetch.go index 925f0a6..c00c2ef 100644 --- a/controllers/project_fetch.go +++ b/controllers/project_fetch.go @@ -105,6 +105,9 @@ func FetchAllProjects(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} utils.HTTPMessage "Project with id `id` does not exist." // @Failure 400 {object} utils.HTTPMessage "Error: Mentor `mentor` does not own the project with ID `id`." // @Failure 500 {object} utils.HTTPMessage "Error fetching project from the database." +// +// @Security JWT +// // @Router /project/{id} [get] func FetchProjectDetails(w http.ResponseWriter, r *http.Request) { reqParams := mux.Vars(r) diff --git a/controllers/stats_overall.go b/controllers/stats_overall.go index 8710599..1c3215c 100644 --- a/controllers/stats_overall.go +++ b/controllers/stats_overall.go @@ -16,6 +16,16 @@ type OverallStats struct { GenTime int64 `json:"gen_time"` } +// FetchOverallStats godoc +// +// @Summary Fetches Overall Stats +// @Description Fetches overall stats from the database. +// @Accept plain +// @Produce json +// @Success 200 {object} []OverallStats "Fetched overall stats successfully." +// @Failure 500 {object} utils.HTTPMessage "Error fetching stats from the database." +// +// @Router /stats/overall/ [get] func FetchOverallStats(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db diff --git a/controllers/stats_project.go b/controllers/stats_project.go index 5526b82..c9c7694 100644 --- a/controllers/stats_project.go +++ b/controllers/stats_project.go @@ -17,6 +17,16 @@ type ProjectStats struct { LinesRemoved uint `json:"lines_removed"` } +// FetchAllProjectStats godoc +// +// @Summary Fetches all Project Stats +// @Description Fetches all project stats from the database. +// @Accept plain +// @Produce json +// @Success 200 {object} []ProjectStats "Fetch project stats successfully." +// @Failure 500 {object} utils.HTTPMessage "Error fetching project stats from the database." +// +// @Router /stats/projects/ [get] func FetchAllProjectStats(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db diff --git a/controllers/stats_student.go b/controllers/stats_student.go index 2431924..6d6d7f3 100644 --- a/controllers/stats_student.go +++ b/controllers/stats_student.go @@ -17,6 +17,16 @@ type StudentBriefStats struct { LinesRemoved uint `json:"lines_removed"` } +// FetchAllStudentStats godoc +// +// @Summary Fetches all Student Stats +// @Description Fetches all student stats from the database. +// @Accept plain +// @Produce json +// @Success 200 {object} []StudentBriefStats "Success." +// @Failure 500 {object} utils.HTTPMessage "Error fetching student stats from the database." +// +// @Router /stats/students/ [get] func FetchAllStudentStats(w http.ResponseWriter, r *http.Request) { app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) db := app.Db From dfc06c2568b747b2cb1707c684bd8fabfdfe073a Mon Sep 17 00:00:00 2001 From: Devansh Gupta <67866743+Devansh-bit@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:53:15 +0530 Subject: [PATCH 6/6] docs: requested changes Co-authored-by: Harsh Khandeparkar Signed-off-by: Devansh Gupta <67866743+Devansh-bit@users.noreply.github.com> --- controllers/project_fetch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/project_fetch.go b/controllers/project_fetch.go index c00c2ef..8b2c8ef 100644 --- a/controllers/project_fetch.go +++ b/controllers/project_fetch.go @@ -95,7 +95,7 @@ func FetchAllProjects(w http.ResponseWriter, r *http.Request) { // FetchProjectDetails godoc // // @Summary Fetches Project Details -// @Description Fetches the public details for the Project with the provided ID +// @Description Fetches all the details for the Project with the provided ID provided the logged in user owns the project. // @Accept plain // @Produce json // @Param id path int true "Project ID"