Skip to content

Commit

Permalink
fix(user): move the collections to their own sub-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevMinerTV committed Aug 27, 2024
1 parent 8c10af2 commit 152d3d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
12 changes: 7 additions & 5 deletions internal/entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ func (u User) ToVersia() *versia.User {
Bio: u.Biography,
Fields: u.Fields,

Inbox: u.Inbox,
Outbox: u.Outbox,
Featured: u.Featured,
Followers: u.Followers,
Following: u.Following,
Inbox: u.Inbox,
Collections: versia.UserCollections{
versia.UserCollectionOutbox: u.Outbox,
versia.UserCollectionFeatured: u.Featured,
versia.UserCollectionFollowing: u.Following,
versia.UserCollectionFollowers: u.Followers,
},
}
}

Expand Down
9 changes: 5 additions & 4 deletions internal/repository/repo_impls/user_repository_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/lysand-org/versia-go/config"
"github.com/lysand-org/versia-go/internal/repository"
"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"
"golang.org/x/crypto/bcrypt"

Expand Down Expand Up @@ -109,10 +110,10 @@ func (i *UserRepositoryImpl) ImportVersiaUserByURI(ctx context.Context, uri *ver
SetFields(lUser.Fields).
SetExtensions(lUser.Extensions).
SetInbox(lUser.Inbox.String()).
SetOutbox(lUser.Outbox.String()).
SetFeatured(lUser.Featured.String()).
SetFollowers(lUser.Followers.String()).
SetFollowing(lUser.Following.String()).
SetOutbox(lUser.Collections[versia.UserCollectionOutbox].String()).
SetFeatured(lUser.Collections[versia.UserCollectionFeatured].String()).
SetFollowers(lUser.Collections[versia.UserCollectionFollowers].String()).
SetFollowing(lUser.Collections[versia.UserCollectionFollowing].String()).
OnConflict().
UpdateNewValues().
ID(ctx)
Expand Down
33 changes: 18 additions & 15 deletions pkg/versia/actor_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,12 @@ type User struct {
// https://lysand.org/objects/user#fields
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.
// https://lysand.org/objects/user#posts
Inbox *versiautils.URL `json:"inbox"`

// Outbox is the outbox of the user.
// https://lysand.org/objects/user#outbox
Outbox *versiautils.URL `json:"outbox"`
// Collections is a map of all collections for a user
Collections UserCollections `json:"collections"`
}

func (u User) MarshalJSON() ([]byte, error) {
Expand All @@ -81,6 +68,22 @@ type UserField struct {
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].
//
// [Spec]: https://lysand.org/security/keys#public-key-cryptography
Expand Down

0 comments on commit 152d3d5

Please sign in to comment.