feat: finish back-end work (untested)

This commit is contained in:
2025-11-12 12:58:21 -07:00
parent b6a08573f3
commit 8b351524b8
18 changed files with 300 additions and 27 deletions

View File

@@ -21,6 +21,7 @@ func SetUserName(pool *pgxpool.Pool) gin.HandlerFunc {
if err != nil {
// TODO: Log this error
ctx.String(http.StatusInternalServerError, err.Error())
log.Printf("SetUserName(): ERROR... Failed to acquire connection... %s", err.Error())
return
}
user_profile, _ := ctx.Get("user_profile")
@@ -109,6 +110,13 @@ func GetUserTable(pool *pgxpool.Pool) gin.HandlerFunc {
}
defer conn.Release()
var request dto.UserRequest
body_read_err := ctx.ShouldBindJSON(&request)
if body_read_err != nil {
ctx.String(http.StatusBadRequest, "GetUserTable(): ERROR... Invalid user query object")
return
}
page := ctx.Query("page")
if page == "" {
ctx.String(http.StatusBadRequest, "GetUserTable(): Missing page")
@@ -119,7 +127,7 @@ func GetUserTable(pool *pgxpool.Pool) gin.HandlerFunc {
ctx.String(http.StatusBadRequest, "GetUserTable(): Not an integer")
return
}
rows, query_err := conn.Query(context.Background(), queries.USER_GET_TABLE_DATA, page_int*utils.PAGE_SIZE, utils.PAGE_SIZE)
rows, query_err := conn.Query(context.Background(), queries.USER_GET_TABLE_DATA, page_int*utils.PAGE_SIZE, utils.PAGE_SIZE, request.Name, request.JobPosition)
if query_err != nil {
ctx.String(http.StatusInternalServerError, "GetUserTable(): Failed to query database...")
log.Printf("GetUserTable(): ERROR... %s", query_err.Error())
@@ -129,7 +137,7 @@ func GetUserTable(pool *pgxpool.Pool) gin.HandlerFunc {
var users []dto.UserResponse
for rows.Next() {
var user dto.UserResponse
scan_err := rows.Scan(&user.Id, &user.Name, &user.Job_Position, &user.Active, &user.Admin)
scan_err := rows.Scan(&user.Id, &user.Name, &user.JobPosition, &user.Active, &user.Admin)
if scan_err != nil {
ctx.String(http.StatusInternalServerError, "GetUserTable(): ERROR: Failed to scan..")
log.Printf("GetUserTable(): ERROR... %s", scan_err.Error())
@@ -158,7 +166,7 @@ func GetCurrentAuthenticatedUser(pool *pgxpool.Pool) gin.HandlerFunc {
var user dto.UserResponse
query_err := conn.QueryRow(context.Background(), queries.GET_CURRENT_USER_OBJECT, sub_id).Scan(&user.Id, &user.Name, &user.Job_Position, &user.Active, &user.Admin)
query_err := conn.QueryRow(context.Background(), queries.GET_CURRENT_USER_OBJECT, sub_id).Scan(&user.Id, &user.Name, &user.JobPosition, &user.Active, &user.Admin)
if query_err != nil {
ctx.String(http.StatusInternalServerError, "GetCurrentAuthenticatedUser(): ERROR.... Failed to query")
log.Printf("GetCurrentAuthenticatedUser(): ERROR in querying user table... %s", query_err.Error())