Skip to content

Commit 58d9ea6

Browse files
authored
Merge pull request #35 from Oik17/master
Get all female and fresher teams
2 parents 9cef1ec + fdf8ae1 commit 58d9ea6

File tree

7 files changed

+148
-33
lines changed

7 files changed

+148
-33
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: '3'
22
services:
3+
34
api:
45
build: .
56
ports:
@@ -9,4 +10,3 @@ services:
910
env_file:
1011
- .env
1112
restart: on-failure
12-

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,34 @@ require (
2020
require (
2121
cloud.google.com/go/compute v1.23.3 // indirect
2222
cloud.google.com/go/compute/metadata v0.2.3 // indirect
23+
filippo.io/edwards25519 v1.1.0 // indirect
2324
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2425
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2526
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2627
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
2728
github.com/go-playground/locales v0.14.1 // indirect
2829
github.com/go-playground/universal-translator v0.18.1 // indirect
30+
github.com/go-sql-driver/mysql v1.8.0 // indirect
2931
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3032
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3133
github.com/golang/protobuf v1.5.3 // indirect
3234
github.com/google/s2a-go v0.1.7 // indirect
3335
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
3436
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
37+
github.com/grailbio-external/goose v4.0.1+incompatible // indirect
3538
github.com/jackc/pgpassfile v1.0.0 // indirect
3639
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
3740
github.com/jackc/puddle/v2 v2.2.1 // indirect
3841
github.com/labstack/gommon v0.4.2 // indirect
3942
github.com/leodido/go-urn v1.2.4 // indirect
43+
github.com/lib/pq v1.10.9 // indirect
4044
github.com/mattn/go-colorable v0.1.13 // indirect
4145
github.com/mattn/go-isatty v0.0.20 // indirect
46+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
4247
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4348
github.com/valyala/bytebufferpool v1.0.0 // indirect
4449
github.com/valyala/fasttemplate v1.2.2 // indirect
50+
github.com/ziutek/mymysql v1.5.4 // indirect
4551
go.opencensus.io v0.24.0 // indirect
4652
golang.org/x/net v0.20.0 // indirect
4753
golang.org/x/sync v0.5.0 // indirect

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiV
33
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
44
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
55
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
6+
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
7+
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
68
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
79
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
810
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
@@ -33,6 +35,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
3335
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
3436
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
3537
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
38+
github.com/go-sql-driver/mysql v1.8.0 h1:UtktXaU2Nb64z/pLiGIxY4431SJ4/dR5cjMmlVHgnT4=
39+
github.com/go-sql-driver/mysql v1.8.0/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
3640
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
3741
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
3842
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
@@ -73,6 +77,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF
7377
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
7478
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
7579
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
80+
github.com/grailbio-external/goose v4.0.1+incompatible h1:jST4yUuBedXmgVCd6uLrIDzNurZKv2IkaZZRWnD4tuo=
81+
github.com/grailbio-external/goose v4.0.1+incompatible/go.mod h1:iT97/OP5V1NfG4dvLI1gtZeBrIxBClclzxBC1sUBWsc=
7682
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
7783
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
7884
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@@ -89,11 +95,15 @@ github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0
8995
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
9096
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
9197
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
98+
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
99+
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
92100
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
93101
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
94102
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
95103
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
96104
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
105+
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
106+
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
97107
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
98108
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
99109
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -115,6 +125,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
115125
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
116126
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
117127
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
128+
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
129+
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
118130
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
119131
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
120132
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

internal/controllers/admin_teams_controller.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func GetTeams(ctx echo.Context) error {
104104
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
105105
"message": "Successfully fetched teams",
106106
"data": team,
107-
"status": "false",
107+
"status": "true",
108108
})
109109
}
110110

@@ -188,3 +188,35 @@ func GetTeamLeader(ctx echo.Context) error {
188188
})
189189

190190
}
191+
192+
func GetAllFresherTeams(ctx echo.Context) error {
193+
team, err := teamService.GetAllFresherTeam()
194+
if err != nil {
195+
return ctx.JSON(http.StatusBadRequest, map[string]string{
196+
"message": "Failed to fetch teams",
197+
"data": err.Error(),
198+
"status": "false",
199+
})
200+
}
201+
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
202+
"message": "Successfully fetched teams",
203+
"data": team,
204+
"status": "true",
205+
})
206+
}
207+
208+
func GetAllFemaleTeams(ctx echo.Context) error {
209+
team, err := teamService.GetAllFemaleTeams()
210+
if err != nil {
211+
return ctx.JSON(http.StatusBadRequest, map[string]string{
212+
"message": "Failed to fetch teams",
213+
"data": err.Error(),
214+
"status": "false",
215+
})
216+
}
217+
return ctx.JSON(http.StatusAccepted, map[string]interface{}{
218+
"message": "Successfully fetched teams",
219+
"data": team,
220+
"status": "true",
221+
})
222+
}

internal/routes/admin_routes.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package routes
22

33
import (
44
"github.com/CodeChefVIT/devsoc-backend-24/internal/controllers"
5-
"github.com/CodeChefVIT/devsoc-backend-24/internal/middleware"
65
"github.com/labstack/echo/v4"
76
)
87

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

3029
admin.GET("/projects/all", controllers.GetAllProject)
3130
admin.GET("/ideas/all", controllers.GetAllIdeas)
31+
32+
admin.GET("/team/freshers", controllers.GetAllFresherTeams)
33+
admin.GET("/team/females", controllers.GetAllFemaleTeams)
3234
}

internal/services/team/get_team.go

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212

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

