Skip to content

Commit

Permalink
Merge pull request #93 from ABHINAVGARG05/master
Browse files Browse the repository at this point in the history
modified route get idea
  • Loading branch information
ABHINAVGARG05 authored Feb 3, 2025
2 parents 91408a5 + 307cb3e commit ad595ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
6 changes: 3 additions & 3 deletions database/queries/ideas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LIMIT $2;

-- name: GetIdeasByTrack :many
SELECT * FROM ideas
WHERE track = $1
AND id > $2
WHERE (track = $1 OR $1 = '') AND (title = $2 OR $2 = '')
AND id > $3
ORDER BY id
LIMIT $3;
LIMIT $4;
39 changes: 25 additions & 14 deletions pkg/controller/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,18 @@ func GetAllIdeas(c echo.Context) error {

func GetIdeasByTrack(c echo.Context) error {
ctx := c.Request().Context()
num := c.Param("track")
var payload struct {
Track int `json:"track"`
Title string `json:"title"`
}

limitParam := c.QueryParam("limit")
cursor := c.QueryParam("cursor")
trackNum, err := strconv.Atoi(num)
if err != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Status: "fail",
Message: "couldn't convert string to int",

if err := c.Bind(&payload); err != nil {
return c.JSON(http.StatusBadRequest, &models.Response{
Status: "success",
Message: err.Error(),
})
}

Expand All @@ -766,8 +770,10 @@ func GetIdeasByTrack(c echo.Context) error {

var idea []db.Idea

if trackNum == 1 {
switch payload.Track {
case 1:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "AI & ML",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -778,8 +784,9 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else if trackNum == 2 {
case 2:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "Finance and Fintech",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -790,8 +797,9 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else if trackNum == 3 {
case 3:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "Healthcare and Education",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -802,8 +810,9 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else if trackNum == 4 {
case 4:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "Digital Security",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -814,8 +823,9 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else if trackNum == 5 {
case 5:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "Environment and Sustainability",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -826,8 +836,9 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else if trackNum == 6 {
case 6:
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
Title: payload.Title,
Track: "Open Innovation",
ID: cursorUUID,
Limit: int32(limit),
Expand All @@ -838,10 +849,10 @@ func GetIdeasByTrack(c echo.Context) error {
Message: err.Error(),
})
}
} else {
default:
return c.JSON(http.StatusBadRequest, &models.Response{
Status: "fail",
Message: "give number from 1 to 6",
Message: "",
})
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/db/ideas.sql.go

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

0 comments on commit ad595ae

Please sign in to comment.