44 "context"
55 "database/sql"
66 "errors"
7- "log"
87 "net/http"
98 "strconv"
109
@@ -735,60 +734,17 @@ func GetAllIdeas(c echo.Context) error {
735734func GetIdeasByTrack (c echo.Context ) error {
736735 ctx := c .Request ().Context ()
737736
738- TrackParam := c .QueryParam ("track" )
739- TitleParam := c .QueryParam ("title" )
740-
741- log .Println (TrackParam )
742-
743- if TrackParam == "" {
744- TrackParam = "7"
745- }
746-
747- log .Println (TrackParam )
748-
749- TrackParamInt , err := strconv .Atoi (TrackParam )
750- if err != nil {
751- return c .JSON (http .StatusBadRequest , & models.Response {
752- Status : "fail" ,
753- Message : err .Error (),
754- })
755- }
756-
757- if TrackParamInt < 1 || TrackParamInt > 6 {
758- TrackParamInt = 7
759- }
760-
761- payload := struct {
762- Track int `json:"track"`
763- Title string `json:"title"`
764- }{
765- Track : TrackParamInt ,
766- Title : TitleParam ,
767- }
768-
737+ search := c .QueryParam ("search" )
769738 limitParam := c .QueryParam ("limit" )
770739 cursor := c .QueryParam ("cursor" )
771740
772- if err := c .Bind (& payload ); err != nil {
773- return c .JSON (http .StatusBadRequest , & models.Response {
774- Status : "success" ,
775- Message : err .Error (),
776- })
777- }
778-
779741 limit , err := strconv .Atoi (limitParam )
780- if err != nil {
781- return c .JSON (http .StatusInternalServerError , & models.Response {
782- Status : "fail" ,
783- Message : err .Error (),
784- })
742+ if err != nil || limit <= 0 {
743+ limit = 10
785744 }
786745
787746 var cursorUUID uuid.UUID
788-
789- if cursor == "" {
790- cursorUUID = uuid .Nil
791- } else {
747+ if cursor != "" {
792748 cursorUUID , err = uuid .Parse (cursor )
793749 if err != nil {
794750 return c .JSON (http .StatusBadRequest , map [string ]string {
@@ -797,144 +753,31 @@ func GetIdeasByTrack(c echo.Context) error {
797753 }
798754 }
799755
800- var idea []db.Idea
801-
802- tracks := map [int ]string {
803- 1 : "AI&ML" ,
804- 2 : "Finance and Fintech" ,
805- 3 : "Healthcare and Education" ,
806- 4 : "Digital Security" ,
807- 5 : "Environment and Sustainability" ,
808- 6 : "Open Innovation" ,
809- 7 : "General" ,
810- }
811- log .Println ("--------------" )
812- log .Println (payload .Title )
813- log .Println ("--------------" )
814-
815- switch payload .Track {
816- case 1 :
817- trackname := tracks [1 ]
818- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
819- Column1 : & payload .Title ,
820- Column2 : & trackname ,
821- ID : cursorUUID ,
822- Limit : int32 (limit ),
823- })
824- if err != nil {
825- return c .JSON (http .StatusInternalServerError , & models.Response {
826- Status : "fail" ,
827- Message : err .Error (),
828- })
829- }
830- case 2 :
831- trackname := tracks [2 ]
832- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
833- Column1 : & payload .Title ,
834- Column2 : & trackname ,
835- ID : cursorUUID ,
836- Limit : int32 (limit ),
837- })
838- if err != nil {
839- return c .JSON (http .StatusInternalServerError , & models.Response {
840- Status : "fail" ,
841- Message : err .Error (),
842- })
843- }
844- case 3 :
845- trackname := tracks [3 ]
846- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
847- Column1 : & payload .Title ,
848- Column2 : & trackname ,
849- ID : cursorUUID ,
850- Limit : int32 (limit ),
851- })
852- if err != nil {
853- return c .JSON (http .StatusInternalServerError , & models.Response {
854- Status : "fail" ,
855- Message : err .Error (),
856- })
857- }
858- case 4 :
859- trackname := tracks [4 ]
860- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
861- Column1 : & payload .Title ,
862- Column2 : & trackname ,
863- ID : cursorUUID ,
864- Limit : int32 (limit ),
865- })
866- if err != nil {
867- return c .JSON (http .StatusInternalServerError , & models.Response {
868- Status : "fail" ,
869- Message : err .Error (),
870- })
871- }
872- case 5 :
873- trackname := tracks [5 ]
874- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
875- Column1 : & payload .Title ,
876- Column2 : & trackname ,
877- ID : cursorUUID ,
878- Limit : int32 (limit ),
879- })
880- if err != nil {
881- return c .JSON (http .StatusInternalServerError , & models.Response {
882- Status : "fail" ,
883- Message : err .Error (),
884- })
885- }
886- case 6 :
887- trackname := tracks [6 ]
888- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
889- Column1 : & payload .Title ,
890- Column2 : & trackname ,
891- ID : cursorUUID ,
892- Limit : int32 (limit ),
893- })
894- if err != nil {
895- return c .JSON (http .StatusInternalServerError , & models.Response {
896- Status : "fail" ,
897- Message : err .Error (),
898- })
899- }
900- case 7 :
901- trackname := tracks [7 ]
902- idea , err = utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
903- Column1 : & payload .Title ,
904- Column2 : & trackname ,
905- ID : cursorUUID ,
906- Limit : int32 (limit ),
907- })
908- log .Println ("-----------" )
909- log .Println (cursorUUID )
910- log .Println (payload .Title )
911- log .Println ("-----------" )
912- if err != nil {
913- return c .JSON (http .StatusInternalServerError , & models.Response {
914- Status : "fail" ,
915- Message : err .Error (),
916- })
917- }
918- default :
919- return c .JSON (http .StatusBadRequest , & models.Response {
756+ ideas , err := utils .Queries .GetIdeasByTrack (ctx , db.GetIdeasByTrackParams {
757+ Column1 : & search ,
758+ Column2 : cursorUUID ,
759+ Column3 : int32 (limit ),
760+ })
761+ if err != nil {
762+ return c .JSON (http .StatusInternalServerError , & models.Response {
920763 Status : "fail" ,
921- Message : "" ,
764+ Message : err . Error () ,
922765 })
923766 }
924767
925768 var nextCursor uuid.NullUUID
926-
927- for _ , ide := range idea {
928- nextCursor = uuid.NullUUID {UUID : ide .TeamID }
769+ if len (ideas ) > 0 {
770+ nextCursor = uuid.NullUUID {UUID : ideas [len (ideas )- 1 ].ID , Valid : true }
771+ } else {
772+ nextCursor = uuid.NullUUID {Valid : false }
929773 }
930774
931775 return c .JSON (http .StatusOK , & models.Response {
932776 Status : "success" ,
933777 Message : "ideas fetched successfully" ,
934778 Data : map [string ]interface {}{
935- "ideas" : idea ,
779+ "ideas" : ideas ,
936780 "next_cursor" : nextCursor ,
937781 },
938782 })
939-
940783}
0 commit comments