Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions db/clans.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ func GetClansCount() (int, error) {
return count, nil
}

// GetClanMemberCount Returns the amount of users that are in a given clan
func GetClanMemberCount(clanId int) (int, error) {
var count int

result := SQL.Raw("SELECT COUNT(*) as count FROM users WHERE clan_id = ?", clanId).
Scan(&count)

if result.Error != nil {
return 0, result.Error
}

return count, nil
}

// DeleteClan Fully deletes a clan with a given id
func DeleteClan(id int) error {
err := SQL.Transaction(func(tx *gorm.DB) error {
Expand Down
10 changes: 10 additions & 0 deletions handlers/clan_invites.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func AcceptClanInvite(c *gin.Context) *APIError {
return apiErr
}

memberCount, err := db.GetClanMemberCount(invite.ClanId)

if err != nil {
return APIErrorServerError("Error retrieving clan member count", err)
}

if memberCount >= 100 {
return APIErrorBadRequest("The clan you are trying to join is already full.")
}

if err := db.UpdateUserClan(user.Id, invite.ClanId); err != nil {
return APIErrorServerError("Error updating user clan", err)
}
Expand Down
Loading