2020-12-01 20:06:49 +01:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2020-12-03 14:51:15 +01:00
|
|
|
"errors"
|
2020-12-04 23:22:05 +01:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2020-12-01 20:06:49 +01:00
|
|
|
"github.com/go-gorp/gorp/v3"
|
2020-12-04 23:22:05 +01:00
|
|
|
"time"
|
2020-12-01 20:06:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-12-07 13:13:59 +01:00
|
|
|
|
2020-12-04 23:22:05 +01:00
|
|
|
const databaseTimeFormat = "2006-01-02T15:04:05:99Z"
|
|
|
|
|
|
|
|
// GetParsedTime returns the timestamp as it will retrieved from the database
|
|
|
|
// This allows us to create timestamp consistency on return values from create requests
|
|
|
|
func GetParsedTime(t time.Time) time.Time {
|
|
|
|
parsedTime, err := time.Parse(databaseTimeFormat, t.Format(databaseTimeFormat))
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
return parsedTime
|
|
|
|
}
|
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
type RetrieveQueryParams struct {
|
|
|
|
Offset int
|
|
|
|
Count int
|
|
|
|
SortBy string
|
|
|
|
SortInverted bool
|
|
|
|
}
|
|
|
|
|
2020-12-03 14:51:15 +01:00
|
|
|
var ErrNotFound = errors.New("sql: no rows in result set")
|
2020-12-04 17:29:37 +01:00
|
|
|
var ErrInvalidOperation = errors.New("sql: no rows in result set")
|
2020-12-01 20:06:49 +01:00
|
|
|
|
|
|
|
type Store interface {
|
|
|
|
Connect() error
|
|
|
|
Close() error
|
|
|
|
Migrate() error
|
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
GetEnvironment(projectID int, environmentID int) (Environment, error)
|
|
|
|
GetEnvironments(projectID int, params RetrieveQueryParams) ([]Environment, error)
|
|
|
|
UpdateEnvironment(env Environment) error
|
|
|
|
CreateEnvironment(env Environment) (Environment, error)
|
2020-12-04 17:29:37 +01:00
|
|
|
DeleteEnvironment(projectID int, templateID int) error
|
|
|
|
DeleteEnvironmentSoft(projectID int, templateID int) error
|
2020-12-03 14:51:15 +01:00
|
|
|
|
2020-12-07 13:13:59 +01:00
|
|
|
GetInventory(projectID int, inventoryID int) (Inventory, error)
|
|
|
|
GetInventories(projectID int, params RetrieveQueryParams) ([]Inventory, error)
|
|
|
|
UpdateInventory(inventory Inventory) error
|
|
|
|
CreateInventory(inventory Inventory) (Inventory, error)
|
|
|
|
DeleteInventory(projectID int, templateID int) error
|
|
|
|
DeleteInventorySoft(projectID int, templateID int) error
|
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
GetUsers(params RetrieveQueryParams) ([]User, error)
|
|
|
|
CreateUser(user User) (User, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
DeleteUser(userID int) error
|
2020-12-04 23:41:26 +01:00
|
|
|
UpdateUser(user User) error
|
2020-12-01 20:06:49 +01:00
|
|
|
SetUserPassword(userID int, password string) error
|
2020-12-04 23:41:26 +01:00
|
|
|
GetUser(userID int) (User, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
CreateProject(project Project) (Project, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
//DeleteProject(projectId int) error
|
|
|
|
//UpdateProject(project Project) error
|
|
|
|
//GetProjectById(projectId int) (Project, error)
|
|
|
|
//GetProjects(userId int) ([]Project, error)
|
|
|
|
//
|
2020-12-03 14:51:15 +01:00
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
GetTemplates(projectID int, params RetrieveQueryParams) ([]Template, error)
|
|
|
|
CreateTemplate(template Template) (Template, error)
|
|
|
|
UpdateTemplate(template Template) error
|
|
|
|
GetTemplate(projectID int, templateID int) (Template, error)
|
2020-12-03 14:51:15 +01:00
|
|
|
DeleteTemplate(projectID int, templateID int) error
|
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
CreateProjectUser(projectUser ProjectUser) (ProjectUser, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
DeleteProjectUser(projectID, userID int) error
|
2020-12-03 14:51:15 +01:00
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
CreateEvent(event Event) (Event, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
GetAPITokens(userID int) ([]APIToken, error)
|
|
|
|
CreateAPIToken(token APIToken) (APIToken, error)
|
|
|
|
GetAPIToken(tokenID string) (APIToken, error)
|
2020-12-03 14:51:15 +01:00
|
|
|
ExpireAPIToken(userID int, tokenID string) error
|
|
|
|
|
2020-12-04 23:41:26 +01:00
|
|
|
GetSession(userID int, sessionID int) (Session, error)
|
2020-12-03 14:51:15 +01:00
|
|
|
ExpireSession(userID int, sessionID int) error
|
|
|
|
TouchSession(userID int, sessionID int) error
|
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
Sql() *gorp.DbMap
|
|
|
|
}
|