54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type System struct {
|
|
Id int
|
|
TextId string
|
|
Title string
|
|
Description string
|
|
Url string
|
|
Download string
|
|
CreatedAt time.Time
|
|
Compatibility Compatibility
|
|
}
|
|
|
|
type Systems []System
|
|
|
|
func (systems Systems) GetById(id int) *System {
|
|
return &systems[id]
|
|
}
|
|
|
|
func (m FoundryStateModel) InsertSystem(system *System, stateId int) error {
|
|
query := `
|
|
INSERT INTO systems (state_id, text_id, title, description, url, download)
|
|
VALUES ($1, $2, $3, $4, $5, $6)`
|
|
|
|
args := []any{stateId, system.TextId, system.Title, system.Description, system.Url, system.Download}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
|
|
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&system.Id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return m.InsertModuleCompatibility(&system.Compatibility, system.Id)
|
|
}
|
|
|
|
func (m FoundryStateModel) InsertSystenCompatibility(compatibility *Compatibility, systemId int) error {
|
|
query := `
|
|
INSERT INTO systems_compatibility (system_id, minumum, verified, maximum)
|
|
VALUES ($1, $2, $3, $4)`
|
|
|
|
args := []any{systemId, compatibility.Minimum, compatibility.Verified, compatibility.Maximum}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
|
|
return m.DB.QueryRowContext(ctx, query, args...).Scan(&compatibility.Id)
|
|
}
|