summaryrefslogtreecommitdiff
path: root/app/domain/user.go
blob: 97bacdd7586306c43c0bfeeda4e66eaedcd645b4 (plain)
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 domain

import (
	v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
	"github.com/xlgmokha/x/pkg/x"
)

type User struct {
	ID         ID     `json:"id" jsonapi:"primary,users"`
	Username   string `json:"username" jsonapi:"attr,username"`
	ProfileURL string `json:"profile" jsonapi:"attr,profile"`
	Picture    string `json:"picture" jsonapi:"attr,picture"`
}

func (u *User) GetID() ID {
	return u.ID
}

func (u *User) SetID(id ID) error {
	u.ID = id
	return nil
}

func (u *User) Validate() error {
	return nil
}

func (self *User) Sparkle(sparklee string, reason string) *Sparkle {
	return &Sparkle{
		Sparklee: sparklee,
		Author:   self,
		Reason:   reason,
	}
}

func (self *User) ToGID() GlobalID {
	if x.IsZero(self.Username) {
		return GlobalID("gid://sparkle/User/*")
	}
	return GlobalID("gid://sparkle/User/" + self.Username)
}

func (self *User) ToSubjectReference() *v1.SubjectReference {
	return &v1.SubjectReference{
		Object: self.ToGID().ToObjectReference(),
	}
}