-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from Black-Sirius69/master
feat: feat
- Loading branch information
Showing
13 changed files
with
470 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,4 @@ CREATE TABLE IF NOT EXISTS teams ( | |
); | ||
|
||
-- +goose Down | ||
|
||
DROP TABLE teams; | ||
DROP TABLE IF EXISTS teams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,4 @@ CREATE TABLE IF NOT EXISTS ideas ( | |
); | ||
|
||
-- +goose Down | ||
|
||
DROP TABLE ideas; | ||
DROP TABLE IF EXISTS ideas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- +goose Up | ||
CREATE TABLE IF NOT EXISTS reviews ( | ||
id UUID PRIMARY KEY, | ||
team_id UUID NOT NULL, | ||
reviewer TEXT NOT NULL, | ||
innovation_score DOUBLE PRECISION NOT NULL, | ||
functionality_score DOUBLE PRECISION NOT NULL, | ||
design_score DOUBLE PRECISION NOT NULL, | ||
tech_score DOUBLE PRECISION NOT NULL, | ||
presentation_score DOUBLE PRECISION NOT NULL, | ||
comments TEXT NOT NULL, | ||
total_score DOUBLE PRECISION NOT NULL, | ||
review_round INTEGER NOT NULL | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE IF EXISTS reviews; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- +goose Up | ||
ALTER TABLE reviews | ||
ADD CONSTRAINT fk_reviews | ||
FOREIGN KEY (team_id) | ||
REFERENCES teams(id) | ||
ON UPDATE CASCADE; | ||
|
||
-- +goose Down | ||
ALTER TABLE reviews | ||
DROP CONSTRAINT fk_reviews; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
package controllers | ||
|
||
import ( | ||
"database/sql" | ||
"errors" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/CodeChefVIT/devsoc-backend-24/internal/models" | ||
services "github.com/CodeChefVIT/devsoc-backend-24/internal/services/admin" | ||
"github.com/google/uuid" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func ReviewTeam(ctx echo.Context) error { | ||
var payload models.TeamReviewRequest | ||
|
||
if err := ctx.Bind(&payload); err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": "invalid request payload", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
if err := ctx.Validate(&payload); err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
totalScore := payload.InnovationScore + payload.FunctionalityScore + payload.DesignScore + payload.TechScore + payload.PresentationScore | ||
|
||
review := models.TeamReview{ | ||
ID: uuid.New(), | ||
TeamID: payload.TeamID, | ||
Reviewer: payload.Reviewer, | ||
InnovationScore: payload.InnovationScore, | ||
FunctionalityScore: payload.FunctionalityScore, | ||
DesignScore: payload.DesignScore, | ||
TechScore: payload.TechScore, | ||
PresentationScore: payload.PresentationScore, | ||
ReviewRound: payload.ReviewRound, | ||
Comments: payload.Comments, | ||
TotalScore: totalScore, | ||
} | ||
|
||
if err := services.InsertReview(review); err != nil { | ||
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, map[string]interface{}{ | ||
"message": "review inserted", | ||
"status": "success", | ||
"data": review, | ||
}) | ||
} | ||
|
||
func GetReviewsByTeamID(ctx echo.Context) error { | ||
teamIDStr := ctx.Param("id") | ||
|
||
teamID, err := uuid.Parse(teamIDStr) | ||
if err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": "invalid team id", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
reviews, err := services.GetReviewsByTeamID(teamID) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return ctx.JSON(http.StatusNotFound, map[string]interface{}{ | ||
"message": "no reviews found", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, map[string]interface{}{ | ||
"message": "reviews found", | ||
"status": "success", | ||
"data": reviews, | ||
}) | ||
} | ||
|
||
func GetReviewsByRound(ctx echo.Context) error { | ||
roundStr := ctx.Param("round") | ||
|
||
round, err := strconv.Atoi(roundStr) | ||
if err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": "invalid round id", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
reviews, err := services.GetReviewsByRound(round) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return ctx.JSON(http.StatusNotFound, map[string]interface{}{ | ||
"message": "no reviews found", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, map[string]interface{}{ | ||
"message": "reviews found", | ||
"status": "success", | ||
"data": reviews, | ||
}) | ||
} | ||
|
||
func UpdateReview(ctx echo.Context) error { | ||
var payload models.UpdateTeamReviewRequest | ||
|
||
if err := ctx.Bind(&payload); err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
if err := ctx.Validate(&payload); err != nil { | ||
return ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
review, err := services.GetReviewByID(payload.ID) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return ctx.JSON(http.StatusNotFound, map[string]interface{}{ | ||
"message": "review not found", | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
payload.Reviewer = strings.TrimSpace(payload.Reviewer) | ||
payload.Comments = strings.TrimSpace(payload.Comments) | ||
|
||
if payload.Reviewer != "" { | ||
review.Reviewer = payload.Reviewer | ||
} | ||
|
||
if payload.FunctionalityScore != nil { | ||
review.TotalScore -= review.FunctionalityScore | ||
review.TotalScore += *payload.FunctionalityScore | ||
review.FunctionalityScore = *payload.FunctionalityScore | ||
} | ||
|
||
if payload.DesignScore != nil { | ||
review.TotalScore -= review.DesignScore | ||
review.TotalScore += *payload.DesignScore | ||
review.DesignScore = *payload.DesignScore | ||
} | ||
|
||
if payload.InnovationScore != nil { | ||
review.TotalScore -= review.InnovationScore | ||
review.TotalScore += *payload.InnovationScore | ||
review.InnovationScore = *payload.InnovationScore | ||
} | ||
|
||
if payload.PresentationScore != nil { | ||
review.TotalScore -= review.PresentationScore | ||
review.TotalScore += *payload.PresentationScore | ||
review.PresentationScore = *payload.PresentationScore | ||
} | ||
|
||
if payload.TechScore != nil { | ||
review.TotalScore -= review.TechScore | ||
review.TotalScore += *payload.TechScore | ||
review.TechScore = *payload.TechScore | ||
} | ||
|
||
if payload.ReviewRound != nil { | ||
review.ReviewRound = *payload.ReviewRound | ||
} | ||
|
||
if payload.Comments != "" { | ||
review.Comments = payload.Comments | ||
} | ||
|
||
if err := services.UpdateReview(review); err != nil { | ||
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ | ||
"message": err.Error(), | ||
"status": "fail", | ||
"data": nil, | ||
}) | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, map[string]interface{}{ | ||
"message": "review updated", | ||
"status": "success", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package models | ||
|
||
import "github.com/google/uuid" | ||
|
||
type TeamReview struct { | ||
ID uuid.UUID `json:"id"` | ||
TeamID uuid.UUID `json:"team_id"` | ||
Reviewer string `json:"reviewer"` | ||
InnovationScore float64 `json:"innovation_and_creativity"` | ||
FunctionalityScore float64 `json:"functionality_and_completeness"` | ||
DesignScore float64 `json:"ui_and_design"` | ||
TechScore float64 `json:"techincal_implementation"` | ||
PresentationScore float64 `json:"presentation_and_communication"` | ||
ReviewRound int `json:"review_round"` | ||
Comments string `json:"comments"` | ||
TotalScore float64 `json:"total_score"` | ||
} | ||
|
||
type TeamReviewRequest struct { | ||
TeamID uuid.UUID `json:"team_id" validate:"required,uuid"` | ||
Reviewer string `json:"reviewer" validate:"required"` | ||
InnovationScore float64 `json:"innovation_and_creativity" validate:"required"` | ||
FunctionalityScore float64 `json:"functionality_and_completeness" validate:"required"` | ||
DesignScore float64 `json:"ui_and_design" validate:"required"` | ||
TechScore float64 `json:"techincal_implementation" validate:"required"` | ||
PresentationScore float64 `json:"presentation_and_communication" validate:"required"` | ||
ReviewRound int `json:"review_round" validate:"required"` | ||
Comments string `json:"comments"` | ||
} | ||
|
||
type UpdateTeamReviewRequest struct { | ||
ID uuid.UUID `json:"id" validate:"required,uuid"` | ||
Reviewer string `json:"reviewer"` | ||
InnovationScore *float64 `json:"innovation_and_creativity,omitempty"` | ||
FunctionalityScore *float64 `json:"functionality_and_completeness,omitempty"` | ||
DesignScore *float64 `json:"ui_and_design,omitempty"` | ||
TechScore *float64 `json:"techincal_implementation,omitempty"` | ||
PresentationScore *float64 `json:"presentation_and_communication,omitempty"` | ||
ReviewRound *int `json:"review_round,omitempty"` | ||
Comments string `json:"comments"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.