Add Projects #13
38
api/v1/projects.go
Normal file
38
api/v1/projects.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
projects "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/projects/v1"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewProjectsServer() *ProjectsServer {
|
||||
return &ProjectsServer{}
|
||||
}
|
||||
|
||||
// var _ projects.ProjectsServiceServer = (*ProjectsServer)(nil)
|
||||
|
||||
type ProjectsServer struct {
|
||||
projects.UnimplementedProjectsServiceServer
|
||||
}
|
||||
|
||||
// CreateProject implements [v1.ProjectsServiceServer].
|
||||
func (p *ProjectsServer) CreateProject(context.Context, *projects.CreateProjectRequest) (*projects.CreateProjectResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetProject implements [v1.ProjectsServiceServer].
|
||||
func (p *ProjectsServer) GetProject(context.Context, *projects.GetProjectRequest) (*projects.GetProjectResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// ListProjects implements [v1.ProjectsServiceServer].
|
||||
func (p *ProjectsServer) ListProjects(*projects.ListProjectsRequest, grpc.ServerStreamingServer[projects.ListProjectsResponse]) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// UpdateProject implements [v1.ProjectsServiceServer].
|
||||
func (p *ProjectsServer) UpdateProject(context.Context, *projects.UpdateProjectRequest) (*projects.UpdateProjectResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
@@ -72,6 +72,8 @@ func (a *PublicAccountService) SignUp(ctx context.Context, in *accounts.SignUpRe
|
||||
data := &controllers.AccountData{
|
||||
Password: in.GetPassword(),
|
||||
Email: in.GetEmail(),
|
||||
Name: in.PersonalData.GetName(),
|
||||
Surname: in.PersonalData.GetSurname(),
|
||||
}
|
||||
id, err := a.accountsCtrl.Create(ctx, data)
|
||||
if err != nil {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -43,7 +43,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260517200845-22f1b32dfad9
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260518175130-4b27db42e21e
|
||||
github.com/golang/protobuf v1.5.4
|
||||
golang.org/x/net v0.51.0 // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
cloud.google.com/go v0.121.6 h1:waZiuajrI28iAf40cWgycWNgaXPO06dupuS+sgibK6c=
|
||||
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
|
||||
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260517200845-22f1b32dfad9 h1:RP73i+SOZYmc61F+gZjO/rvUlpPP0Za4MLJKAgS+1YI=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260517200845-22f1b32dfad9/go.mod h1:EcQEZ3NN06b3UmKxiRnQnXDDjQ9kmJgoQQBAS+fpRQw=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260518175130-4b27db42e21e h1:9pt3cvnJ3slg0lDjCwgVbvS/kI1JlKuNUFxdlYCGWF0=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260518175130-4b27db42e21e/go.mod h1:EcQEZ3NN06b3UmKxiRnQnXDDjQ9kmJgoQQBAS+fpRQw=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
|
||||
@@ -41,6 +41,8 @@ type AccountData struct {
|
||||
Password string
|
||||
Email string
|
||||
UUID string
|
||||
Name string
|
||||
Surname string
|
||||
}
|
||||
|
||||
// Create a new account
|
||||
@@ -59,6 +61,8 @@ func (c *AccountController) Create(ctx context.Context, data *AccountData) (stri
|
||||
UUID: data.UUID,
|
||||
Email: data.Email,
|
||||
PasswordHash: passwordHash,
|
||||
Name: data.Name,
|
||||
Surname: data.Surname,
|
||||
}
|
||||
|
||||
if err := repository.CreateAccount(ctx, c.DB, queryData); err != nil {
|
||||
|
||||
@@ -70,6 +70,8 @@ func TestIntegrationAccountCreate_Success(t *testing.T) {
|
||||
accountData := &controllers.AccountData{
|
||||
Password: "qwertyu9",
|
||||
Email: newTestUniqueEmail("accounts"),
|
||||
Surname: "Doe",
|
||||
Name: "John",
|
||||
}
|
||||
id, err := ctrl.Create(t.Context(), accountData)
|
||||
assert.NoError(t, err)
|
||||
@@ -82,6 +84,8 @@ func TestIntegrationAccountCreate_ExistingAccountErr(t *testing.T) {
|
||||
accountData := &controllers.AccountData{
|
||||
Password: "qwertyu9",
|
||||
Email: email,
|
||||
Surname: "Doe",
|
||||
Name: "John",
|
||||
}
|
||||
id, err := ctrl.Create(t.Context(), accountData)
|
||||
assert.NoError(t, err)
|
||||
|
||||
27
internal/controllers/projects.go
Normal file
27
internal/controllers/projects.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package controllers
|
||||
|
||||
import "context"
|
||||
|
||||
type ProjectsController struct{}
|
||||
|
||||
type ProjectData struct{}
|
||||
|
||||
// Create a new project
|
||||
func (ctrl *ProjectsController) Create(ctx context.Context, data *ProjectData) (id string, err error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Update an existing project
|
||||
func (ctrl *ProjectsController) Update(ctx context.Context, data *ProjectData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get an existing project by ID
|
||||
func (ctrl *ProjectsController) Get(ctx context.Context, projectID string) (data *ProjectData, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// List projects available for a user
|
||||
func (ctrl *ProjectsController) List(ctx context.Context) (data []*ProjectData, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -18,13 +18,15 @@ type AccountData struct {
|
||||
UUID string
|
||||
Email string
|
||||
PasswordHash string
|
||||
Name string
|
||||
Surname string
|
||||
}
|
||||
|
||||
// CreateAccount adds a new account to a database
|
||||
func CreateAccount(ctx context.Context, db *sql.DB, account *AccountData) error {
|
||||
query := "INSERT INTO accounts (uuid, email, password_hash) VALUES ($1, $2, $3)"
|
||||
query := "INSERT INTO accounts (uuid, email, password_hash, name, surname) VALUES ($1, $2, $3, $4, $5)"
|
||||
|
||||
if _, err := db.ExecContext(ctx, query, account.UUID, account.Email, account.PasswordHash); err != nil {
|
||||
if _, err := db.ExecContext(ctx, query, account.UUID, account.Email, account.PasswordHash, account.Name, account.Surname); err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == pgerrcode.UniqueViolation {
|
||||
|
||||
40
internal/repository/projects.go
Normal file
40
internal/repository/projects.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ProjectData struct {
|
||||
UUID string
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
OwnerID string
|
||||
CreatedAt string
|
||||
ArchivedAt time.Time
|
||||
Blocked bool
|
||||
UpdatedAt time.Time
|
||||
UpdatedBy string
|
||||
}
|
||||
|
||||
// CreateProject adds a new projects to the database
|
||||
func CreateProject(ctx context.Context, db *sql.DB, data *ProjectData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetProjectByID returns a project from the database
|
||||
func GetProjectByID(ctx context.Context, db *sql.DB, projectID string) (data *ProjectData, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UpdateProject change editable project data
|
||||
func UpdateProject(ctx context.Context, db *sql.DB, data *ProjectData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListProjects get all projects that are available for the user from the database
|
||||
func ListProjects(ctx context.Context, db *sql.DB) ([]*ProjectData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
3
migrations/20260518174322_users_personal_data.down.sql
Normal file
3
migrations/20260518174322_users_personal_data.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE accounts
|
||||
DROP COLUMN name,
|
||||
DROP COLUMN surname;
|
||||
14
migrations/20260518174322_users_personal_data.up.sql
Normal file
14
migrations/20260518174322_users_personal_data.up.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Up migration (safe for existing data)
|
||||
ALTER TABLE accounts
|
||||
ADD COLUMN name TEXT,
|
||||
ADD COLUMN surname TEXT;
|
||||
|
||||
UPDATE accounts
|
||||
SET
|
||||
name = 'John',
|
||||
surname = 'Doe'
|
||||
WHERE name IS NULL OR surname IS NULL;
|
||||
|
||||
ALTER TABLE accounts
|
||||
ALTER COLUMN name SET NOT NULL,
|
||||
ALTER COLUMN surname SET NOT NULL;
|
||||
1
migrations/20260518193048_projects_init.down.sql
Normal file
1
migrations/20260518193048_projects_init.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXIST prohects;
|
||||
16
migrations/20260518193048_projects_init.up.sql
Normal file
16
migrations/20260518193048_projects_init.up.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE projects (
|
||||
id UUID PRIMARY KEY,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
slug VARCHAR(120) NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
owner_user_id UUID NOT NULL,
|
||||
archived_at TIMESTAMP NULL,
|
||||
closed_at TIMESTAMP NULL,
|
||||
billing_account_id UUID NULL,
|
||||
max_clusters INTEGER DEFAULT 10,
|
||||
max_nodes INTEGER DEFAULT 100,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||
created_by UUID NOT NULL,
|
||||
updated_by UUID NOT NULL,
|
||||
);
|
||||
Reference in New Issue
Block a user