mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 06:28:18 +01:00
fix(user): move the collections to their own sub-struct
This commit is contained in:
parent
cb135706e2
commit
0223ea0535
|
|
@ -103,10 +103,12 @@ func (u User) ToVersia() *versia.User {
|
||||||
Fields: u.Fields,
|
Fields: u.Fields,
|
||||||
|
|
||||||
Inbox: u.Inbox,
|
Inbox: u.Inbox,
|
||||||
Outbox: u.Outbox,
|
Collections: versia.UserCollections{
|
||||||
Featured: u.Featured,
|
versia.UserCollectionOutbox: u.Outbox,
|
||||||
Followers: u.Followers,
|
versia.UserCollectionFeatured: u.Featured,
|
||||||
Following: u.Following,
|
versia.UserCollectionFollowing: u.Following,
|
||||||
|
versia.UserCollectionFollowers: u.Followers,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/config"
|
"github.com/lysand-org/versia-go/config"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
|
|
@ -109,10 +110,10 @@ func (i *UserRepositoryImpl) ImportVersiaUserByURI(ctx context.Context, uri *ver
|
||||||
SetFields(lUser.Fields).
|
SetFields(lUser.Fields).
|
||||||
SetExtensions(lUser.Extensions).
|
SetExtensions(lUser.Extensions).
|
||||||
SetInbox(lUser.Inbox.String()).
|
SetInbox(lUser.Inbox.String()).
|
||||||
SetOutbox(lUser.Outbox.String()).
|
SetOutbox(lUser.Collections[versia.UserCollectionOutbox].String()).
|
||||||
SetFeatured(lUser.Featured.String()).
|
SetFeatured(lUser.Collections[versia.UserCollectionFeatured].String()).
|
||||||
SetFollowers(lUser.Followers.String()).
|
SetFollowers(lUser.Collections[versia.UserCollectionFollowers].String()).
|
||||||
SetFollowing(lUser.Following.String()).
|
SetFollowing(lUser.Collections[versia.UserCollectionFollowing].String()).
|
||||||
OnConflict().
|
OnConflict().
|
||||||
UpdateNewValues().
|
UpdateNewValues().
|
||||||
ID(ctx)
|
ID(ctx)
|
||||||
|
|
|
||||||
|
|
@ -48,25 +48,12 @@ type User struct {
|
||||||
// https://lysand.org/objects/user#fields
|
// https://lysand.org/objects/user#fields
|
||||||
Fields []UserField `json:"fields,omitempty"`
|
Fields []UserField `json:"fields,omitempty"`
|
||||||
|
|
||||||
// Featured is the featured posts of the user.
|
|
||||||
// https://lysand.org/objects/user#featured
|
|
||||||
Featured *versiautils.URL `json:"featured"`
|
|
||||||
|
|
||||||
// Followers is the followers of the user.
|
|
||||||
// https://lysand.org/objects/user#followers
|
|
||||||
Followers *versiautils.URL `json:"followers"`
|
|
||||||
|
|
||||||
// Following is the users that the user is following.
|
|
||||||
// https://lysand.org/objects/user#following
|
|
||||||
Following *versiautils.URL `json:"following"`
|
|
||||||
|
|
||||||
// Inbox is the inbox of the user.
|
// Inbox is the inbox of the user.
|
||||||
// https://lysand.org/objects/user#posts
|
// https://lysand.org/objects/user#posts
|
||||||
Inbox *versiautils.URL `json:"inbox"`
|
Inbox *versiautils.URL `json:"inbox"`
|
||||||
|
|
||||||
// Outbox is the outbox of the user.
|
// Collections is a map of all collections for a user
|
||||||
// https://lysand.org/objects/user#outbox
|
Collections UserCollections `json:"collections"`
|
||||||
Outbox *versiautils.URL `json:"outbox"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) MarshalJSON() ([]byte, error) {
|
func (u User) MarshalJSON() ([]byte, error) {
|
||||||
|
|
@ -81,6 +68,22 @@ type UserField struct {
|
||||||
Value versiautils.TextContentTypeMap `json:"value"`
|
Value versiautils.TextContentTypeMap `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserCollectionType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UserCollectionFeatured is a URL to a collection of the user's featured posts.
|
||||||
|
UserCollectionFeatured UserCollectionType = "featured"
|
||||||
|
// UserCollectionFollowers is a URL to a collection of the user's followers.
|
||||||
|
UserCollectionFollowers UserCollectionType = "followers"
|
||||||
|
// UserCollectionFollowing is a URL to a collection of the users that the user is following.
|
||||||
|
UserCollectionFollowing UserCollectionType = "following"
|
||||||
|
// UserCollectionOutbox is a URL to a collection of the user's posts.
|
||||||
|
UserCollectionOutbox UserCollectionType = "outbox"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserCollections is a map of all collections for a user
|
||||||
|
type UserCollections map[UserCollectionType]*versiautils.URL
|
||||||
|
|
||||||
// UserPublicKey represents a public key for a user. For more information, see the [Spec].
|
// UserPublicKey represents a public key for a user. For more information, see the [Spec].
|
||||||
//
|
//
|
||||||
// [Spec]: https://lysand.org/security/keys#public-key-cryptography
|
// [Spec]: https://lysand.org/security/keys#public-key-cryptography
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue