From dc72440189842b00b146679b6abb591db806131c Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 26 Sep 2023 21:12:48 +0900 Subject: [PATCH] initial commits --- ent/role.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ent/role.go b/ent/role.go index 3653ebf..78e758c 100644 --- a/ent/role.go +++ b/ent/role.go @@ -7,6 +7,7 @@ import ( "sourcecode.social/reiver/go-jsonint" ) +var _ json.Marshaler = Role{} var _ json.Unmarshaler = new(Role) // Role represents a Mastodon API "Role". @@ -29,6 +30,23 @@ type role struct { Highlighted opt.Optional[bool] `json:"Highlighted"` } +func (receiver Role) MarshalJSON() ([]byte, error) { + + var src role + + src.ID = receiver.ID + src.Name = receiver.Name + src.Permissions = receiver.Permissions + src.Highlighted = src.Highlighted + + src.Color = receiver.Color + receiver.Color.WhenNothing(func(){ + src.Color = opt.Something("") + }) + + return json.Marshal(src) +} + func (receiver *Role) UnmarshalJSON(data []byte) error { if nil == receiver { return errNilReceiver