Skip to content
Open
2 changes: 1 addition & 1 deletion database/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ UPDATE users
SET
reg_no = $2,
updated_at = now()
WHERE email = $1;
WHERE email = $1;
3 changes: 0 additions & 3 deletions pkg/controllers/submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func CreateSubmission(c echo.Context) error {
Success: false,
Message: "Invalid request payload",
})

}

if errors := utils.ValSub(
Expand All @@ -55,7 +54,6 @@ func CreateSubmission(c echo.Context) error {
Success: false,
Message: "User or team not found",
})

}

exists, err := db.Queries.Submission(ctx, teamID)
Expand Down Expand Up @@ -181,7 +179,6 @@ func GetSubmission(c echo.Context) error {
Success: false,
Message: "Submission not found",
})

}
log.Println("Error while getting submission from db: ", err)
return c.JSON(http.StatusInternalServerError, &models.Response{
Expand Down
14 changes: 10 additions & 4 deletions pkg/controllers/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"fmt"
"net/http"
"strings"
"time"

"github.com/CodeChefVIT/devsoc-backend-26/pkg/db"
Expand Down Expand Up @@ -49,6 +50,13 @@ func CreateTeam(c echo.Context) error {
team sqlc.Team
err error
)
if len(strings.TrimSpace(req.Name)) < 5 || len(req.Name) > 12 {
return c.JSON(http.StatusBadRequest, &models.Response{
Success: false,
Message: "team name should be in between 5 to 12 characters",
})
}

ctx := c.Request().Context()
exists, err := db.Queries.NameExists(ctx, req.Name)
if err != nil {
Expand All @@ -63,7 +71,7 @@ func CreateTeam(c echo.Context) error {
Message: "team name already taken TwT",
})
}
for attempts := 0; attempts < 5; attempts++ {
for range 5 {
code, genErr := utils.GenerateTeamCode(6)
if genErr != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Expand Down Expand Up @@ -242,7 +250,6 @@ func UpdateTeam(c echo.Context) error {
ID: id,
Name: name,
})

if err != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Success: false,
Expand Down Expand Up @@ -285,7 +292,6 @@ func ToggleTeamBan(c echo.Context) error {
IsBanned: newBanStatus,
TotalScore: existing.TotalScore,
})

if err != nil {
return c.JSON(http.StatusInternalServerError, &models.Response{
Success: false,
Expand Down Expand Up @@ -331,6 +337,7 @@ func JoinTeam(c echo.Context) error {
})
}


teamKeyStr := teamKey.String()

ok, err = redis.RequestManager.SetNX(
Expand All @@ -339,7 +346,6 @@ func JoinTeam(c echo.Context) error {
teamKeyStr,
30*time.Minute,
).Result()

if err != nil {
fmt.Printf("Rediserror: %v\n", err)
return c.JSON(http.StatusInternalServerError, &models.Response{
Expand Down
20 changes: 20 additions & 0 deletions pkg/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ func CompleteProfile(c echo.Context) error {
})
}

if req.PhoneNo != "" {
existingPhone, err := db.Queries.GetUserByPhoneNo(ctx, &req.PhoneNo)
if err == nil && existingPhone.ID != user.ID {
return c.JSON(http.StatusConflict, models.Response{
Success: false,
Message: "Phone number already in use",
})
}
}

phone := req.PhoneNo
gender := req.Gender
ghub := req.GithubProfile
Expand Down Expand Up @@ -241,6 +251,16 @@ func UpdateProfile(c echo.Context) error {
})
}

if req.PhoneNo != "" {
existingPhone, err := db.Queries.GetUserByPhoneNo(ctx, &req.PhoneNo)
if err == nil && existingPhone.ID != user.ID {
return c.JSON(http.StatusConflict, models.Response{
Success: false,
Message: "Phone number already in use",
})
}
}

phone := req.PhoneNo
gender := req.Gender
ghub := req.GithubProfile
Expand Down
34 changes: 34 additions & 0 deletions pkg/db/sqlc/users.sql.go

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

15 changes: 10 additions & 5 deletions pkg/utils/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func FormatValidationErrors(err error) []string {
}

func ValSub(t, d, g, f, o string) string {
chk := func(v string) bool {
u, err := url.ParseRequestURI(v)
return err == nil && (u.Scheme == "http" || u.Scheme == "https")
}

t = strings.TrimSpace(t)
if t == "" {
return "title is required"
Expand All @@ -93,14 +98,14 @@ func ValSub(t, d, g, f, o string) string {
return "description too long"
}

chk := func(v string) bool {
u, err := url.ParseRequestURI(v)
return err == nil && (u.Scheme == "http" || u.Scheme == "https")
g = strings.TrimSpace(g)
if g == "" {
return "github link is required"
}

if strings.TrimSpace(g) != "" && !chk(g) {
if !chk(g) {
return "invalid github url"
}

if strings.TrimSpace(f) != "" && !chk(f) {
return "invalid figma url"
}
Expand Down