Skip to content

Commit fdf8ae1

Browse files
authored
Merge branch 'master' into master
2 parents 2c842dc + 9cef1ec commit fdf8ae1

File tree

14 files changed

+329
-115
lines changed

14 files changed

+329
-115
lines changed

docker-compose.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ services:
33

44
api:
55
build: .
6+
ports:
7+
- "8080:8080"
68
volumes:
79
- .:/app
810
env_file:
911
- .env
1012
restart: on-failure
11-
12-
nginx:
13-
image: nginx:latest
14-
ports:
15-
- "80:80" # Replace 8080 with the desired port for your application
16-
volumes:
17-
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf # Mount your Nginx configuration file
18-
depends_on:
19-
- api # Nginx depends on the API service being available
20-

internal/controllers/auth_controller.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"strconv"
10+
"strings"
1011
"time"
1112

1213
"github.com/golang-jwt/jwt/v5"
@@ -37,6 +38,8 @@ func Login(ctx echo.Context) error {
3738
})
3839
}
3940

41+
payload.Email = strings.ToLower(payload.Email)
42+
4043
user, err := services.FindUserByEmail(payload.Email)
4144
if err != nil {
4245
if errors.Is(err, sql.ErrNoRows) {
@@ -71,13 +74,6 @@ func Login(ctx echo.Context) error {
7174
})
7275
}
7376

74-
if !user.IsProfileComplete {
75-
return ctx.JSON(http.StatusLocked, map[string]interface{}{
76-
"message": "profile not completed",
77-
"status": "fail",
78-
})
79-
}
80-
8177
tokenVersionStr, err := database.RedisClient.Get(
8278
fmt.Sprintf("token_version:%s", user.User.Email))
8379
if err != nil && err != redis.Nil {

internal/controllers/idea_controller.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
"errors"
66
"net/http"
7+
"strings"
78

89
"github.com/CodeChefVIT/devsoc-backend-24/internal/models"
910
services "github.com/CodeChefVIT/devsoc-backend-24/internal/services/idea"
@@ -55,6 +56,13 @@ func CreateIdea(ctx echo.Context) error {
5556
})
5657
}
5758

