Start refactoring
This commit is contained in:
12
data/datasource/datasource.go
Normal file
12
data/datasource/datasource.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
Datasource interface {
|
||||
Connect(dsn string) error
|
||||
DB() *gorm.DB
|
||||
}
|
||||
)
|
||||
40
data/datasource/pgsql/models/game/game.go
Normal file
40
data/datasource/pgsql/models/game/game.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"opensavecloudserver/data/datasource"
|
||||
"opensavecloudserver/data/repository/game"
|
||||
"opensavecloudserver/data/repository/user"
|
||||
)
|
||||
|
||||
type (
|
||||
GameDatasource struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
)
|
||||
|
||||
func (g *GameDatasource) GameMetadataByID(ID game.ID) (game.GameMetadata, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GameDatasource) CreateGameEntry(game game.NewGameEntry) (game.GameMetadata, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GameDatasource) GameSavesHistory(gameID game.ID) ([]game.GameSaveVersion, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GameDatasource) UserGamesByUserID(userID user.ID) ([]game.GameMetadata, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewGameDatasource(dts datasource.Datasource) game.GameRepository {
|
||||
g := new(GameDatasource)
|
||||
g.db = dts.DB()
|
||||
return g
|
||||
}
|
||||
31
data/datasource/pgsql/models/user/user.go
Normal file
31
data/datasource/pgsql/models/user/user.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"opensavecloudserver/data/datasource"
|
||||
"opensavecloudserver/data/repository/user"
|
||||
)
|
||||
|
||||
type (
|
||||
UserDatasource struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
)
|
||||
|
||||
func NewUserDatasource(dts datasource.Datasource) user.UserRepository {
|
||||
repo := new(UserDatasource)
|
||||
repo.db = dts.DB()
|
||||
return repo
|
||||
}
|
||||
|
||||
func (ud *UserDatasource) UserByID(ID user.ID) (user.User, error) {
|
||||
return nil, user.ErrUserNotFound
|
||||
}
|
||||
|
||||
func (ud *UserDatasource) UserByUsername(username string) (user.User, error) {
|
||||
return nil, user.ErrUserNotFound
|
||||
}
|
||||
|
||||
func (ud *UserDatasource) CreateUser(u user.NewUserTemplate) (user.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
30
data/datasource/pgsql/pgsql.go
Normal file
30
data/datasource/pgsql/pgsql.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package pgsql
|
||||
|
||||
import (
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"opensavecloudserver/data/datasource"
|
||||
)
|
||||
|
||||
type (
|
||||
DatabaseDatasource struct {
|
||||
conn *gorm.DB
|
||||
}
|
||||
)
|
||||
|
||||
func NewDatabaseDatasource() datasource.Datasource {
|
||||
return new(DatabaseDatasource)
|
||||
}
|
||||
|
||||
func (dd *DatabaseDatasource) Connect(dsn string) error {
|
||||
conn, err := gorm.Open(postgres.Open(dsn))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dd.conn = conn
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dd *DatabaseDatasource) DB() *gorm.DB {
|
||||
return dd.conn
|
||||
}
|
||||
40
data/repository/game/game.go
Normal file
40
data/repository/game/game.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"opensavecloudserver/data/repository/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
GameRepository interface {
|
||||
GameMetadataByID(ID ID) (GameMetadata, error)
|
||||
CreateGameEntry(game NewGameEntry) (GameMetadata, error)
|
||||
GameSavesHistory(gameID ID) ([]GameSaveVersion, error)
|
||||
UserGamesByUserID(userID user.ID) ([]GameMetadata, error)
|
||||
}
|
||||
|
||||
GameMetadata interface {
|
||||
ID() uuid.UUID
|
||||
Name() string
|
||||
Path() string
|
||||
Revision() string
|
||||
}
|
||||
|
||||
GameSaveVersion interface {
|
||||
ID() string
|
||||
Date() time.Time
|
||||
}
|
||||
|
||||
NewGameEntry interface {
|
||||
Path() string
|
||||
Name() string
|
||||
}
|
||||
|
||||
ID uuid.UUID
|
||||
)
|
||||
|
||||
var (
|
||||
ErrGameNotFound = errors.New("game not found")
|
||||
)
|
||||
36
data/repository/user/user.go
Normal file
36
data/repository/user/user.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type (
|
||||
UserRepository interface {
|
||||
UserByID(ID ID) (User, error)
|
||||
UserByUsername(username string) (User, error)
|
||||
CreateUser(user NewUserTemplate) (User, error)
|
||||
}
|
||||
|
||||
User interface {
|
||||
ID() uuid.UUID
|
||||
Username() string
|
||||
DisplayName() string
|
||||
Roles() []Role
|
||||
SetPassword() string
|
||||
CheckPassword(password string) bool
|
||||
}
|
||||
|
||||
NewUserTemplate interface {
|
||||
Username() string
|
||||
Password() string
|
||||
DisplayName() string
|
||||
}
|
||||
|
||||
ID uuid.UUID
|
||||
Role string
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUserNotFound = errors.New("user not found")
|
||||
)
|
||||
Reference in New Issue
Block a user