Skip to content

Commit 314d9bd

Browse files
Merge pull request #53 from Black-Sirius69/master
feat: feat
2 parents 3f4e326 + 7ecab3c commit 314d9bd

File tree

13 files changed

+470
-8
lines changed

13 files changed

+470
-8
lines changed

db/migrations/001_users.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ CREATE TABLE vit_details (
3232
);
3333

3434
-- +goose Down
35-
DROP TABLE vit_details;
36-
DROP TABLE users;
35+
DROP TABLE IF EXISTS vit_details;
36+
DROP TABLE IF EXISTS users;

db/migrations/002_teams.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ CREATE TABLE IF NOT EXISTS teams (
99
);
1010

1111
-- +goose Down
12-
13-
DROP TABLE teams;
12+
DROP TABLE IF EXISTS teams;

db/migrations/003_ideas.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ CREATE TABLE IF NOT EXISTS ideas (
1212
);
1313

1414
-- +goose Down
15-
16-
DROP TABLE ideas;
15+
DROP TABLE IF EXISTS ideas;

db/migrations/006_reviews.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- +goose Up
2+
CREATE TABLE IF NOT EXISTS reviews (
3+
id UUID PRIMARY KEY,
4+
team_id UUID NOT NULL,
5+
reviewer TEXT NOT NULL,
6+
innovation_score DOUBLE PRECISION NOT NULL,
7+
functionality_score DOUBLE PRECISION NOT NULL,
8+
design_score DOUBLE PRECISION NOT NULL,
9+
tech_score DOUBLE PRECISION NOT NULL,
10+
presentation_score DOUBLE PRECISION NOT NULL,
11+
comments TEXT NOT NULL,
12+
total_score DOUBLE PRECISION NOT NULL,
13+
review_round INTEGER NOT NULL
14+
);
15+
16+
-- +goose Down
17+
DROP TABLE IF EXISTS reviews;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- +goose Up
2+
ALTER TABLE reviews
3+
ADD CONSTRAINT fk_reviews
4+
FOREIGN KEY (team_id)
5+
REFERENCES teams(id)
6+
ON UPDATE CASCADE;
7+
8+
-- +goose Down
9+
ALTER TABLE reviews
10+
DROP CONSTRAINT fk_reviews;
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
package controllers
2+
3+
import (
4+
"database/sql"
5+
"errors"
6+
"net/http"
7+
"strconv"
8+
"strings"
9+
10+
"github.com/CodeChefVIT/devsoc-backend-24/internal/models"
11+
services "github.com/CodeChefVIT/devsoc-backend-24/internal/services/admin"
12+
"github.com/google/uuid"
13+
"github.com/labstack/echo/v4"
14+
)
15+
16+
func ReviewTeam(ctx echo.Context) error {
17+
var payload models.TeamReviewRequest
18+
19+
if err := ctx.Bind(&payload); err != nil {
20+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
21+
"message": "invalid request payload",
22+
"status": "fail",
23+
"data": nil,
24+
})
25+
}
26+
27+
if err := ctx.Validate(&payload); err != nil {
28+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
29+
"message": err.Error(),
30+
"status": "fail",
31+
"data": nil,
32+
})
33+
}
34+
35+
totalScore := payload.InnovationScore + payload.FunctionalityScore + payload.DesignScore + payload.TechScore + payload.PresentationScore
36+
37+
review := models.TeamReview{
38+
ID: uuid.New(),
39+
TeamID: payload.TeamID,
40+
Reviewer: payload.Reviewer,
41+
InnovationScore: payload.InnovationScore,
42+
FunctionalityScore: payload.FunctionalityScore,
43+
DesignScore: payload.DesignScore,
44+
TechScore: payload.TechScore,
45+
PresentationScore: payload.PresentationScore,
46+
ReviewRound: payload.ReviewRound,
47+
Comments: payload.Comments,
48+
TotalScore: totalScore,
49+
}
50+
51+
if err := services.InsertReview(review); err != nil {
52+
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
53+
"message": err.Error(),
54+
"status": "fail",
55+
"data": nil,
56+
})
57+
}
58+
59+
return ctx.JSON(http.StatusOK, map[string]interface{}{
60+
"message": "review inserted",
61+
"status": "success",
62+
"data": review,
63+
})
64+
}
65+
66+
func GetReviewsByTeamID(ctx echo.Context) error {
67+
teamIDStr := ctx.Param("id")
68+
69+
teamID, err := uuid.Parse(teamIDStr)
70+
if err != nil {
71+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
72+
"message": "invalid team id",
73+
"status": "fail",
74+
"data": nil,
75+
})
76+
}
77+
78+
reviews, err := services.GetReviewsByTeamID(teamID)
79+
if err != nil {
80+
if errors.Is(err, sql.ErrNoRows) {
81+
return ctx.JSON(http.StatusNotFound, map[string]interface{}{
82+
"message": "no reviews found",
83+
"status": "fail",
84+
"data": nil,
85+
})
86+
}
87+
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
88+
"message": err.Error(),
89+
"status": "fail",
90+
"data": nil,
91+
})
92+
}
93+
94+
return ctx.JSON(http.StatusOK, map[string]interface{}{
95+
"message": "reviews found",
96+
"status": "success",
97+
"data": reviews,
98+
})
99+
}
100+
101+
func GetReviewsByRound(ctx echo.Context) error {
102+
roundStr := ctx.Param("round")
103+
104+
round, err := strconv.Atoi(roundStr)
105+
if err != nil {
106+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
107+
"message": "invalid round id",
108+
"status": "fail",
109+
"data": nil,
110+
})
111+
}
112+
113+
reviews, err := services.GetReviewsByRound(round)
114+
if err != nil {
115+
if errors.Is(err, sql.ErrNoRows) {
116+
return ctx.JSON(http.StatusNotFound, map[string]interface{}{
117+
"message": "no reviews found",
118+
"status": "fail",
119+
"data": nil,
120+
})
121+
}
122+
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
123+
"message": err.Error(),
124+
"status": "fail",
125+
"data": nil,
126+
})
127+
}
128+
129+
return ctx.JSON(http.StatusOK, map[string]interface{}{
130+
"message": "reviews found",
131+
"status": "success",
132+
"data": reviews,
133+
})
134+
}
135+
136+
func UpdateReview(ctx echo.Context) error {
137+
var payload models.UpdateTeamReviewRequest
138+
139+
if err := ctx.Bind(&payload); err != nil {
140+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
141+
"message": err.Error(),
142+
"status": "fail",
143+
"data": nil,
144+
})
145+
}
146+
147+
if err := ctx.Validate(&payload); err != nil {
148+
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
149+
"message": err.Error(),
150+
"status": "fail",
151+
"data": nil,
152+
})
153+
}
154+
155+
review, err := services.GetReviewByID(payload.ID)
156+
if err != nil {
157+
if errors.Is(err, sql.ErrNoRows) {
158+
return ctx.JSON(http.StatusNotFound, map[string]interface{}{
159+
"message": "review not found",
160+
"status": "fail",
161+
"data": nil,
162+
})
163+
}
164+
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
165+
"message": err.Error(),
166+
"status": "fail",
167+
"data": nil,
168+
})
169+
}
170+
171+
payload.Reviewer = strings.TrimSpace(payload.Reviewer)
172+
payload.Comments = strings.TrimSpace(payload.Comments)
173+
174+
if payload.Reviewer != "" {
175+
review.Reviewer = payload.Reviewer
176+
}
177+
178+
if payload.FunctionalityScore != nil {
179+
review.TotalScore -= review.FunctionalityScore
180+
review.TotalScore += *payload.FunctionalityScore
181+
review.FunctionalityScore = *payload.FunctionalityScore
182+
}
183+
184+
if payload.DesignScore != nil {
185+
review.TotalScore -= review.DesignScore
186+
review.TotalScore += *payload.DesignScore
187+
review.DesignScore = *payload.DesignScore
188+
}
189+
190+
if payload.InnovationScore != nil {
191+
review.TotalScore -= review.InnovationScore
192+
review.TotalScore += *payload.InnovationScore
193+
review.InnovationScore = *payload.InnovationScore
194+
}
195+
196+
if payload.PresentationScore != nil {
197+
review.TotalScore -= review.PresentationScore
198+
review.TotalScore += *payload.PresentationScore
199+
review.PresentationScore = *payload.PresentationScore
200+
}
201+
202+
if payload.TechScore != nil {
203+
review.TotalScore -= review.TechScore
204+
review.TotalScore += *payload.TechScore
205+
review.TechScore = *payload.TechScore
206+
}
207+
208+
if payload.ReviewRound != nil {
209+
review.ReviewRound = *payload.ReviewRound
210+
}
211+
212+
if payload.Comments != "" {
213+
review.Comments = payload.Comments
214+
}
215+
216+
if err := services.UpdateReview(review); err != nil {
217+
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
218+
"message": err.Error(),
219+
"status": "fail",
220+
"data": nil,
221+
})
222+
}
223+
224+
return ctx.JSON(http.StatusOK, map[string]interface{}{
225+
"message": "review updated",
226+
"status": "success",
227+
})
228+
}

