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
|
||||
}
|
||||
Reference in New Issue
Block a user