Skip to content

Commit fa95fef

Browse files
Merge pull request #95 from ABHINAVGARG05/master
idea route fix
2 parents ae028d0 + 2b62b96 commit fa95fef

File tree

4 files changed

+67
-33
lines changed

4 files changed

+67
-33
lines changed

database/queries/ideas.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ LIMIT $2;
4141

4242
-- name: GetIdeasByTrack :many
4343
SELECT * FROM ideas
44-
WHERE (track = $1 OR $1 = '') AND (title = $2 OR $2 = '')
44+
WHERE (track ILIKE '%' || $1 || '%' OR $1 = '') AND (title ILIKE '%' || $2 || '%' OR $2 = '')
4545
AND id > $3
4646
ORDER BY id
4747
LIMIT $4;

pkg/controller/admin.go

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ func GetIdeasByTrack(c echo.Context) error {
744744
Message: err.Error(),
745745
})
746746
}
747+
if TrackParamInt < 1 || TrackParamInt > 6 {
748+
TrackParamInt = 7
749+
}
750+
747751
payload := struct {
748752
Track int `json:"track"`
749753
Title string `json:"title"`
@@ -783,13 +787,24 @@ func GetIdeasByTrack(c echo.Context) error {
783787

784788
var idea []db.Idea
785789

790+
tracks := map[int]string{
791+
1: "AI&ML",
792+
2: "Finance and Fintech",
793+
3: "Healthcare and Education",
794+
4: "Digital Security",
795+
5: "Environment and Sustainability",
796+
6: "Open Innovation",
797+
7: " ",
798+
}
799+
786800
switch payload.Track {
787801
case 1:
802+
trackname := tracks[0]
788803
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
789-
Title: payload.Title,
790-
Track: "AI & ML",
791-
ID: cursorUUID,
792-
Limit: int32(limit),
804+
Column1: &payload.Title,
805+
Column2: &trackname,
806+
ID: cursorUUID,
807+
Limit: int32(limit),
793808
})
794809
if err != nil {
795810
return c.JSON(http.StatusInternalServerError, &models.Response{
@@ -798,11 +813,12 @@ func GetIdeasByTrack(c echo.Context) error {
798813
})
799814
}
800815
case 2:
816+
trackname := tracks[1]
801817
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
802-
Title: payload.Title,
803-
Track: "Finance and Fintech",
804-
ID: cursorUUID,
805-
Limit: int32(limit),
818+
Column1: &payload.Title,
819+
Column2: &trackname,
820+
ID: cursorUUID,
821+
Limit: int32(limit),
806822
})
807823
if err != nil {
808824
return c.JSON(http.StatusInternalServerError, &models.Response{
@@ -811,11 +827,12 @@ func GetIdeasByTrack(c echo.Context) error {
811827
})
812828
}
813829
case 3:
830+
trackname := tracks[2]
814831
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
815-
Title: payload.Title,
816-
Track: "Healthcare and Education",
817-
ID: cursorUUID,
818-
Limit: int32(limit),
832+
Column1: &payload.Title,
833+
Column2: &trackname,
834+
ID: cursorUUID,
835+
Limit: int32(limit),
819836
})
820837
if err != nil {
821838
return c.JSON(http.StatusInternalServerError, &models.Response{
@@ -824,11 +841,12 @@ func GetIdeasByTrack(c echo.Context) error {
824841
})
825842
}
826843
case 4:
844+
trackname := tracks[3]
827845
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
828-
Title: payload.Title,
829-
Track: "Digital Security",
830-
ID: cursorUUID,
831-
Limit: int32(limit),
846+
Column1: &payload.Title,
847+
Column2: &trackname,
848+
ID: cursorUUID,
849+
Limit: int32(limit),
832850
})
833851
if err != nil {
834852
return c.JSON(http.StatusInternalServerError, &models.Response{
@@ -837,11 +855,12 @@ func GetIdeasByTrack(c echo.Context) error {
837855
})
838856
}
839857
case 5:
858+
trackname := tracks[4]
840859
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
841-
Title: payload.Title,
842-
Track: "Environment and Sustainability",
843-
ID: cursorUUID,
844-
Limit: int32(limit),
860+
Column1: &payload.Title,
861+
Column2: &trackname,
862+
ID: cursorUUID,
863+
Limit: int32(limit),
845864
})
846865
if err != nil {
847866
return c.JSON(http.StatusInternalServerError, &models.Response{
@@ -850,11 +869,26 @@ func GetIdeasByTrack(c echo.Context) error {
850869
})
851870
}
852871
case 6:
872+
trackname := tracks[5]
873+
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
874+
Column1: &payload.Title,
875+
Column2: &trackname,
876+
ID: cursorUUID,
877+
Limit: int32(limit),
878+
})
879+
if err != nil {
880+
return c.JSON(http.StatusInternalServerError, &models.Response{
881+
Status: "fail",
882+
Message: err.Error(),
883+
})
884+
}
885+
case 7:
886+
trackname := tracks[7]
853887
idea, err = utils.Queries.GetIdeasByTrack(ctx, db.GetIdeasByTrackParams{
854-
Title: payload.Title,
855-
Track: "Open Innovation",
856-
ID: cursorUUID,
857-
Limit: int32(limit),
888+
Column1: &payload.Title,
889+
Column2: &trackname,
890+
ID: cursorUUID,
891+
Limit: int32(limit),
858892
})
859893
if err != nil {
860894
return c.JSON(http.StatusInternalServerError, &models.Response{

pkg/db/ideas.sql.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/router/admin_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ func AdminRoutes(incomingRoutes *echo.Group) {
3535
admin.PUT("/team/rounds", controller.UpdateTeamRounds)
3636

3737
admin.GET("/ideas", controller.GetAllIdeas)
38-
admin.GET("/ideas/filter/:track/:title", controller.GetIdeasByTrack)
38+
admin.GET("/ideas/filter", controller.GetIdeasByTrack)
3939
}

0 commit comments

Comments
 (0)