Add Application and ParameterSchema models with CRUD store. Includes 10 store tests and ParamType constants. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
77 lines
3.1 KiB
Go
77 lines
3.1 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// Parameter type constants for ParameterSchema.Type.
|
|
const (
|
|
ParamTypeString = "string"
|
|
ParamTypeInteger = "integer"
|
|
ParamTypeEnum = "enum"
|
|
ParamTypeFile = "file"
|
|
ParamTypeDirectory = "directory"
|
|
ParamTypeBoolean = "boolean"
|
|
)
|
|
|
|
// Application represents a parameterized application definition for HPC job submission.
|
|
type Application struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
Name string `gorm:"uniqueIndex;size:255;not null" json:"name"`
|
|
Description string `gorm:"type:text" json:"description,omitempty"`
|
|
Icon string `gorm:"size:255" json:"icon,omitempty"`
|
|
Category string `gorm:"size:255" json:"category,omitempty"`
|
|
ScriptTemplate string `gorm:"type:text;not null" json:"script_template"`
|
|
Parameters json.RawMessage `gorm:"type:json" json:"parameters,omitempty"`
|
|
Scope string `gorm:"size:50;default:'system'" json:"scope,omitempty"`
|
|
CreatedBy int64 `json:"created_by,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (Application) TableName() string {
|
|
return "applications"
|
|
}
|
|
|
|
// ParameterSchema defines a single parameter in an application's form schema.
|
|
type ParameterSchema struct {
|
|
Name string `json:"name"`
|
|
Label string `json:"label,omitempty"`
|
|
Type string `json:"type"`
|
|
Required bool `json:"required,omitempty"`
|
|
Default string `json:"default,omitempty"`
|
|
Options []string `json:"options,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
|
|
// CreateApplicationRequest is the DTO for creating a new application.
|
|
type CreateApplicationRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Description string `json:"description,omitempty"`
|
|
Icon string `json:"icon,omitempty"`
|
|
Category string `json:"category,omitempty"`
|
|
ScriptTemplate string `json:"script_template" binding:"required"`
|
|
Parameters json.RawMessage `json:"parameters,omitempty"`
|
|
Scope string `json:"scope,omitempty"`
|
|
}
|
|
|
|
// UpdateApplicationRequest is the DTO for updating an existing application.
|
|
// All fields are optional. Parameters uses *json.RawMessage to distinguish
|
|
// between "not provided" (nil) and "set to empty" (non-nil).
|
|
type UpdateApplicationRequest struct {
|
|
Name *string `json:"name,omitempty"`
|
|
Description *string `json:"description,omitempty"`
|
|
Icon *string `json:"icon,omitempty"`
|
|
Category *string `json:"category,omitempty"`
|
|
ScriptTemplate *string `json:"script_template,omitempty"`
|
|
Parameters *json.RawMessage `json:"parameters,omitempty"`
|
|
Scope *string `json:"scope,omitempty"`
|
|
}
|
|
|
|
// ApplicationSubmitRequest is the DTO for submitting a job from an application.
|
|
// ApplicationID is parsed from the URL :id parameter, not included in the body.
|
|
type ApplicationSubmitRequest struct {
|
|
Values map[string]string `json:"values" binding:"required"`
|
|
}
|