Semaphore/models/Project.go

32 lines
604 B
Go
Raw Normal View History

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 {
ID int `db:"id" json:"id"`
Name string `db:"name" json:"name" binding:"required"`
Created time.Time `db:"created" json:"created"`
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
}