Skip to content

Commit

Permalink
Merge pull request #89 from CodeChefVIT/feat/filter
Browse files Browse the repository at this point in the history
Gender Filter
  • Loading branch information
Soham-Maha authored Feb 2, 2025
2 parents 8c5133c + f992974 commit 294993a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 29 deletions.
6 changes: 5 additions & 1 deletion database/queries/user.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
-- name: GetAllUsers :many
SELECT u.*,t.round_qualified
SELECT u.*, t.round_qualified
FROM users u
JOIN teams t ON t.id = u.team_id
WHERE (u.first_name LIKE '%' || $1 || '%'
OR u.reg_no LIKE '%' || $1 || '%'
OR u.email LIKE '%' || $1 || '%')
AND u.id > $2
AND ($4 = '' OR u.gender = $4)
ORDER BY u.id
LIMIT $3;

-- name: GetUsersByGender :many
SELECT * FROM users WHERE gender = $1;

-- name: GetUsersByTeamId :many
SELECT first_name, last_name, email, reg_no, phone_no FROM users WHERE team_id = $1;

Expand Down
49 changes: 23 additions & 26 deletions docs/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2855,13 +2855,13 @@ paths:

/admin/ideas:
get:
summary: Get all ideas
tags:
- Admin
summary: Get all ideas
description: Retrieves a list of all ideas.
description: Fetches all submitted ideas.
responses:
"200":
description: Successful response with ideas list.
description: Successfully fetched ideas
content:
application/json:
schema:
Expand All @@ -2880,19 +2880,19 @@ paths:
properties:
id:
type: string
example: "123e4567-e89b-12d3-a456-426614174000"
format: uuid
example: "550e8400-e29b-41d4-a716-446655440000"
title:
type: string
example: "New Startup Idea"
example: "AI-Powered Assistant"
description:
type: string
example: "A platform for AI-driven content creation"
created_at:
example: "An AI-powered virtual assistant."
track:
type: string
format: date-time
example: "2024-02-01T12:00:00Z"
example: "Artificial Intelligence"
"500":
description: Internal server error.
description: Internal server error
content:
application/json:
schema:
Expand All @@ -2903,25 +2903,25 @@ paths:
example: fail
message:
type: string
example: Internal Server Error
example: Internal server error

/ideas/{track}:
/admin/ideas/{track}:
get:
tags:
- Admin
summary: Get ideas by track
description: Retrieves a list of ideas based on the provided track number (1 to 6).
description: Fetches ideas associated with a specific track based on a numeric identifier.
parameters:
- name: track
in: path
required: true
description: Track number (1-6) to filter ideas.
schema:
type: integer
enum: [1, 2, 3, 4, 5, 6]
description: "Track number (1: Media and Entertainment, 2: Finance and Fintech, 3: Healthcare and Education, 4: Digital Security, 5: Environment and Sustainability, 6: Open Innovation)"
responses:
"200":
description: Successful response with a list of ideas.
description: Successfully fetched ideas
content:
application/json:
schema:
Expand All @@ -2940,22 +2940,19 @@ paths:
properties:
id:
type: string
example: "123e4567-e89b-12d3-a456-426614174000"
format: uuid
example: "550e8400-e29b-41d4-a716-446655440000"
title:
type: string
example: "AI-powered News Aggregator"
example: "Revolutionizing Digital Security"
description:
type: string
example: "An AI-driven platform to aggregate personalized news content."
example: "An AI-powered security solution for digital platforms."
track:
type: string
example: "Media and Entertainment"
created_at:
type: string
format: date-time
example: "2024-02-01T12:00:00Z"
example: "Digital Security"
"400":
description: Invalid track number provided.
description: Invalid track number
content:
application/json:
schema:
Expand All @@ -2968,7 +2965,7 @@ paths:
type: string
example: give number from 1 to 6
"500":
description: Internal server error.
description: Internal server error
content:
application/json:
schema:
Expand All @@ -2979,7 +2976,7 @@ paths:
example: fail
message:
type: string
example: Internal Server Error
example: Internal server error

components:
schemas:
Expand Down
29 changes: 29 additions & 0 deletions pkg/controller/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func GetAllUsers(c echo.Context) error {
limitParam := c.QueryParam("limit")
cursor := c.QueryParam("cursor")
name := c.QueryParam("name")
gender := c.QueryParam("gender")

limit, err := strconv.Atoi(limitParam)
if err != nil {
Expand All @@ -48,6 +49,7 @@ func GetAllUsers(c echo.Context) error {
Limit: int32(limit),
ID: cursorUUID,
Column1: &name,
Column4: gender,
})
if err != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Expand Down Expand Up @@ -89,6 +91,33 @@ func GetUsersByEmail(c echo.Context) error {
})
}

func GetUsersByGender(c echo.Context) error {
ctx := c.Request().Context()
gender := c.Param("gender")

if gender != "M" && gender != "F" && gender != "O" {
return c.JSON(http.StatusBadRequest, &models.Response{
Status: "fail",
Message: "Gender should be M or F",
})
}

users, err := utils.Queries.GetUsersByGender(ctx, gender)
if err != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Status: "fail",
Message: err.Error(),
})
}

return c.JSON(http.StatusOK, &models.Response{
Status: "success",
Message: "users fetched successfully",
Data: users,
})

}

func BanUser(c echo.Context) error {
var payload models.BanUserReq

Expand Down
54 changes: 52 additions & 2 deletions pkg/db/user.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/router/admin_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func AdminRoutes(incomingRoutes *echo.Group) {
admin.POST("/ban", controller.BanUser)
admin.POST("/unban", controller.UnbanUser)
admin.POST("/star", controller.CheckStarred)
admin.GET("/users/:gender", controller.GetUsersByGender)

admin.GET("/teams", controller.GetTeams)
admin.GET("/teams/:id", controller.GetTeamById)
Expand Down

0 comments on commit 294993a

Please sign in to comment.