59+
req.Title = strings.TrimSpace(req.Title)
60+
req.Description = strings.TrimSpace(req.Description)
61+
req.Track = strings.TrimSpace(req.Track)
62+
req.Figma = strings.TrimSpace(req.Figma)
63+
req.Github = strings.TrimSpace(req.Github)
64+
req.Others = strings.TrimSpace(req.Others)
65+
5866
if err := ctx.Validate(&req); err != nil {
5967
return ctx.JSON(http.StatusBadRequest, map[string]string{
6068
"message": err.Error(),
@@ -64,8 +72,15 @@ func CreateIdea(ctx echo.Context) error {
6472

6573
user := ctx.Get("user").(*models.User)
6674

75+
if user.TeamID == uuid.Nil {
76+
return ctx.JSON(http.StatusForbidden, map[string]string{
77+
"message": "user is not in a team",
78+
"status": "fail",
79+
})
80+
}
81+
6782
if !user.IsLeader {
68-
return ctx.JSON(http.StatusUnauthorized, map[string]string{
83+
return ctx.JSON(http.StatusForbidden, map[string]string{
6984
"message": "user is not a leader",
7085
"status": "fail",
7186
})
@@ -103,6 +118,13 @@ func UpdateIdea(ctx echo.Context) error {
103118
})
104119
}
105120

121+
req.Title = strings.TrimSpace(req.Title)
122+
req.Description = strings.TrimSpace(req.Description)
123+
req.Track = strings.TrimSpace(req.Track)
124+
req.Github = strings.TrimSpace(req.Github)
125+
req.Figma = strings.TrimSpace(req.Figma)
126+
req.Others = strings.TrimSpace(req.Others)
127+
106128
if err := ctx.Validate(&req); err != nil {
107129
return ctx.JSON(http.StatusBadRequest, map[string]string{
108130
"message": err.Error(),

internal/controllers/project_controller.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
"errors"
66
"net/http"
7+
"strings"
78

89
"github.com/google/uuid"
910
"github.com/jackc/pgx/v5/pgconn"
@@ -54,6 +55,13 @@ func CreateProject(ctx echo.Context) error {
5455
})
5556
}
5657

58+
req.Name = strings.TrimSpace(req.Name)
59+
req.Description = strings.TrimSpace(req.Description)
60+
req.Track = strings.TrimSpace(req.Track)
61+
req.GithubLink = strings.TrimSpace(req.GithubLink)
62+
req.FigmaLink = strings.TrimSpace(req.FigmaLink)
63+
req.Others = strings.TrimSpace(req.Others)
64+
5765
if err := ctx.Validate(&req); err != nil {
5866
return ctx.JSON(http.StatusBadRequest, map[string]string{
5967
"message": err.Error(),
@@ -63,16 +71,16 @@ func CreateProject(ctx echo.Context) error {
6371

6472
user := ctx.Get("user").(*models.User)
6573

66-
if !user.IsLeader {
67-
return ctx.JSON(http.StatusUnauthorized, map[string]string{
68-
"message": "user is not a leader",
74+
if user.TeamID == uuid.Nil {
75+
return ctx.JSON(http.StatusForbidden, map[string]string{
76+
"message": "user is not in a team",
6977
"status": "fail",
7078
})
7179
}
7280

73-
if user.TeamID == uuid.Nil {
81+
if !user.IsLeader {
7482
return ctx.JSON(http.StatusForbidden, map[string]string{
75-
"message": "The user is not in a team",
83+
"message": "user is not a leader",
7684
"status": "fail",
7785
})
7886
}
@@ -110,6 +118,13 @@ func UpdateProject(ctx echo.Context) error {
110118
})
111119
}
112120

121+
req.Name = strings.TrimSpace(req.Name)
122+
req.Description = strings.TrimSpace(req.Description)
123+
req.Track = strings.TrimSpace(req.Track)
124+
req.GithubLink = strings.TrimSpace(req.GithubLink)
125+
req.FigmaLink = strings.TrimSpace(req.FigmaLink)
126+
req.Others = strings.TrimSpace(req.Others)
127+
113128
if err := ctx.Validate(&req); err != nil {
114129
return ctx.JSON(http.StatusBadRequest, map[string]string{
115130
"message": err.Error(),

internal/controllers/team_controller.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
"errors"
66
"net/http"
7+
"strings"
78

89
"github.com/google/uuid"
910
"github.com/jackc/pgx/v5/pgconn"
@@ -24,6 +25,8 @@ func CreateTeam(ctx echo.Context) error {
2425
})
2526
}
2627

28+
payload.Name = strings.TrimSpace(payload.Name)
29+
2730
if err := ctx.Validate(&payload); err != nil {
2831
return ctx.JSON(http.StatusBadRequest, map[string]string{
2932
"message": err.Error(),
@@ -74,6 +77,81 @@ func CreateTeam(ctx echo.Context) error {
7477
})
7578
}
7679

80+
func UpdateTeamName(ctx echo.Context) error {
81+
var payload models.CreateTeamRequest
82+
83+
if err := ctx.Bind(&payload); err != nil {
84+
return ctx.JSON(http.StatusBadRequest, map[string]string{
85+
"message": err.Error(),
86+
"status": "fail",
87+
})
88+
}
89+
90+
payload.Name = strings.TrimSpace(payload.Name)
91+
92+
if err := ctx.Validate(&payload); err != nil {
93+
return ctx.JSON(http.StatusBadRequest, map[string]string{
94+
"message": err.Error(),
95+
"status": "fail",
96+
})
97+
}
98+
99+
user := ctx.Get("user").(*models.User)
100+
101+
if !user.IsLeader {
102+
return ctx.JSON(http.StatusForbidden, map[string]string{
103+
"status": "fail",
104+
"message": "user is not leader",
105+
})
106+
}
107+
108+
if !user.IsLeader {
109+
return ctx.JSON(http.StatusForbidden, map[string]string{
110+
"status": "fail",
111+
"message": "user is not leader",
112+
})
113+
}
114+
115+
if user.TeamID == uuid.Nil {
116+
return ctx.JSON(http.StatusNotFound, map[string]string{
117+
"message": "user not in a team",
118+
"status": "fail",
119+
})
120+
}
121+
122+
/*team, err := services.FindTeamByTeamID(payload.ID)
123+
if err != nil {
124+
if errors.Is(err, sql.ErrNoRows) {
125+
return ctx.JSON(http.StatusNotFound, map[string]string{
126+
"message": "user not found",
127+
"status": "fail",
128+
})
129+
}
130+
}*/
131+
132+
err := services.UpdateTeamName(payload.Name, user.TeamID)
133+
if err != nil {
134+
var pgerr *pgconn.PgError
135+
if errors.As(err, &pgerr) {
136+
if pgerr.Code == "23505" {
137+
return ctx.JSON(http.StatusConflict, map[string]string{
138+
"message": "team name already exists",
139+
"status": "failed to update team",
140+
})
141+
}
142+
}
143+
return ctx.JSON(http.StatusInternalServerError, map[string]string{
144+
"message": err.Error(),
145+
"status": "error",
146+
})
147+
}
148+
149+
return ctx.JSON(http.StatusOK, map[string]interface{}{
150+
"message": "team updated successfully",
151+
"status": "success",
152+
})
153+
}
154+
77155
func GetTeamDetails(ctx echo.Context) error {
78156
user := ctx.Get("user").(*models.User)
79157

internal/controllers/user_controller.go

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func CreateUser(ctx echo.Context) error {
3939
})
4040
}
4141

42+
payload.Email = strings.ToLower(payload.Email)
43+
4244
_, err := services.FindUserByEmail(payload.Email)
4345
if err != nil && !errors.Is(err, sql.ErrNoRows) {
4446
return ctx.JSON(http.StatusInternalServerError, map[string]string{
@@ -259,10 +261,10 @@ func CompleteProfile(ctx echo.Context) error {
259261
})
260262
}
261263

262-
// err = services.WriteUserToGoogleSheet(*user)
263-
// if err != nil {
264-
// slog.Error(err.Error())
265-
// }
264+
err = services.WriteUserToGoogleSheet(user.User)
265+
if err != nil {
266+
slog.Error(err.Error())
267+
}
266268

267269
return ctx.JSON(http.StatusOK, map[string]string{
268270
"message": "user profile updated",
@@ -322,6 +324,19 @@ func UpdateUser(ctx echo.Context) error {
322324
})
323325
}
324326

327+
payload.FirstName = strings.TrimSpace(payload.FirstName)
328+
payload.LastName = strings.TrimSpace(payload.LastName)
329+
payload.PhoneNumber = strings.TrimSpace(payload.PhoneNumber)
330+
payload.Gender = strings.TrimSpace(payload.Gender)
331+
payload.VitEmail = strings.TrimSpace(payload.VitEmail)
332+
payload.HostelBlock = strings.TrimSpace(payload.HostelBlock)
333+
payload.College = strings.TrimSpace(payload.College)
334+
payload.City = strings.TrimSpace(payload.City)
335+
payload.State = strings.TrimSpace(payload.State)
336+
payload.Country = strings.TrimSpace(payload.Country)
337+
payload.RegNo = strings.TrimSpace(payload.RegNo)
338+
payload.Room = strings.TrimSpace(payload.Room)
339+
325340
if payload.FirstName != "" {
326341
user.FirstName = payload.FirstName
327342
}
@@ -334,27 +349,15 @@ func UpdateUser(ctx echo.Context) error {
334349
if payload.Gender != "" {
335350
user.Gender = payload.Gender
336351
}
337-
if payload.VitEmail != "" {
338-
user.VITDetails.Email = payload.VitEmail
339-
}
340352
if payload.HostelBlock != "" {
341353
user.Block = payload.HostelBlock
342354
}
343-
if payload.College != "" {
344-
user.College = payload.College
345-
}
346-
if payload.City != "" {
347-
user.City = payload.City
348-
}
349-
if payload.State != "" {
350-
user.State = payload.State
351-
}
352-
if payload.Country != "" {
353-
user.Country = payload.Country
354-
}
355355
if payload.RegNo != "" {
356356
user.RegNo = payload.RegNo
357357
}
358+
if payload.Room != "" {
359+
user.Room = payload.Room
360+
}
358361

359362
if err := services.UpdateUser(&user.User); err != nil {
360363
var pgerr *pgconn.PgError
@@ -455,6 +458,8 @@ func VerifyUser(ctx echo.Context) error {
455458
})
456459
}
457460

461+
database.RedisClient.Delete("verification:" + user.User.Email)
462+
458463
return ctx.JSON(http.StatusOK, map[string]string{
459464
"message": "User verified",
460465
"status": "success",
@@ -579,7 +584,7 @@ func RequestResetPassword(ctx echo.Context) error {
579584
})
580585
}
581586

582-
if err := database.RedisClient.Set("resettries"+payload.Email, fmt.Sprint(1), time.Minute*5); err != nil {
587+
if err := database.RedisClient.Set("resettries:"+payload.Email, fmt.Sprint(1), time.Minute*5); err != nil {
583588
return ctx.JSON(http.StatusInternalServerError, map[string]string{
584589
"message": err.Error(),
585590
"status": "error",
@@ -636,7 +641,7 @@ func ResetPassword(ctx echo.Context) error {
636641
})
637642
}
638643

639-
triesString, err := database.RedisClient.Get("resettries" + payload.Email)
644+
triesString, err := database.RedisClient.Get("resettries:" + payload.Email)
640645
if err != nil {
641646
if err == redis.Nil {
642647
return ctx.JSON(http.StatusForbidden, map[string]string{
@@ -653,7 +658,7 @@ func ResetPassword(ctx echo.Context) error {
653658
tries, _ := strconv.Atoi(triesString)
654659

655660
if tries >= 10 {
656-
database.RedisClient.Delete("resetpass" + payload.Email)
661+
database.RedisClient.Delete("resetpass:" + payload.Email)
657662
return ctx.JSON(http.StatusGone, map[string]string{
658663
"message": "otp expired",
659664
"status": "fail",
@@ -675,7 +680,7 @@ func ResetPassword(ctx echo.Context) error {
675680
}
676681

677682
if payload.OTP != otp {
678-
if err := database.RedisClient.Set("resettries"+payload.Email, fmt.Sprint(tries+1), time.Minute*5); err != nil {
683+
if err := database.RedisClient.Set("resettries:"+payload.Email, fmt.Sprint(tries+1), time.Minute*5); err != nil {
679684
return ctx.JSON(http.StatusInternalServerError, map[string]string{
680685
"message": err.Error(),
681686
"status": "error",
@@ -695,7 +700,7 @@ func ResetPassword(ctx echo.Context) error {
695700
})
696701
}
697702

698-
err = services.ResetPassword(payload.Email, string(hashed))
703+
err = services.ResetPassword(string(hashed), payload.Email)
699704
if err != nil {
700705
if errors.Is(err, sql.ErrNoRows) {
701706
return ctx.JSON(http.StatusNotFound, map[string]string{
@@ -709,6 +714,8 @@ func ResetPassword(ctx echo.Context) error {
709714
})
710715
}
711716

717+
database.RedisClient.Delete("resetpass:" + payload.Email)
718+
712719
return ctx.JSON(http.StatusOK, map[string]string{
713720
"status": "success",
714721
"message": "password reset successfully",

0 commit comments

Comments
 (0)