Skip to content

Commit

Permalink
Merge pull request #49 from CodeChefVIT/revert-35-master
Browse files Browse the repository at this point in the history
Revert "Get all female and fresher teams"
  • Loading branch information
aditansh authored Mar 17, 2024
2 parents 58d9ea6 + 2f74973 commit 4c1a70e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 148 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version: '3'
services:

api:
build: .
ports:
Expand All @@ -10,3 +9,4 @@ services:
env_file:
- .env
restart: on-failure

6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,28 @@ require (
require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.8.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/grailbio-external/goose v4.0.1+incompatible // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/ziutek/mymysql v1.5.4 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.5.0 // indirect
Expand Down
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiV
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
Expand Down Expand Up @@ -35,8 +33,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.8.0 h1:UtktXaU2Nb64z/pLiGIxY4431SJ4/dR5cjMmlVHgnT4=
github.com/go-sql-driver/mysql v1.8.0/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
Expand Down Expand Up @@ -77,8 +73,6 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
github.com/grailbio-external/goose v4.0.1+incompatible h1:jST4yUuBedXmgVCd6uLrIDzNurZKv2IkaZZRWnD4tuo=
github.com/grailbio-external/goose v4.0.1+incompatible/go.mod h1:iT97/OP5V1NfG4dvLI1gtZeBrIxBClclzxBC1sUBWsc=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
Expand All @@ -95,15 +89,11 @@ github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -125,8 +115,6 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
34 changes: 1 addition & 33 deletions internal/controllers/admin_teams_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetTeams(ctx echo.Context) error {
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
"message": "Successfully fetched teams",
"data": team,
"status": "true",
"status": "false",
})
}

Expand Down Expand Up @@ -188,35 +188,3 @@ func GetTeamLeader(ctx echo.Context) error {
})

}

func GetAllFresherTeams(ctx echo.Context) error {
team, err := teamService.GetAllFresherTeam()
if err != nil {
return ctx.JSON(http.StatusBadRequest, map[string]string{
"message": "Failed to fetch teams",
"data": err.Error(),
"status": "false",
})
}
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
"message": "Successfully fetched teams",
"data": team,
"status": "true",
})
}

func GetAllFemaleTeams(ctx echo.Context) error {
team, err := teamService.GetAllFemaleTeams()
if err != nil {
return ctx.JSON(http.StatusBadRequest, map[string]string{
"message": "Failed to fetch teams",
"data": err.Error(),
"status": "false",
})
}
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
"message": "Successfully fetched teams",
"data": team,
"status": "true",
})
}
8 changes: 3 additions & 5 deletions internal/routes/admin_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"github.com/CodeChefVIT/devsoc-backend-24/internal/controllers"
"github.com/CodeChefVIT/devsoc-backend-24/internal/middleware"
"github.com/labstack/echo/v4"
)

