-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
385f948
commit bc71d39
Showing
5 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ import ( | |
|
||
func main() { | ||
db := config.NewDatabase() | ||
seeders.Run(db) | ||
seeders.OnlyCardsRun(db) | ||
} |
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,14 @@ | ||
//go:build migrate | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/Game-as-a-Service/The-Message/config" | ||
"github.com/Game-as-a-Service/The-Message/database/seeders" | ||
_ "github.com/joho/godotenv/autoload" | ||
) | ||
|
||
func main() { | ||
db := config.NewDatabase() | ||
seeders.Run(db) | ||
} |
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,46 @@ | ||
package seeders | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/Game-as-a-Service/The-Message/enums" | ||
"github.com/Game-as-a-Service/The-Message/service/repository" | ||
"github.com/go-faker/faker/v4" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func SeederGameWithPlayers(db *gorm.DB) { | ||
// Get all cards | ||
var cards []*repository.Card | ||
_ = db.Find(&cards) | ||
|
||
// Fake game data | ||
game := &repository.Game{ | ||
RoomID: faker.UUIDDigit(), | ||
Status: enums.ActionCardStage, | ||
Players: []repository.Player{}, | ||
} | ||
|
||
// Fake player count random 1~3 | ||
playerCount := rand.Intn(3) + 1 | ||
|
||
// Fake players data | ||
for i := 0; i < playerCount; i++ { | ||
player := repository.Player{ | ||
UserID: faker.UUIDDigit(), | ||
Name: faker.FirstName(), | ||
PlayerCards: []repository.PlayerCard{}, | ||
} | ||
|
||
// Each player gets 3 cards | ||
for j := 0; j < 3; j++ { | ||
player.PlayerCards = append(player.PlayerCards, repository.PlayerCard{ | ||
CardID: cards[i*3+j].ID, | ||
Type: "hand", | ||
}) | ||
} | ||
game.Players = append(game.Players, player) | ||
} | ||
|
||
_ = db.Create(&game) | ||
} |
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