16-
query := `SELECT teams.name,teams.code, teams.leader_id, teams.round ,
17-
users.first_name, users.last_name, users.id, users.reg_no,
18-
ideas.title, ideas.description, ideas.track, ideas.github, ideas.figma, ideas.others ,
19-
projects.name, projects.description, projects.github, projects.figma, projects.track, projects.others
20-
FROM teams
21-
INNER JOIN users ON users.team_id = teams.id
22-
LEFT JOIN projects ON teams.id = projects.teamid
23-
LEFT JOIN ideas ON teams.id = ideas.teamid`
17+
query := `SELECT teams.name, teams.code, teams.leader_id, teams.round,
18+
users.first_name, users.last_name, users.id, users.reg_no,
19+
ideas.title, ideas.description, ideas.track, ideas.github, ideas.figma, ideas.others,
20+
projects.name, projects.description, projects.github, projects.figma, projects.track, projects.others
21+
FROM teams
22+
INNER JOIN users ON users.team_id = teams.id
23+
LEFT JOIN projects ON teams.id = projects.teamid
24+
LEFT JOIN ideas ON teams.id = ideas.teamid`
2425

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

3637
for rows.Next() {
3738
var team models.GetTeam
39+
3840
values := make([]sql.NullString, len(columns))
3941
columnPointers := make([]interface{}, len(columns))
4042

@@ -45,11 +47,30 @@ func GetAllTeams() ([]models.GetTeam, error) {
4547
if err := rows.Scan(columnPointers...); err != nil {
4648
return teams, err
4749
}
50+
round, err := strconv.Atoi(values[3].String)
51+
if err != nil {
52+
return teams, err
53+
}
54+
teamCode := values[1].String
55+
if _, ok := teamMap[teamCode]; !ok {
56+
team = models.GetTeam{
57+
TeamName: values[0].String,
58+
TeamCode: teamCode,
59+
LeaderID: uuid.MustParse(values[2].String),
60+
Round: round,
61+
Ideas: models.Idea{},
62+
Project: models.Project{},
63+
Users: []models.GetUser{},
64+
}
65+
teamMap[teamCode] = &team
66+
}
4867

49-
team.TeamName = values[0].String
50-
team.TeamCode = values[1].String
51-
team.LeaderID = uuid.MustParse(values[2].String)
52-
team.Round, _ = strconv.Atoi(values[3].String)
68+
user := models.GetUser{
69+
FullName: values[4].String + " " + values[5].String,
70+
RegNo: values[7].String,
71+
ID: uuid.MustParse(values[6].String),
72+
IsLeader: values[7].String == values[2].String,
73+
}
5374

5475
if values[8].Valid {
5576
team.Ideas = models.Idea{
@@ -72,23 +93,11 @@ func GetAllTeams() ([]models.GetTeam, error) {
7293
Others: values[19].String,
7394
}
7495
}
96+
teamMap[teamCode].Users = append(teamMap[teamCode].Users, user)
97+
}
7598

76-
var isLeader bool
77-
if values[7].Valid {
78-
isLeader = values[7].String != ""
79-
} else {
80-
isLeader = false
81-
}
82-
83-
user := models.GetUser{
84-
FullName: values[4].String,
85-
RegNo: values[5].String,
86-
ID: uuid.MustParse(values[6].String),
87-
IsLeader: isLeader,
88-
}
89-
team.Users = append(team.Users, user)
90-
91-
teams = append(teams, team)
99+
for _, team := range teamMap {
100+
teams = append(teams, *team)
92101
}
93102

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

173182
return team, err
174183
}
184+
185+
func GetAllFresherTeam() ([]models.GetTeam, error) {
186+
var teamFresher []models.GetTeam
187+
teams, err := GetAllTeams()
188+
if err != nil {
189+
return teams, err
190+
}
191+
for _, team := range teams {
192+
if IsFresher(team) {
193+
teamFresher = append(teamFresher, team)
194+
}
195+
}
196+
return teamFresher, nil
197+
198+
}
199+
200+
func GetAllFemaleTeams() ([]models.GetTeam, error) {
201+
var teamFemale []models.GetTeam
202+
teams, err := GetAllTeams()
203+
if err != nil {
204+
return teams, err
205+
}
206+
for _, team := range teams {
207+
if IsFemale(team) {
208+
teamFemale = append(teamFemale, team)
209+
}
210+
}
211+
return teamFemale, nil
212+
}

internal/services/team/team_checks.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"github.com/google/uuid"
55

66
"github.com/CodeChefVIT/devsoc-backend-24/internal/database"
7+
"github.com/CodeChefVIT/devsoc-backend-24/internal/models"
8+
9+
services "github.com/CodeChefVIT/devsoc-backend-24/internal/services/user"
710
)
811

912
func CheckTeamCode(code string) bool {
@@ -38,3 +41,25 @@ func CheckUserInTeam(id uuid.UUID, teamid uuid.UUID) bool {
3841
}
3942
return true
4043
}
44+
45+
func IsFresher(team models.GetTeam) bool {
46+
for _, user := range team.Users {
47+
if user.RegNo[:2] != "23" {
48+
return false
49+
}
50+
}
51+
return true
52+
}
53+
54+
func IsFemale(team models.GetTeam) bool {
55+
for _, user := range team.Users {
56+
userData, err := services.FindUserByID(user.ID)
57+
if err != nil {
58+
return false
59+
}
60+
if userData.Gender != "Female" {
61+
return false
62+
}
63+
}
64+
return true
65+
}

0 commit comments

Comments
 (0)