Add frontend #1
@@ -3,11 +3,12 @@ package models
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
type GitServer struct {
|
type GitServer struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
BaseUrl string `json:"baseUrl"`
|
BaseUrl string `json:"baseUrl"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
AuthToken string `json:"auth_token"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,21 +21,6 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
|
|||||||
userRepository := database.NewSQLiteUserRepository(db)
|
userRepository := database.NewSQLiteUserRepository(db)
|
||||||
gitServerRepository := database.NewSQLiteGitServerRepository(db)
|
gitServerRepository := database.NewSQLiteGitServerRepository(db)
|
||||||
|
|
||||||
// Seed default git servers if none exist
|
|
||||||
if gsList, err := gitServerRepository.ListGitServers(); err != nil {
|
|
||||||
log.Printf("Warning checking gitservers: %v", err)
|
|
||||||
} else if len(gsList) == 0 {
|
|
||||||
defaults := []models.GitServer{
|
|
||||||
{Name: "GitHub", Protocol: "https", BaseUrl: "github.com", Type: "github"},
|
|
||||||
{Name: "GitLab", Protocol: "https", BaseUrl: "gitlab.com", Type: "gitlab"},
|
|
||||||
}
|
|
||||||
for _, d := range defaults {
|
|
||||||
if err := gitServerRepository.CreateGitServer(&d); err != nil {
|
|
||||||
log.Printf("Warning creating default gitserver %s: %v", d.Name, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
siteHandler := handlers.NewSiteHandler(siteRepository)
|
siteHandler := handlers.NewSiteHandler(siteRepository)
|
||||||
deploySiteHandler := handlers.NewDeploySiteHandler(envCfg, siteRepository, deploymentRepository)
|
deploySiteHandler := handlers.NewDeploySiteHandler(envCfg, siteRepository, deploymentRepository)
|
||||||
userHandler := handlers.NewUserHandler(userRepository)
|
userHandler := handlers.NewUserHandler(userRepository)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func NewSQLiteGitServerRepository(db *sql.DB) *SQLiteGitServerRepository {
|
|||||||
var _ repository.GitServerRepository = (*SQLiteGitServerRepository)(nil)
|
var _ repository.GitServerRepository = (*SQLiteGitServerRepository)(nil)
|
||||||
|
|
||||||
func (r *SQLiteGitServerRepository) ListGitServers() ([]models.GitServer, error) {
|
func (r *SQLiteGitServerRepository) ListGitServers() ([]models.GitServer, error) {
|
||||||
rows, err := r.db.Query(`SELECT id, name, protocol, base_url, type, created_at FROM gitservers`)
|
rows, err := r.db.Query(`SELECT id, name, protocol, base_url, type, auth_token, created_at FROM gitservers`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("list gitservers: %w", err)
|
return nil, fmt.Errorf("list gitservers: %w", err)
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func (r *SQLiteGitServerRepository) ListGitServers() ([]models.GitServer, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *SQLiteGitServerRepository) GetGitServer(id string) (*models.GitServer, error) {
|
func (r *SQLiteGitServerRepository) GetGitServer(id string) (*models.GitServer, error) {
|
||||||
row := r.db.QueryRow(`SELECT id, name, protocol, base_url, type, created_at FROM gitservers WHERE id = ?`, id)
|
row := r.db.QueryRow(`SELECT id, name, protocol, base_url, type, auth_token, created_at FROM gitservers WHERE id = ?`, id)
|
||||||
return scanGitServer(row)
|
return scanGitServer(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,8 +55,8 @@ func (r *SQLiteGitServerRepository) CreateGitServer(gs *models.GitServer) error
|
|||||||
|
|
||||||
gs.ID = uuid.NewString()
|
gs.ID = uuid.NewString()
|
||||||
|
|
||||||
_, err = tx.Exec(`INSERT INTO gitservers (id, name, protocol, base_url, type) VALUES (?, ?, ?, ?, ?)`,
|
_, err = tx.Exec(`INSERT INTO gitservers (id, name, protocol, base_url, type, auth_token) VALUES (?, ?, ?, ?, ?, ?)`,
|
||||||
gs.ID, gs.Name, gs.Protocol, gs.BaseUrl, gs.Type)
|
gs.ID, gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.AuthToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if isSQLiteUniqueConstraintError(err) {
|
if isSQLiteUniqueConstraintError(err) {
|
||||||
return fmt.Errorf("create gitserver insert: %w", repository.ErrGitServerAlreadyExists)
|
return fmt.Errorf("create gitserver insert: %w", repository.ErrGitServerAlreadyExists)
|
||||||
@@ -74,8 +74,8 @@ func (r *SQLiteGitServerRepository) UpdateGitServer(gs *models.GitServer) error
|
|||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
_, err = tx.Exec(`UPDATE gitservers SET name = ?, protocol = ?, base_url = ?, type = ? WHERE id = ?`,
|
_, err = tx.Exec(`UPDATE gitservers SET name = ?, protocol = ?, base_url = ?, type = ?, auth_token = ? WHERE id = ?`,
|
||||||
gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.ID)
|
gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.AuthToken, gs.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if isSQLiteUniqueConstraintError(err) {
|
if isSQLiteUniqueConstraintError(err) {
|
||||||
return fmt.Errorf("update gitserver: %w", repository.ErrGitServerAlreadyExists)
|
return fmt.Errorf("update gitserver: %w", repository.ErrGitServerAlreadyExists)
|
||||||
@@ -96,7 +96,7 @@ func (r *SQLiteGitServerRepository) DeleteGitServer(id string) error {
|
|||||||
|
|
||||||
func scanGitServer(s scanner) (*models.GitServer, error) {
|
func scanGitServer(s scanner) (*models.GitServer, error) {
|
||||||
g := new(models.GitServer)
|
g := new(models.GitServer)
|
||||||
err := s.Scan(&g.ID, &g.Name, &g.Protocol, &g.BaseUrl, &g.Type, &g.CreatedAt)
|
err := s.Scan(&g.ID, &g.Name, &g.Protocol, &g.BaseUrl, &g.Type, &g.AuthToken, &g.CreatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ CREATE TABLE IF NOT EXISTS gitservers (
|
|||||||
protocol TEXT NOT NULL,
|
protocol TEXT NOT NULL,
|
||||||
base_url TEXT NOT NULL,
|
base_url TEXT NOT NULL,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
|
auth_token TEXT,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
`)
|
`)
|
||||||
|
|||||||
Reference in New Issue
Block a user