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
15 changes: 15 additions & 0 deletions cmd/console/commands/clan_rank_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ var ClanRankMapCmd = &cobra.Command{

if err := db.UpdateMapClanRanked(mapQua.Id, true); err != nil {
logrus.Error("Error updating clan ranked status: ", err)
return
}

clanUsers, err := db.GetAllUsersInAClan()

if err != nil {
logrus.Error("Error retrieving users a part of a clan", err)
return
}

for _, user := range clanUsers {
if err := db.NewClanMapRankedNotification(mapQua, user.Id).Insert(); err != nil {
logrus.Error("Error inserting clan map ranked notification", err)
return
}
}

logrus.Info("Ranked Clan Map: ", mapQua.Id, mapQua)
Expand Down
5 changes: 5 additions & 0 deletions cmd/database/migrations/23_users_clan_id_index.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

DROP INDEX users_clan_id_index ON users;

COMMIT;
6 changes: 6 additions & 0 deletions cmd/database/migrations/23_users_clan_id_index.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

CREATE INDEX users_clan_id_index
ON users (clan_id);

COMMIT;
23 changes: 23 additions & 0 deletions db/user_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
NotificationReceivedOrderItemGift
NotificationDonatorExpired
NotificationClanKicked
NotificationClanMapRanked
)

type UserNotificationCategory int
Expand Down Expand Up @@ -348,3 +349,25 @@ func NewClanKickedNotification(clan *Clan, userId int) *UserNotification {
notif.RawData = string(marshaled)
return notif
}

// NewClanMapRankedNotification Returns a new clan map ranked notification
func NewClanMapRankedNotification(mapQua *MapQua, userId int) *UserNotification {
notif := &UserNotification{
SenderId: QuaverBotId,
ReceiverId: userId,
Type: NotificationClanMapRanked,
Category: NotificationCategoryClan,
}

data := map[string]interface{}{
"map_id": mapQua.Id,
"mapset_id": mapQua.MapsetId,
"map_name": mapQua.String(),
"creator_username": mapQua.CreatorUsername,
"creator_id": mapQua.CreatorId,
}

marshaled, _ := json.Marshal(data)
notif.RawData = string(marshaled)
return notif
}
15 changes: 15 additions & 0 deletions db/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ func GetUsersInClan(clanId int) ([]*User, error) {
return users, nil
}

// GetAllUsersInAClan Returns all users that are in a clan
func GetAllUsersInAClan() ([]*User, error) {
var users = make([]*User, 0)

result := SQL.
Where("users.clan_id IS NOT NULL").
Find(&users)

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

return users, nil
}

// SearchUsersByName Searches for users that have a similar name to the query
func SearchUsersByName(searchQuery string) ([]*User, error) {
var users = make([]*User, 0)
Expand Down
Loading