mirror of
https://github.com/sigmasternchen/threadule
synced 2025-03-15 08:09:01 +00:00
added models
This commit is contained in:
parent
a7153e44c6
commit
3bc7a42e62
9 changed files with 92 additions and 1 deletions
|
@ -5,6 +5,7 @@ go 1.16
|
||||||
require (
|
require (
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.3
|
github.com/pelletier/go-toml/v2 v2.0.0-beta.3
|
||||||
|
github.com/satori/go.uuid v1.2.0
|
||||||
gorm.io/driver/mysql v1.1.2
|
gorm.io/driver/mysql v1.1.2
|
||||||
gorm.io/gorm v1.21.13
|
gorm.io/gorm v1.21.13
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,9 +12,12 @@ github.com/pelletier/go-toml/v2 v2.0.0-beta.3 h1:PNCTU4naEJ8mKal97P3A2qDU74QRQGl
|
||||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.3/go.mod h1:aNseLYu/uKskg0zpr/kbr2z8yGuWtotWf/0BpGIAL2Y=
|
github.com/pelletier/go-toml/v2 v2.0.0-beta.3/go.mod h1:aNseLYu/uKskg0zpr/kbr2z8yGuWtotWf/0BpGIAL2Y=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||||
|
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU=
|
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU=
|
||||||
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
|
"threadule/backend/internal/data/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func connect(dsn string) (*gorm.DB, error) {
|
func connect(dsn string) (*gorm.DB, error) {
|
||||||
|
@ -14,7 +15,11 @@ func connect(dsn string) (*gorm.DB, error) {
|
||||||
func migrate(db *gorm.DB) error {
|
func migrate(db *gorm.DB) error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
//errs = append(errs, db.AutoMigrate())
|
errs = append(errs, db.AutoMigrate(&models.Group{}))
|
||||||
|
errs = append(errs, db.AutoMigrate(&models.User{}))
|
||||||
|
errs = append(errs, db.AutoMigrate(&models.Account{}))
|
||||||
|
errs = append(errs, db.AutoMigrate(&models.Tweet{}))
|
||||||
|
errs = append(errs, db.AutoMigrate(&models.Thread{}))
|
||||||
|
|
||||||
errorBuilder := strings.Builder{}
|
errorBuilder := strings.Builder{}
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
|
13
backend/internal/data/models/account.go
Normal file
13
backend/internal/data/models/account.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
|
type Account struct {
|
||||||
|
BaseModel
|
||||||
|
UserID uuid.UUID
|
||||||
|
User *User
|
||||||
|
|
||||||
|
Name string
|
||||||
|
AccessToken *string
|
||||||
|
AccessTokenSecret *string
|
||||||
|
}
|
19
backend/internal/data/models/base.go
Normal file
19
backend/internal/data/models/base.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/satori/go.uuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BaseModel struct {
|
||||||
|
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BaseModel) BeforeCreate(_ *gorm.DB) error {
|
||||||
|
b.ID = uuid.NewV4()
|
||||||
|
return nil
|
||||||
|
}
|
13
backend/internal/data/models/group.go
Normal file
13
backend/internal/data/models/group.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
BaseModel
|
||||||
|
Users []*User `gorm:"many2many:user_groups;"`
|
||||||
|
|
||||||
|
Name string
|
||||||
|
DisplayName string
|
||||||
|
|
||||||
|
LimitAccounts uint
|
||||||
|
LimitThreads uint
|
||||||
|
LimitTweets uint
|
||||||
|
}
|
16
backend/internal/data/models/thread.go
Normal file
16
backend/internal/data/models/thread.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Thread struct {
|
||||||
|
BaseModel
|
||||||
|
AccountID uuid.UUID
|
||||||
|
Account *Account
|
||||||
|
Tweets []Tweet
|
||||||
|
|
||||||
|
Sent bool
|
||||||
|
ScheduledFor time.Time
|
||||||
|
}
|
12
backend/internal/data/models/tweet.go
Normal file
12
backend/internal/data/models/tweet.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
|
type Tweet struct {
|
||||||
|
BaseModel
|
||||||
|
ThreadID uuid.UUID
|
||||||
|
|
||||||
|
TweetID *string
|
||||||
|
Text string
|
||||||
|
Sent bool
|
||||||
|
}
|
9
backend/internal/data/models/user.go
Normal file
9
backend/internal/data/models/user.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
BaseModel
|
||||||
|
Groups []*Group `gorm:"many2many:user_groups;"`
|
||||||
|
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
Loading…
Reference in a new issue