-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
49 lines (44 loc) · 965 Bytes
/
models.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
45
46
47
48
49
package main
import (
"fmt"
"time"
"github.com/google/uuid"
"github.com/icrowley/fake"
"github.com/jinzhu/gorm"
)
type Event struct {
ID uuid.UUID `gorm:"primary_key; type:uuid; colum:id;default:uuid_generate_v4()`
Title string
Starts time.Time
Ends time.Time
Description string
Category string
IsRecurring bool
Frequency string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
func (event *Event) BeforeCreate(scope *gorm.Scope) error {
id := uuid.New()
scope.SetColumn("ID", id)
return nil
}
func generateFakeEvent(count int) {
db := getDB()
defer db.Close()
for i := 0; i < count; i++ {
title := fake.Sentence()
starts := time.Now()
ends := time.Now()
description := fmt.Sprintf("Description %d", i)
event := Event{
Title: title,
Starts: starts,
Ends: ends,
Description: description,
}
db.Create(&event)
fmt.Printf("%+v \n", event)
}
}