mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
added folder for models and corresponding source files
This commit is contained in:
parent
7e044cdc82
commit
24a4eb1718
8 changed files with 201 additions and 0 deletions
78
common/database.go
Normal file
78
common/database.go
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
//"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
//DB_USER = "postgres"
|
||||||
|
//DB_PASSWORD = "postgres"
|
||||||
|
//DB_NAME = "test"
|
||||||
|
DB_USER = "odiseas"
|
||||||
|
DB_PASSWORD = "toumpacity"
|
||||||
|
DB_NAME = "mytestdb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
|
||||||
|
DB_USER, DB_PASSWORD, DB_NAME)
|
||||||
|
db, err := sql.Open("postgres", dbinfo)
|
||||||
|
checkErr(err)
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
//fmt.Println("# Inserting values")
|
||||||
|
|
||||||
|
//var lastInsertId int
|
||||||
|
//err = db.QueryRow("INSERT INTO userinfo(username,departname,created) VALUES($1,$2,$3) returning uid;", "astaxie", "研发部门", "2012-12-09").Scan(&lastInsertId)
|
||||||
|
//checkErr(err)
|
||||||
|
//fmt.Println("last inserted id =", lastInsertId)
|
||||||
|
|
||||||
|
//fmt.Println("# Updating")
|
||||||
|
//stmt, err := db.Prepare("update userinfo set username=$1 where uid=$2")
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//res, err := stmt.Exec("astaxieupdate", lastInsertId)
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//affect, err := res.RowsAffected()
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//fmt.Println(affect, "rows changed")
|
||||||
|
|
||||||
|
//fmt.Println("# Querying")
|
||||||
|
//rows, err := db.Query("SELECT * FROM userinfo")
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//for rows.Next() {
|
||||||
|
//var uid int
|
||||||
|
//var username string
|
||||||
|
//var department string
|
||||||
|
//var created time.Time
|
||||||
|
//err = rows.Scan(&uid, &username, &department, &created)
|
||||||
|
//checkErr(err)
|
||||||
|
//fmt.Println("uid | username | department | created ")
|
||||||
|
//fmt.Printf("%3v | %8v | %6v | %6v\n", uid, username, department, created)
|
||||||
|
//}
|
||||||
|
|
||||||
|
//fmt.Println("# Deleting")
|
||||||
|
//stmt, err = db.Prepare("delete from userinfo where uid=$1")
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//res, err = stmt.Exec(lastInsertId)
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//affect, err = res.RowsAffected()
|
||||||
|
//checkErr(err)
|
||||||
|
|
||||||
|
//fmt.Println(affect, "rows changed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkErr(err error) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Something went wrong!!")
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
15
file/model.go
Normal file
15
file/model.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type File struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
Path string
|
||||||
|
Type string
|
||||||
|
Size uint
|
||||||
|
Dimmensions string
|
||||||
|
FileUser User
|
||||||
|
}
|
17
project/model.go
Normal file
17
project/model.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package project
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rwth-aachen.de/stemavros/villasweb-backend-go/visualization"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
// XXX: We don't need also User and Simulation???
|
||||||
|
)
|
||||||
|
|
||||||
|
type Project struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
UserProject User // XXX: association?
|
||||||
|
Visualizations []Visualization // TODO: association & foreign key
|
||||||
|
SimulationProject Simulation // XXX: association?n
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: execute before project.delete()
|
17
simulation/model.go
Normal file
17
simulation/model.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package simulation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rwth-aachen.de/stemavros/villasweb-backend-go/visualization"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
// XXX: What about other models??
|
||||||
|
)
|
||||||
|
|
||||||
|
type Simulation struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
Running bool `gorm:"default:false"`
|
||||||
|
Models []SimulationModel // TODO: association & foreign key
|
||||||
|
Projects []Project // TODO: association & foreign key
|
||||||
|
User []Users // TODO: association & foreign key
|
||||||
|
StartParameters []string // TODO: Mixed Type
|
||||||
|
}
|
18
simulationModel/model.go
Normal file
18
simulationModel/model.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package simulationModel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
// XXX: other models
|
||||||
|
)
|
||||||
|
|
||||||
|
type SimulationModel struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
OutputLength int `gorm:"default:1"`
|
||||||
|
InputLength int `gorm:"default:1"`
|
||||||
|
OutputMapping []string // TODO: Mixed Type
|
||||||
|
InputMapping []string // TODO: Mixed Type
|
||||||
|
StartParameters []string // TODO: Mixed Type
|
||||||
|
ModelSimulation Simulation // TODO: association & foreign key
|
||||||
|
ModelSimulator Simulator // TODO: association & foreign key
|
||||||
|
}
|
16
simulator/model.go
Normal file
16
simulator/model.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package simulator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Simulator struct {
|
||||||
|
gorm.Model
|
||||||
|
UUID string
|
||||||
|
Host string `gorm:"default:"`
|
||||||
|
Model string `gorm:"default:"`
|
||||||
|
Uptime int `gorm:"default:0"`
|
||||||
|
State string `gorm:"default:"`
|
||||||
|
Properties []string
|
||||||
|
RawProperties []string
|
||||||
|
}
|
26
user/model.go
Normal file
26
user/model.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rwth-aachen.de/stemavros/villasweb-backend-go/file"
|
||||||
|
"git.rwth-aachen.de/stemavros/villasweb-backend-go/project"
|
||||||
|
"git.rwth-aachen.de/stemavros/villasweb-backend-go/simulation"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
// TODO: we need also bcrypt
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
gorm.Model
|
||||||
|
Username string `gorm:"unique"`
|
||||||
|
Password string
|
||||||
|
Mail string `gorm:"default:"`
|
||||||
|
Role string `gorm:"default:user"`
|
||||||
|
Projects []Project // TODO: association & foreign key
|
||||||
|
Simulations []Simulaion // TODO: association & foreign key
|
||||||
|
Files []File // TODO: association & foreign key
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: callback for verifying password
|
||||||
|
|
||||||
|
// TODO: execute before each user.save()
|
||||||
|
|
||||||
|
// TODO: execute before each user.delete()
|
14
visualization/model.go
Normal file
14
visualization/model.go
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package visualization
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Visualization struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
VisualizationProject Project
|
||||||
|
Widgets string
|
||||||
|
Grid int `gorm:"default:15"`
|
||||||
|
VisualizationUser User
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue