Add update organziation

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-13 11:15:13 +01:00
parent 843a3242e1
commit ab739d9bda
16 changed files with 544 additions and 93 deletions

View File

@@ -27,12 +27,12 @@ import (
type (
Organization struct {
ID gid.GID `db:"id"`
TenantID gid.TenantID `db:"tenant_id"`
Name string `db:"name"`
LogoURL string `db:"logo_url"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID gid.GID `db:"id"`
TenantID gid.TenantID `db:"tenant_id"`
Name string `db:"name"`
LogoObjectKey string `db:"logo_object_key"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
Organizations []*Organization
@@ -49,7 +49,7 @@ SELECT
tenant_id,
id,
name,
logo_url,
logo_object_key,
created_at,
updated_at
FROM
@@ -89,19 +89,19 @@ INSERT INTO organizations (
tenant_id,
id,
name,
logo_url,
logo_object_key,
created_at,
updated_at
) VALUES (@tenant_id, @id, @name, @logo_url, @created_at, @updated_at)
) VALUES (@tenant_id, @id, @name, @logo_object_key, @created_at, @updated_at)
`
args := pgx.StrictNamedArgs{
"tenant_id": o.TenantID,
"id": o.ID,
"name": o.Name,
"logo_url": o.LogoURL,
"created_at": o.CreatedAt,
"updated_at": o.UpdatedAt,
"tenant_id": o.TenantID,
"id": o.ID,
"name": o.Name,
"logo_object_key": o.LogoObjectKey,
"created_at": o.CreatedAt,
"updated_at": o.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
@@ -111,3 +111,38 @@ INSERT INTO organizations (
return nil
}
func (o *Organization) Update(
ctx context.Context,
scope Scoper,
conn pg.Conn,
) error {
q := `
UPDATE organizations
SET
name = @name,
logo_object_key = @logo_object_key,
updated_at = @updated_at
WHERE
%s
AND id = @id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"id": o.ID,
"name": o.Name,
"logo_object_key": o.LogoObjectKey,
"updated_at": o.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot update organization: %w", err)
}
return nil
}