-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseed.go
44 lines (38 loc) · 1.11 KB
/
seed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"context"
"fmt"
"github.com/saleh-ghazimoradi/Gophergram/internal/repository"
"github.com/saleh-ghazimoradi/Gophergram/internal/service"
"github.com/saleh-ghazimoradi/Gophergram/utils"
"log"
"github.com/spf13/cobra"
)
// seedCmd represents the seed command
var seedCmd = &cobra.Command{
Use: "seed",
Short: "Seeding DB",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("seed called")
db, err := utils.PostConnection()
if err != nil {
log.Fatal(err)
}
postRepository := repository.NewPostRepository(db, db)
userRepository := repository.NewUserRepository(db, db)
commentRepository := repository.NewCommentRepository(db, db)
postService := service.NewPostService(postRepository, db)
userService := service.NewUserService(userRepository, db)
commentService := service.NewCommentService(commentRepository)
seed := service.NewSeederService(userService, postService, commentService)
if err := seed.Seed(context.Background(), db); err != nil {
log.Fatal(err)
}
},
}
func init() {
rootCmd.AddCommand(seedCmd)
}