@@ -524,65 +524,63 @@ func DeletePanelMember(c echo.Context) error {
524524 })
525525}
526526
527- func GetAllUsers (ec echo.Context ) error {
528- ctx := ec .Request ().Context ()
529- limitParam := ec .QueryParam ("limit" )
530- cursor := ec .QueryParam ("cursor" )
531- name := ec .QueryParam ("name" )
532- gender := ec .QueryParam ("gender" )
533-
534- limit := 20
535- if limitParam != "" {
536- lt , err := strconv .Atoi (limitParam )
537- if err != nil || lt <= 0 {
538- return ec .JSON (http .StatusBadRequest , & models.Response {
539- Success : false ,
540- Message : "limit must be a valid positive integer" ,
541- })
542- }
543- limit = lt
527+ func GetAllUsers (c echo.Context ) error {
528+ ctx := c .Request ().Context ()
529+ limitParam := c .QueryParam ("limit" )
530+ cursor := c .QueryParam ("cursor" )
531+ name := c .QueryParam ("name" )
532+ gender := c .QueryParam ("gender" )
533+
534+ limit , err := strconv .Atoi (limitParam )
535+ if err != nil {
536+ return c .JSON (http .StatusInternalServerError , & models.Response {
537+ Success : false ,
538+ Message : "Invalid limit parameter" ,
539+ Data : map [string ]string {"error" : err .Error ()},
540+ })
544541 }
545542
546- var cursorUUID pgtype .UUID
543+ var cursorUUID uuid .UUID
547544 if cursor == "" {
548- cursorUUID = pgtype. UUID { Valid : false }
545+ cursorUUID = uuid . Nil
549546 } else {
550- if err := cursorUUID . Scan (cursor ); err != nil {
551- return ec . JSON ( http . StatusBadRequest , & models. Response {
552- Success : false ,
553- Message : "Invalid UUID for cursor" ,
547+ cursorUUID , err = uuid . Parse (cursor )
548+ if err != nil {
549+ return c . JSON ( http . StatusBadRequest , map [ string ] string {
550+ "error" : "Invalid UUID for cursor" ,
554551 })
555552 }
556553 }
557554
558555 users , err := db .Queries .GetAllUsers (ctx , sqlc.GetAllUsersParams {
559- Column1 : name ,
560- Column2 : cursorUUID ,
561- Limit : int32 ( limit + 1 ) ,
556+ Limit : int32 ( limit ) ,
557+ ID : pgtype. UUID { Bytes : cursorUUID , Valid : true } ,
558+ Column1 : & name ,
562559 Column4 : gender ,
563560 })
564561 if err != nil {
565- return ec .JSON (http .StatusInternalServerError , & models.Response {
562+ return c .JSON (http .StatusInternalServerError , & models.Response {
566563 Success : false ,
567- Message : err .Error (),
564+ Message : "Failed to fetch users" ,
565+ Data : map [string ]string {"error" : err .Error ()},
568566 })
569567 }
570568
571- var nextCursorStr string
572- if len ( users ) > int ( limit ) {
573- nextCursor := users [ len ( users ) - 1 ]. ID
574- nextCursorStr = nextCursor . String ()
575- users = users [: limit ]
576- } else {
577- nextCursorStr = ""
569+ var nextCursor uuid. NullUUID
570+
571+ for _ , user := range users {
572+ nextCursor = uuid. NullUUID {
573+ UUID : uuid . UUID ( user . ID . Bytes ),
574+ Valid : true ,
575+ }
578576 }
579577
580- return ec .JSON (http .StatusOK , & models.Response {
578+ return c .JSON (http .StatusOK , & models.Response {
581579 Success : true ,
582580 Message : "Users fetched successfully" ,
583581 Data : map [string ]interface {}{
584582 "users" : users ,
585- "next_cursor" : nextCursorStr ,
583+ "next_cursor" : nextCursor . UUID . String () ,
586584 },
587585 })
588586}
@@ -1002,6 +1000,17 @@ func IncrementTeamRound(c echo.Context) error {
10021000 Data : map [string ]string {"error" : err .Error ()},
10031001 })
10041002 }
1003+
1004+ if err := db .Queries .SetIsSelectedByTeamID (ctx , sqlc.SetIsSelectedByTeamIDParams {
1005+ TeamID : teamUUID ,
1006+ IsSelected : true ,
1007+ }); err != nil {
1008+ return c .JSON (http .StatusInternalServerError , & models.Response {
1009+ Success : false ,
1010+ Message : "failed to update team selection status" ,
1011+ Data : map [string ]string {"team_id" : teamUUID .String (), "error" : err .Error ()},
1012+ })
1013+ }
10051014 }
10061015
10071016 return c .JSON (http .StatusOK , & models.Response {
0 commit comments