Skip to content

Commit

Permalink
Merge branch 'CodeChefVIT:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenomorph07 committed Mar 16, 2024
2 parents 0cc274f + 9242fa4 commit b652882
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions internal/controllers/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/golang-jwt/jwt/v5"
Expand Down Expand Up @@ -37,6 +38,8 @@ func Login(ctx echo.Context) error {
})
}

payload.Email = strings.ToLower(payload.Email)

user, err := services.FindUserByEmail(payload.Email)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down
22 changes: 19 additions & 3 deletions internal/controllers/team_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,34 @@ func UpdateTeamName(ctx echo.Context) error {
})
}

team, err := services.FindTeamByTeamID(payload.ID)
if user.TeamID == uuid.Nil {
return ctx.JSON(http.StatusNotFound, map[string]string{
"message": "user not in a team",
"status": "fail",
})
}

/*team, err := services.FindTeamByTeamID(payload.ID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return ctx.JSON(http.StatusNotFound, map[string]string{
"message": "user not found",
"status": "fail",
})
}
}
}*/

err = services.UpdateTeamName(payload.Name, team.ID)
err := services.UpdateTeamName(payload.Name, user.TeamID)
if err != nil {
var pgerr *pgconn.PgError
if errors.As(err, &pgerr) {
if pgerr.Code == "23505" {
return ctx.JSON(http.StatusConflict, map[string]string{
"message": "team name already exists",
"status": "failed to update team",
})
}
}
return ctx.JSON(http.StatusInternalServerError, map[string]string{
"message": err.Error(),
"status": "error",
Expand Down
2 changes: 2 additions & 0 deletions internal/controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func CreateUser(ctx echo.Context) error {
})
}

payload.Email = strings.ToLower(payload.Email)

_, err := services.FindUserByEmail(payload.Email)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return ctx.JSON(http.StatusInternalServerError, map[string]string{
Expand Down
3 changes: 1 addition & 2 deletions internal/models/team_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type Team struct {
}

type CreateTeamRequest struct {
ID uuid.UUID `json:"id" validate:"required,uuid"`
Name string `json:"name" validate:"required,min=1,max=50"`
Name string `json:"name" validate:"required,min=1,max=50"`
}

type JoinTeamRequest struct {
Expand Down
4 changes: 2 additions & 2 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ http {
location / {

if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://for-your-eyes-only.codechefvit.com';
add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
Expand All @@ -46,7 +46,7 @@ http {
return 204;
}

add_header 'Access-Control-Allow-Origin' 'https://for-your-eyes-only.codechefvit.com' always;
add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
Expand Down

0 comments on commit b652882

Please sign in to comment.