From 9eb8878e9496d6576929af53632d05dd5130eb20 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Tue, 6 Apr 2021 23:35:04 +0200 Subject: [PATCH] refining some serialization --- internal/apimodule/app/appcreate.go | 2 +- internal/db/model/application.go | 11 +++++++++-- pkg/mastotypes/account.go | 2 +- pkg/mastotypes/application.go | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/apimodule/app/appcreate.go b/internal/apimodule/app/appcreate.go index cd5aff7..1adcef5 100644 --- a/internal/apimodule/app/appcreate.go +++ b/internal/apimodule/app/appcreate.go @@ -109,5 +109,5 @@ func (m *appModule) appsPOSTHandler(c *gin.Context) { } // done, return the new app information per the spec here: https://docs.joinmastodon.org/methods/apps/ - c.JSON(http.StatusOK, app.ToMasto()) + c.JSON(http.StatusOK, app.ToMastoSensitive()) } diff --git a/internal/db/model/application.go b/internal/db/model/application.go index c8eea64..4391552 100644 --- a/internal/db/model/application.go +++ b/internal/db/model/application.go @@ -41,8 +41,8 @@ type Application struct { VapidKey string } -// ToMasto returns this application as a mastodon api type, ready for serialization -func (a *Application) ToMasto() *mastotypes.Application { +// ToMastoSensitive returns this application as a mastodon api type, ready for serialization +func (a *Application) ToMastoSensitive() *mastotypes.Application { return &mastotypes.Application{ ID: a.ID, Name: a.Name, @@ -53,3 +53,10 @@ func (a *Application) ToMasto() *mastotypes.Application { VapidKey: a.VapidKey, } } + +func (a *Application) ToMastoPublic() *mastotypes.Application { + return &mastotypes.Application{ + Name: a.Name, + Website: a.Website, + } +} diff --git a/pkg/mastotypes/account.go b/pkg/mastotypes/account.go index 3ddd3c5..bbcf9c9 100644 --- a/pkg/mastotypes/account.go +++ b/pkg/mastotypes/account.go @@ -67,7 +67,7 @@ type Account struct { // When a timed mute will expire, if applicable. (ISO 8601 Datetime) MuteExpiresAt string `json:"mute_expires_at,omitempty"` // An extra entity to be used with API methods to verify credentials and update credentials. - Source *Source `json:"source"` + Source *Source `json:"source,omitempty"` } // AccountCreateRequest represents the form submitted during a POST request to /api/v1/accounts. diff --git a/pkg/mastotypes/application.go b/pkg/mastotypes/application.go index 1984eff..6140a01 100644 --- a/pkg/mastotypes/application.go +++ b/pkg/mastotypes/application.go @@ -35,7 +35,7 @@ type Application struct { // Client secret to use when obtaining an auth token for this application (ie., in client_secret parameter of https://docs.joinmastodon.org/methods/apps/) ClientSecret string `json:"client_secret,omitempty"` // Used for Push Streaming API. Returned with POST /api/v1/apps. Equivalent to https://docs.joinmastodon.org/entities/pushsubscription/#server_key - VapidKey string `json:"vapid_key"` + VapidKey string `json:"vapid_key,omitempty"` } // ApplicationPOSTRequest represents a POST request to https://example.org/api/v1/apps.