10
pkg/probo/coredata/migrations/20250206T121300Z.sql
Normal file
10
pkg/probo/coredata/migrations/20250206T121300Z.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE TYPE people_kind AS ENUM (
|
||||
'EMPLOYEE',
|
||||
'CONTRACTOR'
|
||||
);
|
||||
|
||||
ALTER TABLE peoples ADD COLUMN kind people_kind;
|
||||
|
||||
UPDATE peoples SET kind = 'EMPLOYEE';
|
||||
|
||||
ALTER TABLE peoples ALTER COLUMN kind SET NOT NULL;
|
||||
@@ -31,6 +31,7 @@ type (
|
||||
People struct {
|
||||
ID gid.GID
|
||||
OrganizationID gid.GID
|
||||
Kind PeopleKind
|
||||
FullName string
|
||||
PrimaryEmailAddress string
|
||||
AdditionalEmailAddresses []string
|
||||
@@ -49,6 +50,7 @@ func (p *People) scan(r pgx.Row) error {
|
||||
return r.Scan(
|
||||
&p.ID,
|
||||
&p.OrganizationID,
|
||||
&p.Kind,
|
||||
&p.FullName,
|
||||
&p.PrimaryEmailAddress,
|
||||
&p.AdditionalEmailAddresses,
|
||||
@@ -67,6 +69,7 @@ func (p *People) LoadByID(
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
kind,
|
||||
full_name,
|
||||
primary_email_address,
|
||||
additional_email_addresses,
|
||||
@@ -106,6 +109,7 @@ INSERT INTO
|
||||
peoples (
|
||||
id,
|
||||
organization_id,
|
||||
kind,
|
||||
full_name,
|
||||
primary_email_address,
|
||||
additional_email_addresses,
|
||||
@@ -115,6 +119,7 @@ INSERT INTO
|
||||
VALUES (
|
||||
@people_id,
|
||||
@organization_id,
|
||||
@kind,
|
||||
@full_name,
|
||||
@primary_email_address,
|
||||
@additional_email_addresses,
|
||||
@@ -126,6 +131,7 @@ VALUES (
|
||||
args := pgx.NamedArgs{
|
||||
"people_id": p.ID,
|
||||
"organization_id": p.OrganizationID,
|
||||
"kind": p.Kind,
|
||||
"full_name": p.FullName,
|
||||
"primary_email_address": p.PrimaryEmailAddress,
|
||||
"additional_email_addresses": p.AdditionalEmailAddresses,
|
||||
@@ -147,6 +153,7 @@ func (p *Peoples) LoadByOrganizationID(
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
kind,
|
||||
full_name,
|
||||
primary_email_address,
|
||||
additional_email_addresses,
|
||||
|
||||
74
pkg/probo/coredata/people_kind.go
Normal file
74
pkg/probo/coredata/people_kind.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
PeopleKind uint8
|
||||
)
|
||||
|
||||
const (
|
||||
PeopleKindEmployee PeopleKind = iota
|
||||
PeopleKindContractor
|
||||
)
|
||||
|
||||
func (ps PeopleKind) MarshalText() ([]byte, error) {
|
||||
return []byte(ps.String()), nil
|
||||
}
|
||||
|
||||
func (ps *PeopleKind) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
|
||||
switch val {
|
||||
case PeopleKindEmployee.String():
|
||||
*ps = PeopleKindEmployee
|
||||
case PeopleKindContractor.String():
|
||||
*ps = PeopleKindContractor
|
||||
default:
|
||||
return fmt.Errorf("invalid PeopleKind value: %q", val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ts PeopleKind) String() string {
|
||||
var val string
|
||||
|
||||
switch ts {
|
||||
case PeopleKindEmployee:
|
||||
val = "EMPLOYEE"
|
||||
case PeopleKindContractor:
|
||||
val = "CONTRACTOR"
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (pk *PeopleKind) Scan(value any) error {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for PeopleKind, expected string got %T", value)
|
||||
}
|
||||
|
||||
return pk.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
func (pk PeopleKind) Value() (driver.Value, error) {
|
||||
return pk.String(), nil
|
||||
}
|
||||
@@ -30,6 +30,7 @@ type (
|
||||
FullName string
|
||||
PrimaryEmailAddress string
|
||||
AdditionalEmailAddresses []string
|
||||
Kind coredata.PeopleKind
|
||||
}
|
||||
)
|
||||
|
||||
@@ -47,6 +48,7 @@ func (s Service) CreatePeople(
|
||||
people := &coredata.People{
|
||||
ID: peopleID,
|
||||
OrganizationID: req.OrganizationID,
|
||||
Kind: req.Kind,
|
||||
FullName: req.FullName,
|
||||
PrimaryEmailAddress: req.PrimaryEmailAddress,
|
||||
AdditionalEmailAddresses: req.AdditionalEmailAddresses,
|
||||
|
||||
Reference in New Issue
Block a user