Expand All @@ -23,12 +24,9 @@ func AdminRoutes(incomingRoutes *echo.Echo) {
admin.GET("/team/project/:id", controllers.GetProjectByTeamID)
admin.GET("/team/leader/:id", controllers.GetTeamLeader)
admin.GET("/team/idea/:id", controllers.GetIdeaByTeamID)
admin.POST("/team/ban/:id", controllers.BanTeam)
admin.POST("/team/unban/:id", controllers.UnbanTeam)
admin.GET("/team/ban/:id", controllers.BanTeam)
admin.GET("/team/unban/:id", controllers.UnbanTeam)

admin.GET("/projects/all", controllers.GetAllProject)
admin.GET("/ideas/all", controllers.GetAllIdeas)

admin.GET("/team/freshers", controllers.GetAllFresherTeams)
admin.GET("/team/females", controllers.GetAllFemaleTeams)
}
94 changes: 28 additions & 66 deletions internal/services/team/get_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import (

func GetAllTeams() ([]models.GetTeam, error) {
var teams []models.GetTeam
teamMap := make(map[string]*models.GetTeam)

query := `SELECT teams.name, teams.code, teams.leader_id, teams.round,
users.first_name, users.last_name, users.id, users.reg_no,
ideas.title, ideas.description, ideas.track, ideas.github, ideas.figma, ideas.others,
projects.name, projects.description, projects.github, projects.figma, projects.track, projects.others
FROM teams
INNER JOIN users ON users.team_id = teams.id
LEFT JOIN projects ON teams.id = projects.teamid
LEFT JOIN ideas ON teams.id = ideas.teamid`
query := `SELECT teams.name,teams.code, teams.leader_id, teams.round ,
users.first_name, users.last_name, users.id, users.reg_no,
ideas.title, ideas.description, ideas.track, ideas.github, ideas.figma, ideas.others ,
projects.name, projects.description, projects.github, projects.figma, projects.track, projects.others
FROM teams
INNER JOIN users ON users.team_id = teams.id
LEFT JOIN projects ON teams.id = projects.teamid
LEFT JOIN ideas ON teams.id = ideas.teamid`

rows, err := database.DB.Query(query)
if err != nil {
Expand All @@ -36,7 +35,6 @@ func GetAllTeams() ([]models.GetTeam, error) {

for rows.Next() {
var team models.GetTeam

values := make([]sql.NullString, len(columns))
columnPointers := make([]interface{}, len(columns))

Expand All @@ -47,30 +45,11 @@ func GetAllTeams() ([]models.GetTeam, error) {
if err := rows.Scan(columnPointers...); err != nil {
return teams, err
}
round, err := strconv.Atoi(values[3].String)
if err != nil {
return teams, err
}
teamCode := values[1].String
if _, ok := teamMap[teamCode]; !ok {
team = models.GetTeam{
TeamName: values[0].String,
TeamCode: teamCode,
LeaderID: uuid.MustParse(values[2].String),
Round: round,
Ideas: models.Idea{},
Project: models.Project{},
Users: []models.GetUser{},
}
teamMap[teamCode] = &team
}

user := models.GetUser{
FullName: values[4].String + " " + values[5].String,
RegNo: values[7].String,
ID: uuid.MustParse(values[6].String),
IsLeader: values[7].String == values[2].String,
}
team.TeamName = values[0].String
team.TeamCode = values[1].String
team.LeaderID = uuid.MustParse(values[2].String)
team.Round, _ = strconv.Atoi(values[3].String)

if values[8].Valid {
team.Ideas = models.Idea{
Expand All @@ -93,11 +72,23 @@ func GetAllTeams() ([]models.GetTeam, error) {
Others: values[19].String,
}
}
teamMap[teamCode].Users = append(teamMap[teamCode].Users, user)
}

for _, team := range teamMap {
teams = append(teams, *team)
var isLeader bool
if values[7].Valid {
isLeader = values[7].String != ""
} else {
isLeader = false
}

user := models.GetUser{
FullName: values[4].String,
RegNo: values[5].String,
ID: uuid.MustParse(values[6].String),
IsLeader: isLeader,
}
team.Users = append(team.Users, user)

teams = append(teams, team)
}

return teams, nil
Expand Down Expand Up @@ -181,32 +172,3 @@ func FindTeamByCode(code string) (models.Team, error) {

return team, err
}

func GetAllFresherTeam() ([]models.GetTeam, error) {
var teamFresher []models.GetTeam
teams, err := GetAllTeams()
if err != nil {
return teams, err
}
for _, team := range teams {
if IsFresher(team) {
teamFresher = append(teamFresher, team)
}
}
return teamFresher, nil

}

func GetAllFemaleTeams() ([]models.GetTeam, error) {
var teamFemale []models.GetTeam
teams, err := GetAllTeams()
if err != nil {
return teams, err
}
for _, team := range teams {
if IsFemale(team) {
teamFemale = append(teamFemale, team)
}
}
return teamFemale, nil
}
25 changes: 0 additions & 25 deletions internal/services/team/team_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"github.com/google/uuid"

"github.com/CodeChefVIT/devsoc-backend-24/internal/database"
"github.com/CodeChefVIT/devsoc-backend-24/internal/models"

services "github.com/CodeChefVIT/devsoc-backend-24/internal/services/user"
)

func CheckTeamCode(code string) bool {
Expand Down Expand Up @@ -41,25 +38,3 @@ func CheckUserInTeam(id uuid.UUID, teamid uuid.UUID) bool {
}
return true
}

func IsFresher(team models.GetTeam) bool {
for _, user := range team.Users {
if user.RegNo[:2] != "23" {
return false
}
}
return true
}

func IsFemale(team models.GetTeam) bool {
for _, user := range team.Users {
userData, err := services.FindUserByID(user.ID)
if err != nil {
return false
}
if userData.Gender != "Female" {
return false
}
}
return true
}

0 comments on commit 4c1a70e

Please sign in to comment.