2016-04-02 14:40:07 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2016-05-24 11:55:48 +02:00
|
|
|
database "github.com/ansible-semaphore/semaphore/db"
|
2016-04-02 14:40:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Project struct {
|
2016-04-07 14:49:34 +02:00
|
|
|
ID int `db:"id" json:"id"`
|
|
|
|
Name string `db:"name" json:"name" binding:"required"`
|
|
|
|
Created time.Time `db:"created" json:"created"`
|
2017-03-10 01:12:55 +01:00
|
|
|
Alert bool `db:"alert" json:"alert"`
|
2016-04-02 14:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (project *Project) CreateProject() error {
|
2016-06-02 20:26:51 +02:00
|
|
|
project.Created = time.Now()
|
|
|
|
|
|
|
|
res, err := database.Mysql.Exec("insert into project set name=?, created=?", project.Name, project.Created)
|
2016-04-02 14:40:07 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
projectID, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
project.ID = int(projectID)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|