-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.go
47 lines (38 loc) · 1.43 KB
/
preferences.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package malak
import (
"context"
"time"
"github.com/google/uuid"
"github.com/uptrace/bun"
)
type CommunicationPreferences struct {
EnableMarketing bool `json:"enable_marketing,omitempty"`
EnableProductUpdates bool `json:"enable_product_updates,omitempty"`
}
type BillingPreferences struct {
FinanceEmail Email `json:"finance_email,omitempty"`
}
type Preference struct {
ID uuid.UUID `bun:"type:uuid,default:uuid_generate_v4(),pk" json:"id,omitempty"`
WorkspaceID uuid.UUID `json:"workspace_id,omitempty"`
Communication CommunicationPreferences `json:"communication,omitempty"`
Billing BillingPreferences `json:"billing,omitempty"`
CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"created_at,omitempty" bson:"created_at"`
UpdatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"updated_at,omitempty" bson:"updated_at"`
DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty" bson:"deleted_at"`
bun.BaseModel `json:"-"`
}
func NewPreference(workspace *Workspace) *Preference {
return &Preference{
WorkspaceID: workspace.ID,
Communication: CommunicationPreferences{
EnableMarketing: true,
EnableProductUpdates: true,
},
Billing: BillingPreferences{},
}
}
type PreferenceRepository interface {
Get(context.Context, *Workspace) (*Preference, error)
Update(context.Context, *Preference) error
}