internal/controllers/user_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func CompleteProfile(ctx echo.Context) error {
243243
if errors.As(err, &pgerr) {
244244
if pgerr.Code == "23505" {
245245
return ctx.JSON(http.StatusExpectationFailed, map[string]string{
246-
"message": "team name already exists",
246+
"message": "vit email already exists",
247247
"status": "failed to update team",
248248
})
249249
}

internal/models/review_model.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package models
2+
3+
import "github.com/google/uuid"
4+
5+
type TeamReview struct {
6+
ID uuid.UUID `json:"id"`
7+
TeamID uuid.UUID `json:"team_id"`
8+
Reviewer string `json:"reviewer"`
9+
InnovationScore float64 `json:"innovation_and_creativity"`
10+
FunctionalityScore float64 `json:"functionality_and_completeness"`
11+
DesignScore float64 `json:"ui_and_design"`
12+
TechScore float64 `json:"techincal_implementation"`
13+
PresentationScore float64 `json:"presentation_and_communication"`
14+
ReviewRound int `json:"review_round"`
15+
Comments string `json:"comments"`
16+
TotalScore float64 `json:"total_score"`
17+
}
18+
19+
type TeamReviewRequest struct {
20+
TeamID uuid.UUID `json:"team_id" validate:"required,uuid"`
21+
Reviewer string `json:"reviewer" validate:"required"`
22+
InnovationScore float64 `json:"innovation_and_creativity" validate:"required"`
23+
FunctionalityScore float64 `json:"functionality_and_completeness" validate:"required"`
24+
DesignScore float64 `json:"ui_and_design" validate:"required"`
25+
TechScore float64 `json:"techincal_implementation" validate:"required"`
26+
PresentationScore float64 `json:"presentation_and_communication" validate:"required"`
27+
ReviewRound int `json:"review_round" validate:"required"`
28+
Comments string `json:"comments"`
29+
}
30+
31+
type UpdateTeamReviewRequest struct {
32+
ID uuid.UUID `json:"id" validate:"required,uuid"`
33+
Reviewer string `json:"reviewer"`
34+
InnovationScore *float64 `json:"innovation_and_creativity,omitempty"`
35+
FunctionalityScore *float64 `json:"functionality_and_completeness,omitempty"`
36+
DesignScore *float64 `json:"ui_and_design,omitempty"`
37+
TechScore *float64 `json:"techincal_implementation,omitempty"`
38+
PresentationScore *float64 `json:"presentation_and_communication,omitempty"`
39+
ReviewRound *int `json:"review_round,omitempty"`
40+
Comments string `json:"comments"`
41+
}

internal/models/user_model.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ type GetUser struct {
115115
ID uuid.UUID `json:"id"`
116116
IsLeader bool `json:"is_leader"`
117117
}
118+
119+
type GetAdminUser struct {
120+
GetUser
121+
Email string `json:"email"`
122+
}
118123
type ResendOTPRequest struct {
119124
Email string `json:"email" validate:"required,email"`
120125
Type string `json:"type" validate:"required,oneof=verification resetpass"`

internal/routes/admin_routes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ func AdminRoutes(incomingRoutes *echo.Echo) {
2828

2929
admin.GET("/projects/all", controllers.GetAllProject)
3030
admin.GET("/ideas/all", controllers.GetAllIdeas)
31+
admin.POST("/idea/shortlist", controllers.ShortList, middleware.EditOnly)
3132

32-
admin.POST("/idea/shortlist", controllers.ShortList)
33+
admin.GET("/reviews/:round", controllers.GetReviewsByRound)
34+
admin.GET("/reviews/team/:id", controllers.GetReviewsByTeamID)
35+
admin.POST("/review", controllers.ReviewTeam, middleware.EditOnly)
36+
admin.PATCH("/review", controllers.UpdateReview, middleware.EditOnly)
3337

3438
//admin.GET("/team/freshers", controllers.GetAllFresherTeams)
3539
//admin.GET("/team/females", controllers.GetAllFemaleTeams)

0 commit comments

Comments
 (0)