add db delete queries, fix module_id
This commit is contained in:
@@ -230,3 +230,31 @@ func (m FoundryStateModel) GetIdByType(stateType StateType) (int64, error) {
|
|||||||
|
|
||||||
return id, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (m FoundryStateModel) InsertModule(module *Module, stateId int64) error {
|
|||||||
|
|
||||||
func (m FoundryStateModel) InsertModuleCompatibility(compatibility *Compatibility, moduleId int64) 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, minumum, verified, maximum)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ func (m FoundryStateModel) InsertModuleCompatibility(compatibility *Compatibilit
|
|||||||
|
|
||||||
func (m FoundryStateModel) InsertModuleLanguages(lang *Language, moduleId int64) error {
|
func (m FoundryStateModel) InsertModuleLanguages(lang *Language, moduleId int64) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO modules_compatibility (model_id, language, name, path)
|
INSERT INTO modules_compatibility (module_id, language, name, path)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
|
|
||||||
@@ -224,3 +224,59 @@ func (m FoundryStateModel) GetModuleLanguages(idModule int64) ([]Language, error
|
|||||||
|
|
||||||
return languages, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -141,3 +141,59 @@ func (m FoundryStateModel) GetSystemCompatibility(idSystem int64) (*Compatibilit
|
|||||||
|
|
||||||
return &compatibility, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -238,3 +238,59 @@ func (m FoundryStateModel) GetUserStats(idSystem int64) (*UserStats, error) {
|
|||||||
|
|
||||||
return &userStats, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -151,6 +151,62 @@ func (m FoundryStateModel) GetWorldsCompatibility(idWorld int64) (*Compatibility
|
|||||||
return &compatibility, nil
|
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) {
|
||||||
// if worldName == "" && len(worlds) != 1 {
|
// if worldName == "" && len(worlds) != 1 {
|
||||||
// return nil, ErrorSetupNotFound
|
// return nil, ErrorSetupNotFound
|
||||||
|
|||||||
Reference in New Issue
Block a user