Compare commits
3 Commits
095dac5db7
...
e5deb5d76d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5deb5d76d | ||
|
|
178404639d | ||
|
|
e48854c55b |
2
Makefile
2
Makefile
@@ -9,7 +9,7 @@ db/migration/new:
|
|||||||
|
|
||||||
db/migrations/up:
|
db/migrations/up:
|
||||||
@echo 'Running up migrations...'
|
@echo 'Running up migrations...'
|
||||||
migrate -path ./db/migrations -database ${DB_DSN} up
|
migrate -path ./db/migrations -database ${DB_DSN_MIGRATE} up
|
||||||
|
|
||||||
help:
|
help:
|
||||||
go run ./cmd/api -help
|
go run ./cmd/api -help
|
||||||
|
|||||||
@@ -142,6 +142,8 @@ func main() {
|
|||||||
app.parseFlags()
|
app.parseFlags()
|
||||||
app.foundryApp.SetLogger(app.slogger)
|
app.foundryApp.SetLogger(app.slogger)
|
||||||
|
|
||||||
|
app.slogger.Info("", "dsn", app.cfg.db.dsn)
|
||||||
|
|
||||||
db, err := openDB(app.cfg)
|
db, err := openDB(app.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.slogger.Error("Error when opening database connection", "err", err)
|
app.slogger.Error("Error when opening database connection", "err", err)
|
||||||
|
|||||||
@@ -13,20 +13,20 @@ CREATE TABLE IF NOT EXISTS modules (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS modules_compatibility (
|
CREATE TABLE IF NOT EXISTS modules_compatibility (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
model_id INTEGER UNIQUE,
|
module_id INTEGER UNIQUE,
|
||||||
minimum VARCHAR(64) NOT NULL,
|
minimum VARCHAR(64) NOT NULL,
|
||||||
verified VARCHAR(64) NOT NULL,
|
verified VARCHAR(64) NOT NULL,
|
||||||
maximum VARCHAR(64) NOT NULL,
|
maximum VARCHAR(64) NOT NULL,
|
||||||
|
|
||||||
FOREIGN KEY (model_id) REFERENCES modules(id) ON DELETE CASCADE
|
FOREIGN KEY (module_id) REFERENCES modules(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS modules_languages (
|
CREATE TABLE IF NOT EXISTS modules_languages (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
model_id INTEGER,
|
module_id INTEGER,
|
||||||
language VARCHAR(256) NOT NULL,
|
language VARCHAR(256) NOT NULL,
|
||||||
name VARCHAR(256) NOT NULL,
|
name VARCHAR(256) NOT NULL,
|
||||||
path VARCHAR(256) NOT NULL,
|
path VARCHAR(256) NOT NULL,
|
||||||
|
|
||||||
FOREIGN KEY (model_id) REFERENCES modules(id) ON DELETE CASCADE
|
FOREIGN KEY (module_id) REFERENCES modules(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS users_hotbar (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS users_stats (
|
CREATE TABLE IF NOT EXISTS users_stats (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_id INTEGER,
|
user_id INTEGER UNIQUE,
|
||||||
core_version TEXT NOT NULL,
|
core_version TEXT NOT NULL,
|
||||||
system_id VARCHAR(64) NOT NULL,
|
system_id VARCHAR(64) NOT NULL,
|
||||||
system_version VARCHAR(64) NOT NULL,
|
system_version VARCHAR(64) NOT NULL,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var (
|
|||||||
ErrorNotAuth = errors.New("Admin is not authenticated")
|
ErrorNotAuth = errors.New("Admin is not authenticated")
|
||||||
ErrorIsNotReady = errors.New("Connection is not ready for communication")
|
ErrorIsNotReady = errors.New("Connection is not ready for communication")
|
||||||
|
|
||||||
|
ErrorStateTypeNotExist = errors.New("State type does not exists")
|
||||||
ErrorMsgNotHaveNumber = errors.New("Message doesn't have dataCode and id")
|
ErrorMsgNotHaveNumber = errors.New("Message doesn't have dataCode and id")
|
||||||
ErrorTimeout = errors.New("Answer has not been received after timeout")
|
ErrorTimeout = errors.New("Answer has not been received after timeout")
|
||||||
ErrorReadChannel = errors.New("Error when reading from msg channel")
|
ErrorReadChannel = errors.New("Error when reading from msg channel")
|
||||||
|
|||||||
@@ -11,45 +11,16 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
data "gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models/db"
|
|
||||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/requests"
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/requests"
|
||||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
RespSessionData = "0"
|
|
||||||
RespPingCode = "2"
|
|
||||||
RespSessionId = "40"
|
|
||||||
RespCreateSessionCode = "42"
|
|
||||||
RespDataCode = "43"
|
|
||||||
|
|
||||||
ReqPongCode = "3"
|
|
||||||
ReqCreateSessionCode = "40"
|
|
||||||
ReqDataCode = "42"
|
|
||||||
)
|
|
||||||
|
|
||||||
var RequestCodes = []string{
|
|
||||||
RespSessionData,
|
|
||||||
RespPingCode,
|
|
||||||
RespSessionId,
|
|
||||||
RespCreateSessionCode,
|
|
||||||
RespDataCode,
|
|
||||||
}
|
|
||||||
|
|
||||||
var CodesRespToReq = map[string]string{
|
|
||||||
RespSessionData: ReqCreateSessionCode,
|
|
||||||
RespPingCode: ReqPongCode,
|
|
||||||
RespCreateSessionCode: ReqDataCode,
|
|
||||||
//ReqDataCode: RespCreateSessionCode,
|
|
||||||
}
|
|
||||||
|
|
||||||
type Foundry struct {
|
type Foundry struct {
|
||||||
//TODO: make check of admin's authentication
|
//TODO: make check of admin's authentication
|
||||||
isAuth bool
|
isAuth bool
|
||||||
|
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
models data.Models
|
|
||||||
config requests.Config
|
config requests.Config
|
||||||
ws *webSocketUtil
|
ws *webSocketUtil
|
||||||
}
|
}
|
||||||
@@ -129,6 +100,7 @@ func (foundry *Foundry) StartListen() error {
|
|||||||
foundry.CloseWebSocketConn()
|
foundry.CloseWebSocketConn()
|
||||||
return foundryErr
|
return foundryErr
|
||||||
}
|
}
|
||||||
|
foundry.logger.Warn("Got error when listening or served websocket", "err", err.Error())
|
||||||
}
|
}
|
||||||
case <-wsChannels.Done():
|
case <-wsChannels.Done():
|
||||||
foundry.CloseWebSocketConn()
|
foundry.CloseWebSocketConn()
|
||||||
@@ -195,7 +167,7 @@ func (foundry *Foundry) ListenAndServeWS() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (foundry *Foundry) HandleWSRequest(msgType string) ([]byte, error) {
|
func (foundry *Foundry) HandleWSRequest(msgType string) ([]byte, error) {
|
||||||
msg := foundry.ws.CreateWSMessageByPage("/setup")
|
msg := foundry.ws.CreateWSMessageByPage(msgType)
|
||||||
|
|
||||||
return foundry.ws.HandleWebsocketRequest(msg)
|
return foundry.ws.HandleWebsocketRequest(msg)
|
||||||
}
|
}
|
||||||
@@ -218,7 +190,7 @@ func (foundry *Foundry) SetLogger(slogger *slog.Logger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (foundry *Foundry) CreateNewDataModels(db *sql.DB) {
|
func (foundry *Foundry) CreateNewDataModels(db *sql.DB) {
|
||||||
foundry.models = data.NewModels(db)
|
foundry.ws.CreateNewDataModels(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ import "errors"
|
|||||||
var (
|
var (
|
||||||
ErrorSetupMoreThanOne = errors.New("Passed more than one setupData")
|
ErrorSetupMoreThanOne = errors.New("Passed more than one setupData")
|
||||||
ErrorSetupNotFound = errors.New("Not found setup data from your request")
|
ErrorSetupNotFound = errors.New("Not found setup data from your request")
|
||||||
|
ErrorRecordNotFound = errors.New("Record not found")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package db
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FoundryState struct {
|
type FoundryState struct {
|
||||||
Id int
|
Id int64
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
IsSetup bool
|
IsSetup bool
|
||||||
Type StateType
|
Type StateType
|
||||||
@@ -31,14 +32,14 @@ type FoundryState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Compatibility struct {
|
type Compatibility struct {
|
||||||
Id int
|
Id int64
|
||||||
Minimum string
|
Minimum string
|
||||||
Verified string
|
Verified string
|
||||||
Maximum string
|
Maximum string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Id int
|
Id int64
|
||||||
Language string
|
Language string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,34 +64,34 @@ func (m FoundryStateModel) Insert(state *FoundryState) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = m.InsertOptions(&state.Options, state.Id)
|
err = m.InsertOptions(&state.Options, state.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range state.Modules {
|
for i := range state.Modules {
|
||||||
err = m.InsertModule(&state.Modules[i], state.Id)
|
err = m.InsertModule(&state.Modules[i], state.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range state.Systems {
|
for i := range state.Systems {
|
||||||
err = m.InsertSystem(&state.Systems[i], state.Id)
|
err = m.InsertSystem(&state.Systems[i], state.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range state.Worlds {
|
for i := range state.Worlds {
|
||||||
err = m.InsertWorld(&state.Worlds[i], state.Id)
|
err = m.InsertWorld(&state.Worlds[i], state.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range state.Users {
|
for i := range state.Users {
|
||||||
err = m.InsertUser(&state.Users[i], state.Id)
|
err = m.InsertUser(&state.Users[i], state.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ func (m FoundryStateModel) Insert(state *FoundryState) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertOptions(options *Options, stateId int) error {
|
func (m FoundryStateModel) InsertOptions(options *Options, stateId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO options (state_id, lang)
|
INSERT INTO options (state_id, lang)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2)
|
||||||
@@ -111,3 +112,195 @@ func (m FoundryStateModel) InsertOptions(options *Options, stateId int) error {
|
|||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&options.Id)
|
return m.DB.QueryRowContext(ctx, query, args...).Scan(&options.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) Get(id int64) (*FoundryState, error) {
|
||||||
|
if id < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, created_at, is_admin, is_setup, state_type
|
||||||
|
FROM foundry_state
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
var state FoundryState
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, id).Scan(
|
||||||
|
&state.Id,
|
||||||
|
&state.CreatedAt,
|
||||||
|
&state.IsAdmin,
|
||||||
|
&state.IsSetup,
|
||||||
|
&state.Type,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.Modules, err = m.GetModules(state.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
state.Systems, err = m.GetSystems(state.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
state.Worlds, err = m.GetWorlds(state.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
state.Users, err = m.GetUsers(state.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
options, err := m.GetOptions(state.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
state.Options = *options
|
||||||
|
|
||||||
|
return &state, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetOptions(idState int64) (*Options, error) {
|
||||||
|
if idState < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, lang
|
||||||
|
FROM options
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
var options Options
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, idState).Scan(
|
||||||
|
&options.Id,
|
||||||
|
&options.Language,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &options, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetIdByType(stateType StateType) (int64, error) {
|
||||||
|
if stateType < 0 {
|
||||||
|
return -1, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id
|
||||||
|
FROM foundry_state
|
||||||
|
WHERE state_type = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
var id int64
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, stateType).Scan(&id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return -1, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) Delete(id int64) error {
|
||||||
|
if id < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM foundry_state
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteAll() error {
|
||||||
|
query := `
|
||||||
|
DELETE FROM foundry_state`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteAllSeq() error {
|
||||||
|
query := `
|
||||||
|
DELETE FROM sqlite_sequence`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
Id int
|
Id int64
|
||||||
TextId string
|
TextId string
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
@@ -19,7 +21,7 @@ type Module struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
Id string
|
Id int64
|
||||||
Lang string
|
Lang string
|
||||||
Name string
|
Name string
|
||||||
Path string
|
Path string
|
||||||
@@ -31,7 +33,7 @@ func (modules Modules) GetById(id int) *Module {
|
|||||||
return &modules[id]
|
return &modules[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertModule(module *Module, stateId int) error {
|
func (m FoundryStateModel) InsertModule(module *Module, stateId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO modules (state_id, text_id, title, description, url, version, availability)
|
INSERT INTO modules (state_id, text_id, title, description, url, version, availability)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
@@ -48,16 +50,16 @@ func (m FoundryStateModel) InsertModule(module *Module, stateId int) error {
|
|||||||
}
|
}
|
||||||
for i := range module.Languages {
|
for i := range module.Languages {
|
||||||
err = m.InsertModuleLanguages(&module.Languages[i], module.Id)
|
err = m.InsertModuleLanguages(&module.Languages[i], module.Id)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m.InsertModuleCompatibility(&module.Compatibility, module.Id)
|
return m.InsertModuleCompatibility(&module.Compatibility, module.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertModuleCompatibility(compatibility *Compatibility, moduleId int) error {
|
func (m FoundryStateModel) InsertModuleCompatibility(compatibility *Compatibility, moduleId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO modules_compatibility (model_id, minumum, verified, maximum)
|
INSERT INTO modules_compatibility (module_id, minimum, verified, maximum)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
|
|
||||||
@@ -66,12 +68,16 @@ func (m FoundryStateModel) InsertModuleCompatibility(compatibility *Compatibilit
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertModuleLanguages(lang *Language, moduleId int) error {
|
func (m FoundryStateModel) InsertModuleLanguages(lang *Language, moduleId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO modules_compatibility (model_id, language, name, path)
|
INSERT INTO modules_languages (module_id, language, name, path)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
|
|
||||||
@@ -80,5 +86,205 @@ func (m FoundryStateModel) InsertModuleLanguages(lang *Language, moduleId int) e
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&lang.Id)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&lang.Id)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetModules(idState int64) (Modules, error) {
|
||||||
|
if idState < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, created_at, text_id, title, description, url, version, availability
|
||||||
|
FROM modules
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modules := make(Modules, 0, 1)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var module Module
|
||||||
|
err := rows.Scan(
|
||||||
|
&module.Id,
|
||||||
|
&module.CreatedAt,
|
||||||
|
&module.TextId,
|
||||||
|
&module.Title,
|
||||||
|
&module.Description,
|
||||||
|
&module.Url,
|
||||||
|
&module.Version,
|
||||||
|
&module.Availability,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
module.Languages, err = m.GetModuleLanguages(module.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
compatibility, err := m.GetModuleCompatibility(module.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
module.Compatibility = *compatibility
|
||||||
|
modules = append(modules, module)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return modules, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetModuleCompatibility(idModule int64) (*Compatibility, error) {
|
||||||
|
if idModule < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, minimum, verified, maximum
|
||||||
|
FROM modules_compatibility
|
||||||
|
WHERE module_id = $1`
|
||||||
|
|
||||||
|
var compatibility Compatibility
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, idModule).Scan(
|
||||||
|
&compatibility.Id,
|
||||||
|
&compatibility.Minimum,
|
||||||
|
&compatibility.Verified,
|
||||||
|
&compatibility.Maximum,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &compatibility, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetModuleLanguages(idModule int64) ([]Language, error) {
|
||||||
|
if idModule < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, language, name, path
|
||||||
|
FROM modules_languages
|
||||||
|
WHERE module_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idModule)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
languages := make([]Language, 0, 1)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var lang Language
|
||||||
|
err := rows.Scan(
|
||||||
|
&lang.Id,
|
||||||
|
&lang.Lang,
|
||||||
|
&lang.Name,
|
||||||
|
&lang.Path,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
languages = append(languages, lang)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return languages, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteModules(idState int64) error {
|
||||||
|
if idState < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM modules
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteModule(idModule int64) error {
|
||||||
|
if idModule < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM modules
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idModule)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type System struct {
|
type System struct {
|
||||||
Id int
|
Id int64
|
||||||
TextId string
|
TextId string
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
@@ -22,26 +24,27 @@ func (systems Systems) GetById(id int) *System {
|
|||||||
return &systems[id]
|
return &systems[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertSystem(system *System, stateId int) error {
|
func (m FoundryStateModel) InsertSystem(system *System, stateId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO systems (state_id, text_id, title, description, url, download)
|
INSERT INTO systems (state_id, text_id, title, description, url, download)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)`
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
RETURNING id, created_at`
|
||||||
|
|
||||||
args := []any{stateId, system.TextId, system.Title, system.Description, system.Url, system.Download}
|
args := []any{stateId, system.TextId, system.Title, system.Description, system.Url, system.Download}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&system.Id)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&system.Id, &system.CreatedAt)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return m.InsertModuleCompatibility(&system.Compatibility, system.Id)
|
return m.InsertSystemCompatibility(&system.Compatibility, system.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertSystenCompatibility(compatibility *Compatibility, systemId int) error {
|
func (m FoundryStateModel) InsertSystemCompatibility(compatibility *Compatibility, systemId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO systems_compatibility (system_id, minumum, verified, maximum)
|
INSERT INTO systems_compatibility (system_id, minimum, verified, maximum)
|
||||||
VALUES ($1, $2, $3, $4)`
|
VALUES ($1, $2, $3, $4)`
|
||||||
|
|
||||||
args := []any{systemId, compatibility.Minimum, compatibility.Verified, compatibility.Maximum}
|
args := []any{systemId, compatibility.Minimum, compatibility.Verified, compatibility.Maximum}
|
||||||
@@ -49,5 +52,153 @@ func (m FoundryStateModel) InsertSystenCompatibility(compatibility *Compatibilit
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetSystems(idState int64) (Systems, error) {
|
||||||
|
if idState < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, created_at, text_id, title, description, url, download
|
||||||
|
FROM systems
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
systems := make(Systems, 0, 1)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var system System
|
||||||
|
err := rows.Scan(
|
||||||
|
&system.Id,
|
||||||
|
&system.CreatedAt,
|
||||||
|
&system.TextId,
|
||||||
|
&system.Title,
|
||||||
|
&system.Description,
|
||||||
|
&system.Url,
|
||||||
|
&system.Download,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
compatibility, err := m.GetModuleCompatibility(system.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
system.Compatibility = *compatibility
|
||||||
|
systems = append(systems, system)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return systems, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetSystemCompatibility(idSystem int64) (*Compatibility, error) {
|
||||||
|
if idSystem < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, minimum, verified, maximum
|
||||||
|
FROM systems_compatibility
|
||||||
|
WHERE system_id = $1`
|
||||||
|
|
||||||
|
var compatibility Compatibility
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, idSystem).Scan(
|
||||||
|
&compatibility.Id,
|
||||||
|
&compatibility.Minimum,
|
||||||
|
&compatibility.Verified,
|
||||||
|
&compatibility.Maximum,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &compatibility, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteSystems(idState int64) error {
|
||||||
|
if idState < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM systems
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteSystem(idSystem int64) error {
|
||||||
|
if idSystem < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM systems
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idSystem)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
Role int
|
Role int
|
||||||
Character string
|
Character string
|
||||||
@@ -18,7 +20,7 @@ type User struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserStats struct {
|
type UserStats struct {
|
||||||
Id int
|
Id int64
|
||||||
CoreVersion string
|
CoreVersion string
|
||||||
SystemId string
|
SystemId string
|
||||||
SystemVersion string
|
SystemVersion string
|
||||||
@@ -33,7 +35,7 @@ func (users Users) GetById(id int) *User {
|
|||||||
return &users[id]
|
return &users[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertUser(user *User, stateId int) error {
|
func (m FoundryStateModel) InsertUser(user *User, stateId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO users (state_id, name, role, character, color, pronouns)
|
INSERT INTO users (state_id, name, role, character, color, pronouns)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
@@ -59,7 +61,7 @@ func (m FoundryStateModel) InsertUser(user *User, stateId int) error {
|
|||||||
return m.InsertUserStats(&user.Stats, user.Id)
|
return m.InsertUserStats(&user.Stats, user.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertUserHotbar(key string, value string, userId int) error {
|
func (m FoundryStateModel) InsertUserHotbar(key string, value string, userId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO users_hotbar (user_id, key, value)
|
INSERT INTO users_hotbar (user_id, key, value)
|
||||||
VALUES ($1, $2, $3)`
|
VALUES ($1, $2, $3)`
|
||||||
@@ -70,13 +72,13 @@ func (m FoundryStateModel) InsertUserHotbar(key string, value string, userId int
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
_, err := m.DB.ExecContext(ctx, query, args...)
|
_, err := m.DB.ExecContext(ctx, query, args...)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertUserStats(stats *UserStats, userId int) error {
|
func (m FoundryStateModel) InsertUserStats(stats *UserStats, userId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO users_stats (user_id, core_version, system_id, system_version, created_time, modified_time, last_modified_by)
|
INSERT INTO users_stats (user_id, core_version, system_id, system_version, created_time, modified_time, last_modified_by)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
@@ -89,3 +91,206 @@ func (m FoundryStateModel) InsertUserStats(stats *UserStats, userId int) error {
|
|||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&stats.Id)
|
return m.DB.QueryRowContext(ctx, query, args...).Scan(&stats.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetUsers(idState int64) (Users, error) {
|
||||||
|
if idState < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, created_at, name, role, character, color, pronouns
|
||||||
|
FROM users
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make(Users, 0, 1)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var user User
|
||||||
|
err := rows.Scan(
|
||||||
|
&user.Id,
|
||||||
|
&user.CreatedAt,
|
||||||
|
&user.Name,
|
||||||
|
&user.Role,
|
||||||
|
&user.Character,
|
||||||
|
&user.Color,
|
||||||
|
&user.Pronouns,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
user.Hotbar, err = m.GetUserHotbar(user.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
userState, err := m.GetUserStats(user.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Stats = *userState
|
||||||
|
users = append(users, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetUserHotbar(idUser int64) (map[string]string, error) {
|
||||||
|
if idUser < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT key, value
|
||||||
|
FROM users_hotbar
|
||||||
|
WHERE user_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idUser)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hotbar := make(map[string]string)
|
||||||
|
for rows.Next() {
|
||||||
|
var key string
|
||||||
|
var val string
|
||||||
|
|
||||||
|
err := rows.Scan(
|
||||||
|
&key,
|
||||||
|
&val,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hotbar[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hotbar, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetUserStats(idSystem int64) (*UserStats, error) {
|
||||||
|
if idSystem < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, core_version, system_id, system_version, created_time, modified_time, last_modified_by
|
||||||
|
FROM users_stats
|
||||||
|
WHERE user_id = $1`
|
||||||
|
|
||||||
|
var userStats UserStats
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, idSystem).Scan(
|
||||||
|
&userStats.Id,
|
||||||
|
&userStats.CoreVersion,
|
||||||
|
&userStats.SystemId,
|
||||||
|
&userStats.SystemVersion,
|
||||||
|
&userStats.CreatedTime,
|
||||||
|
&userStats.ModifiedTime,
|
||||||
|
&userStats.LastModifiedBy,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &userStats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteUsers(idState int64) error {
|
||||||
|
if idState < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM users
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteUser(idUser int64) error {
|
||||||
|
if idUser < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM users
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idUser)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type World struct {
|
type World struct {
|
||||||
Id int
|
Id int64
|
||||||
TextId string
|
TextId string
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
@@ -26,7 +28,7 @@ func (worlds Worlds) GetById(id int) *World {
|
|||||||
return &worlds[id]
|
return &worlds[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertWorld(world *World, stateId int) error {
|
func (m FoundryStateModel) InsertWorld(world *World, stateId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO worlds (state_id, text_id, title, description, system, core_version, system_version, playtime, next_session)
|
INSERT INTO worlds (state_id, text_id, title, description, system, core_version, system_version, playtime, next_session)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
@@ -38,15 +40,15 @@ func (m FoundryStateModel) InsertWorld(world *World, stateId int) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&world.Id, &world.CreatedAt)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&world.Id, &world.CreatedAt)
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return m.InsertWorldCompatibility(&world.Compatibility, world.Id)
|
return m.InsertWorldCompatibility(&world.Compatibility, world.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FoundryStateModel) InsertWorldCompatibility(compatibility *Compatibility, worldId int) error {
|
func (m FoundryStateModel) InsertWorldCompatibility(compatibility *Compatibility, worldId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO worlds_compatibility (world_id, minumum, verified, maximum)
|
INSERT INTO worlds_compatibility (world_id, minimum, verified, maximum)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
|
|
||||||
@@ -55,7 +57,158 @@ func (m FoundryStateModel) InsertWorldCompatibility(compatibility *Compatibility
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
return m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetWorlds(idState int64) (Worlds, error) {
|
||||||
|
if idState < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, created_at, text_id, title, description, system, core_version, system_version, playtime, next_session
|
||||||
|
FROM worlds
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
rows, err := m.DB.QueryContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
worlds := make(Worlds, 0, 1)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var world World
|
||||||
|
err := rows.Scan(
|
||||||
|
&world.Id,
|
||||||
|
&world.CreatedAt,
|
||||||
|
&world.TextId,
|
||||||
|
&world.Title,
|
||||||
|
&world.Description,
|
||||||
|
&world.System,
|
||||||
|
&world.CoreVersion,
|
||||||
|
&world.SystemVersion,
|
||||||
|
&world.PlayTime,
|
||||||
|
&world.NextSession,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
compatibility, err := m.GetWorldsCompatibility(world.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
world.Compatibility = *compatibility
|
||||||
|
worlds = append(worlds, world)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return worlds, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) GetWorldsCompatibility(idWorld int64) (*Compatibility, error) {
|
||||||
|
if idWorld < 1 {
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, minimum, verified, maximum
|
||||||
|
FROM worlds_compatibility
|
||||||
|
WHERE world_id = $1`
|
||||||
|
|
||||||
|
var compatibility Compatibility
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := m.DB.QueryRowContext(ctx, query, idWorld).Scan(
|
||||||
|
&compatibility.Id,
|
||||||
|
&compatibility.Minimum,
|
||||||
|
&compatibility.Verified,
|
||||||
|
&compatibility.Maximum,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrorRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &compatibility, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteWorlds(idState int64) error {
|
||||||
|
if idState < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM worlds
|
||||||
|
WHERE state_id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m FoundryStateModel) DeleteWorld(idWorld int64) error {
|
||||||
|
if idWorld < 1 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
DELETE FROM worlds
|
||||||
|
WHERE id = $1`
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := m.DB.ExecContext(ctx, query, idWorld)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return ErrorRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (worlds Worlds) GetSessionTime(worldName string) (*time.Time, error) {
|
// func (worlds Worlds) GetSessionTime(worldName string) (*time.Time, error) {
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ func (state *FoundryState) GetWorlds() db.Worlds {
|
|||||||
}
|
}
|
||||||
worldsCopy = append(worldsCopy, worldCopy)
|
worldsCopy = append(worldsCopy, worldCopy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if state.World != nil {
|
||||||
|
worldsCopy = append(worldsCopy, *state.GetWorld())
|
||||||
|
}
|
||||||
return worldsCopy
|
return worldsCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,3 @@ type Users []User
|
|||||||
func (users Users) GetById(id int) *User {
|
func (users Users) GetById(id int) *User {
|
||||||
return &users[id]
|
return &users[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *FoundryState) GetUsers() *Users {
|
|
||||||
return &state.Users
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -31,6 +33,18 @@ var WsTypeData = map[string]string{
|
|||||||
UpdatePath: "getUpdateData",
|
UpdatePath: "getUpdateData",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PathToSetupState = map[string]db.StateType{
|
||||||
|
SetupPath: db.SetupState,
|
||||||
|
// AuthPath: db.AuthState,
|
||||||
|
// UpdatePath: db.UpdateState,
|
||||||
|
// LicensePath: db.LicenseState,
|
||||||
|
}
|
||||||
|
|
||||||
|
var PathToWorldState = map[string]db.StateType{
|
||||||
|
JoinPath: db.JoinState,
|
||||||
|
PlayersPath: db.PlayersState,
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Host string
|
Host string
|
||||||
Password string
|
Password string
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package foundry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -9,6 +10,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
db_model "gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models/db"
|
||||||
|
json_model "gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models/json"
|
||||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/requests"
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/requests"
|
||||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@@ -21,6 +24,33 @@ const (
|
|||||||
ReaderCode = TransportCode(1)
|
ReaderCode = TransportCode(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RespSessionData = "0"
|
||||||
|
RespPingCode = "2"
|
||||||
|
RespSessionId = "40"
|
||||||
|
RespCreateSessionCode = "42"
|
||||||
|
RespDataCode = "43"
|
||||||
|
|
||||||
|
ReqPongCode = "3"
|
||||||
|
ReqCreateSessionCode = "40"
|
||||||
|
ReqDataCode = "42"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RequestCodes = []string{
|
||||||
|
RespSessionData,
|
||||||
|
RespPingCode,
|
||||||
|
RespSessionId,
|
||||||
|
RespCreateSessionCode,
|
||||||
|
RespDataCode,
|
||||||
|
}
|
||||||
|
|
||||||
|
var CodesRespToReq = map[string]string{
|
||||||
|
RespSessionData: ReqCreateSessionCode,
|
||||||
|
RespPingCode: ReqPongCode,
|
||||||
|
RespCreateSessionCode: ReqDataCode,
|
||||||
|
//ReqDataCode: RespCreateSessionCode,
|
||||||
|
}
|
||||||
|
|
||||||
type webSocketUtil struct {
|
type webSocketUtil struct {
|
||||||
wsConn *websocket.Conn
|
wsConn *websocket.Conn
|
||||||
currWsId int
|
currWsId int
|
||||||
@@ -30,6 +60,7 @@ type webSocketUtil struct {
|
|||||||
msgMap map[int](chan []byte)
|
msgMap map[int](chan []byte)
|
||||||
chanMutex sync.Mutex
|
chanMutex sync.Mutex
|
||||||
channels types.Channels
|
channels types.Channels
|
||||||
|
models db_model.Models
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebSocketUtil() *webSocketUtil {
|
func NewWebSocketUtil() *webSocketUtil {
|
||||||
@@ -193,6 +224,7 @@ func (ws *webSocketUtil) ServeWebSocket() {
|
|||||||
}
|
}
|
||||||
case RespCreateSessionCode:
|
case RespCreateSessionCode:
|
||||||
ws.isReadReady = true
|
ws.isReadReady = true
|
||||||
|
go ws.GetInitialData()
|
||||||
case RespDataCode:
|
case RespDataCode:
|
||||||
ws.msgMap[message.Id] = make(chan []byte, 1)
|
ws.msgMap[message.Id] = make(chan []byte, 1)
|
||||||
ws.msgMap[message.Id] <- []byte(message.MsgJson)
|
ws.msgMap[message.Id] <- []byte(message.MsgJson)
|
||||||
@@ -209,6 +241,56 @@ func (ws *webSocketUtil) IsReadReady() bool {
|
|||||||
return ws.isReadReady
|
return ws.isReadReady
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ws *webSocketUtil) GetJsonData(stateType string) ([]byte, error) {
|
||||||
|
msg := ws.CreateWSMessageByPage(stateType)
|
||||||
|
|
||||||
|
return ws.HandleWebsocketRequest(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ws *webSocketUtil) InsertJsonDataToDB(statePath string) error {
|
||||||
|
_, ok1 := requests.PathToSetupState[statePath]
|
||||||
|
_, ok2 := requests.PathToWorldState[statePath]
|
||||||
|
if !ok1 && !ok2 {
|
||||||
|
return ErrorStateTypeNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
msgJson, err := ws.GetJsonData(statePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
foundryStateJson, err := json_model.ParseSetupModel(msgJson)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
foundryStateDb := foundryStateJson.GetFoundryStateDB(requests.PathToSetupState[statePath])
|
||||||
|
err = ws.models.FoundryState.Insert(foundryStateDb)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ws *webSocketUtil) GetInitialData() {
|
||||||
|
ws.models.FoundryState.DeleteAll()
|
||||||
|
ws.models.FoundryState.DeleteAllSeq()
|
||||||
|
for k := range requests.PathToSetupState {
|
||||||
|
err := ws.InsertJsonDataToDB(k)
|
||||||
|
if err != nil {
|
||||||
|
ws.channels.Err() <- &FoundryError{Type: WriterCode, Err: err}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for k := range requests.PathToWorldState {
|
||||||
|
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ws *webSocketUtil) CreateNewDataModels(db *sql.DB) {
|
||||||
|
ws.models = db_model.NewModels(db)
|
||||||
|
}
|
||||||
|
|
||||||
func (ws *webSocketUtil) CreateWSMessageByPage(page string) *types.WsMessage {
|
func (ws *webSocketUtil) CreateWSMessageByPage(page string) *types.WsMessage {
|
||||||
msgToSend := &types.WsMessage{Code: CodesRespToReq[RespCreateSessionCode], Id: ws.currWsId, MsgJson: fmt.Sprintf("[\"%s\"]", requests.WsTypeData[page])}
|
msgToSend := &types.WsMessage{Code: CodesRespToReq[RespCreateSessionCode], Id: ws.currWsId, MsgJson: fmt.Sprintf("[\"%s\"]", requests.WsTypeData[page])}
|
||||||
ws.currWsId++
|
ws.currWsId++
|
||||||
|
|||||||
Reference in New Issue
Block a user