-
Notifications
You must be signed in to change notification settings - Fork 5
Pagination and search in student list in admin portal #52
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
base: main
Are you sure you want to change the base?
Changes from all commits
853529a
940ebae
554b64e
c8c9009
80908a9
db0bab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package handler | |
|
|
||
| import ( | ||
| "net/http" | ||
| "strconv" | ||
|
|
||
| "github.com/FrosTiK-SD/auth/constants" | ||
| "github.com/FrosTiK-SD/auth/controller" | ||
|
|
@@ -11,8 +12,12 @@ import ( | |
|
|
||
| func (h *Handler) GetAllCompanies(ctx *gin.Context) { | ||
| noCache := util.GetNoCache(ctx) | ||
| currentPage := 0 | ||
|
|
||
| companies, err := controller.GetAllCompanies(h.MongikClient, noCache) | ||
| currentPage, err := strconv.Atoi(ctx.Request.URL.Query().Get("page")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ctx.DefaultQuery()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will refactor the companies pagination in another pr. Currently it works as expected. |
||
| companiesPerPage, err := strconv.Atoi(ctx.Request.URL.Query().Get("limit")) | ||
|
|
||
| companies, totalCompanies, err := controller.GetAllCompanies(h.MongikClient, noCache, currentPage, companiesPerPage) | ||
|
|
||
| if err != nil { | ||
| ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{ | ||
|
|
@@ -23,6 +28,7 @@ func (h *Handler) GetAllCompanies(ctx *gin.Context) { | |
| } | ||
|
|
||
| ctx.JSON(http.StatusOK, gin.H{ | ||
| "data": companies, | ||
| "data": companies, | ||
| "totalCompanies": totalCompanies, | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package handler | |
| import ( | ||
| "net/http" | ||
| "os" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/FrosTiK-SD/auth/constants" | ||
|
|
@@ -27,22 +28,32 @@ func GetStudentRoleObjectID() primitive.ObjectID { | |
| } | ||
|
|
||
| func (h *Handler) GetAllStudents(ctx *gin.Context) { | ||
|
|
||
| noCache := util.GetNoCache(ctx) | ||
|
|
||
| students, err := controller.GetAllStudents(h.MongikClient, noCache) | ||
| search := ctx.Query("search") | ||
|
|
||
| currentPageStr := ctx.DefaultQuery("page", "0") | ||
| studentsPerPageStr := ctx.DefaultQuery("limit", "0") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change this to 50
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better if the value 50 is handled in the frontend, if some issue is there from the frontend in sending the params, then it defaults to 0 and returns all the students. |
||
|
|
||
| currentPage, err := strconv.Atoi(currentPageStr) | ||
|
|
||
| studentsPerPage, err := strconv.Atoi(studentsPerPageStr) | ||
|
|
||
| students, totalStudents, err := controller.GetAllStudents(h.MongikClient, noCache, currentPage, studentsPerPage, search) | ||
|
|
||
| if err != nil { | ||
| ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ | ||
| "data": nil, | ||
| "error": err, | ||
| }) | ||
| return | ||
| } | ||
| ctx.JSON(http.StatusOK, | ||
| gin.H{ | ||
| "data": students, | ||
| "error": nil, | ||
| }) | ||
|
|
||
| ctx.JSON(http.StatusOK, gin.H{ | ||
| "data": students, | ||
| "totalStudents": totalStudents, | ||
| "error": nil, | ||
| }) | ||
| } | ||
|
|
||
| func (h *Handler) GetStudentById(ctx *gin.Context) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.