initial commits
parent
fcfa76fb74
commit
31ab372cb5
|
@ -388,7 +388,6 @@ func (receiver Account) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
buffer = append(buffer, "}"...)
|
buffer = append(buffer, "}"...)
|
||||||
|
|
||||||
return buffer, nil
|
return buffer, nil
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,13 +9,6 @@ import (
|
||||||
|
|
||||||
var _ json.Marshaler = CustomEmoji{}
|
var _ json.Marshaler = CustomEmoji{}
|
||||||
|
|
||||||
const (
|
|
||||||
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no ‘shortcode’ set")
|
|
||||||
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no ‘url’ set")
|
|
||||||
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no ‘static_url’ set")
|
|
||||||
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no ‘visible_in_picker’ set")
|
|
||||||
)
|
|
||||||
|
|
||||||
// CustomEmoji represents a Mastodon API "CustomEmoji".
|
// CustomEmoji represents a Mastodon API "CustomEmoji".
|
||||||
//
|
//
|
||||||
// See:
|
// See:
|
||||||
|
@ -30,45 +23,69 @@ type CustomEmoji struct {
|
||||||
|
|
||||||
func (receiver CustomEmoji) MarshalJSON() ([]byte, error) {
|
func (receiver CustomEmoji) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
data := map[string]interface{}{}
|
var buffer []byte
|
||||||
|
|
||||||
|
buffer = append(buffer, "{"...)
|
||||||
|
|
||||||
{
|
{
|
||||||
value, found := receiver.ShortCode.Get()
|
buffer = append(buffer, `"shortcode":`...)
|
||||||
if !found {
|
|
||||||
return nil, errCannotMashalCustomEmojiAsJSONNoShortCode
|
marshaled, err := json.Marshal(receiver.ShortCode)
|
||||||
|
if nil != err {
|
||||||
|
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.ShortCode as JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["shortcode"] = value
|
buffer = append(buffer, marshaled...)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
value, found := receiver.URL.Get()
|
buffer = append(buffer, `,"url":`...)
|
||||||
if !found {
|
|
||||||
return nil, errCannotMashalCustomEmojiAsJSONNoURL
|
marshaled, err := json.Marshal(receiver.URL)
|
||||||
|
if nil != err {
|
||||||
|
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.URL as JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["url"] = value
|
buffer = append(buffer, marshaled...)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
value, found := receiver.StaticURL.Get()
|
buffer = append(buffer, `,"static_url":`...)
|
||||||
if !found {
|
|
||||||
return nil, errCannotMashalCustomEmojiAsJSONNoStaticURL
|
marshaled, err := json.Marshal(receiver.StaticURL)
|
||||||
|
if nil != err {
|
||||||
|
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.StaticURL as JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["static_url"] = value
|
buffer = append(buffer, marshaled...)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
value, found := receiver.VisibleInPicker.Get()
|
buffer = append(buffer, `,"visible_in_picker":`...)
|
||||||
if !found {
|
|
||||||
return nil, errCannotMashalCustomEmojiAsJSONNoVisibleInPicker
|
marshaled, err := json.Marshal(receiver.VisibleInPicker)
|
||||||
|
if nil != err {
|
||||||
|
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.VisibleInPicker as JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["visible_in_picker"] = value
|
buffer = append(buffer, marshaled...)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
receiver.Category.WhenSomething(func(value string){
|
if opt.Nothing[string]() != receiver.Category {
|
||||||
data["category"] = value
|
|
||||||
})
|
buffer = append(buffer, `,"category":`...)
|
||||||
|
|
||||||
|
marshaled, err := json.Marshal(receiver.Category)
|
||||||
|
if nil != err {
|
||||||
|
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.Category as JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(data)
|
buffer = append(buffer, marshaled...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = append(buffer, "}"...)
|
||||||
|
|
||||||
|
return buffer, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
|
||||||
Expected:
|
Expected:
|
||||||
"{" +"\n"+
|
"{" +"\n"+
|
||||||
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
|
||||||
"\t"+ `"url":` +`""` +"," +"\n"+
|
"\t"+ `"url":` +`""` +"," +"\n"+
|
||||||
|
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
||||||
"}" +"\n",
|
"}" +"\n",
|
||||||
},
|
},
|
||||||
|
@ -43,8 +43,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
|
||||||
Expected:
|
Expected:
|
||||||
"{" +"\n"+
|
"{" +"\n"+
|
||||||
"\t"+ `"shortcode":` +`"bananas"` +"," +"\n"+
|
"\t"+ `"shortcode":` +`"bananas"` +"," +"\n"+
|
||||||
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
|
||||||
"\t"+ `"url":` +`""` +"," +"\n"+
|
"\t"+ `"url":` +`""` +"," +"\n"+
|
||||||
|
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
||||||
"}" +"\n",
|
"}" +"\n",
|
||||||
},
|
},
|
||||||
|
@ -58,8 +58,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
|
||||||
Expected:
|
Expected:
|
||||||
"{" +"\n"+
|
"{" +"\n"+
|
||||||
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
|
||||||
"\t"+ `"url":` +`"https://example.com/emoji/cracra"` +"," +"\n"+
|
"\t"+ `"url":` +`"https://example.com/emoji/cracra"` +"," +"\n"+
|
||||||
|
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
||||||
"}" +"\n",
|
"}" +"\n",
|
||||||
},
|
},
|
||||||
|
@ -73,8 +73,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
|
||||||
Expected:
|
Expected:
|
||||||
"{" +"\n"+
|
"{" +"\n"+
|
||||||
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"static_url":` +`"https://static.example.com/img/emoji/cracra.png"` +"," +"\n"+
|
|
||||||
"\t"+ `"url":` +`""` +"," +"\n"+
|
"\t"+ `"url":` +`""` +"," +"\n"+
|
||||||
|
"\t"+ `"static_url":` +`"https://static.example.com/img/emoji/cracra.png"` +"," +"\n"+
|
||||||
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
|
||||||
"}" +"\n",
|
"}" +"\n",
|
||||||
},
|
},
|
||||||
|
@ -88,8 +88,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
|
||||||
Expected:
|
Expected:
|
||||||
"{" +"\n"+
|
"{" +"\n"+
|
||||||
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
"\t"+ `"shortcode":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
|
||||||
"\t"+ `"url":` +`""` +"," +"\n"+
|
"\t"+ `"url":` +`""` +"," +"\n"+
|
||||||
|
"\t"+ `"static_url":` +`""` +"," +"\n"+
|
||||||
"\t"+ `"visible_in_picker":` +`true` +"" +"\n"+
|
"\t"+ `"visible_in_picker":` +`true` +"" +"\n"+
|
||||||
"}" +"\n",
|
"}" +"\n",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue