socialnetwork

package
v0.0.0-...-f54e1bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: BSD-3-Clause Imports: 18 Imported by: 1

README

socialnetwork

import "github.com/blueprint-uservices/blueprint/examples/dsb_sn/workflow/socialnetwork"

Index

Constants

Enums aren't supported atm. So just use integers instead.

const (
    POST int64 = iota
    REPOST
    REPLY
    DM
)

func GetMachineID

func GetMachineID() string

From: https://gist.github.com/tsilvers/085c5f39430ced605d970094edf167ba

type ComposePostService

The ComposePostService interface

type ComposePostService interface {
    // Compose a post from the provided arguments
    ComposePost(ctx context.Context, reqID int64, username string, userID int64, text string, mediaIDs []int64, mediaTypes []string, postType int64) (int64, []int64, error)
}

func NewComposePostServiceImpl
func NewComposePostServiceImpl(ctx context.Context, postStorageService PostStorageService, userTimelineService UserTimelineService, userService UserService, uniqueIDService UniqueIdService, mediaService MediaService, textService TextService, homeTimelineService HomeTimelineService) (ComposePostService, error)

Creates a ComposePostService instance that creates a post from the provided arguments and connects to the various internal services to store the newly created post and update the state.

type ComposePostServiceImpl

Implementation of ComposePostService

type ComposePostServiceImpl struct {
    // contains filtered or unexported fields
}

func (*ComposePostServiceImpl) ComposePost
func (c *ComposePostServiceImpl) ComposePost(ctx context.Context, reqID int64, username string, userID int64, text string, mediaIDs []int64, mediaTypes []string, postType int64) (int64, []int64, error)

ComposePost implements ComposePostService

type Creator

The format of a creator stored as part of a post

type Creator struct {
    UserID   int64
    Username string
}

type FolloweeInfo

The format of a followee's info stored in the user info in the social-graph

type FolloweeInfo struct {
    FolloweeID int64
    Timestamp  int64
}

type FollowerInfo

The format of a follower's info stored in the user info in the social-graph

type FollowerInfo struct {
    FollowerID int64
    Timestamp  int64
}

type HomeTimelineService

The HomeTimelineService Interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].

type HomeTimelineService interface {
    // Reads the timeline of the user that has the id `userID`.
    // The return value is represented by the slice: post_ids[start:stop].
    ReadHomeTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)
    // Adds a new post to the home timeline of the following users:
    // (i)   user with id `userID`,
    // (ii)  all the followers of the user with `userID`
    // (iii) all the mentioned users in the post listed in the `userMentionIDs`.
    // The new post ID is placed at the nth position in the post ids array.
    //    post_ids = append(post_ids, `postID`)
    WriteHomeTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64, userMentionIDs []int64) error
}

func NewHomeTimelineServiceImpl
func NewHomeTimelineServiceImpl(ctx context.Context, homeTimelineCache backend.Cache, postStorageService PostStorageService, socialGraphService SocialGraphService) (HomeTimelineService, error)

Creates a HomeTimelineService instance that maintains the home timelines for the various users.

type HomeTimelineServiceImpl

Implementation of HomeTimelineService

type HomeTimelineServiceImpl struct {
    // contains filtered or unexported fields
}

func (*HomeTimelineServiceImpl) ReadHomeTimeline
func (h *HomeTimelineServiceImpl) ReadHomeTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)

Implements HomeTimelineService interface

func (*HomeTimelineServiceImpl) WriteHomeTimeline
func (h *HomeTimelineServiceImpl) WriteHomeTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64, userMentionIDs []int64) error

Implements HomeTimelineService interface

type LoginObj

The format of a Login object.

type LoginObj struct {
    UserID   int64
    Password string
    Salt     string
}

type Media

The format of a media stored as part of a post.

type Media struct {
    MediaID   int64
    MediaType string
}

type MediaService

The MediaService interface

type MediaService interface {
    // Creates and returns a list of Media objects from the provided `mediaTypes` and `mediaIds` arguments.
    // Returns an error if the length of mediaTypes and mediaIds do not match.
    ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error)
}

func NewMediaServiceImpl
func NewMediaServiceImpl(ctx context.Context) (MediaService, error)

Creates a MediaService instance that creates media objects

type MediaServiceImpl

Implementation of MediaService

type MediaServiceImpl struct{}

func (*MediaServiceImpl) ComposeMedia
func (m *MediaServiceImpl) ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error)

Implements MediaService interface

type Post

type Post struct {
    PostID       int64
    Creator      Creator
    ReqID        int64
    Text         string
    UserMentions []UserMention
    Medias       []Media
    Urls         []URL
    Timestamp    int64
    PostType     int64
}

type PostInfo

The format of a single post in a user's timeline stored in the backend.

type PostInfo struct {
    PostID    int64
    Timestamp int64
}

type PostStorageService

The PostStorageService interface

type PostStorageService interface {
    // Stores a new `post` in the relevant backends.
    StorePost(ctx context.Context, reqID int64, post Post) error
    // Returns the post with id `postID`
    // If no post with id `postID` exists in the database, an error is returned.
    ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)
    // Returns a list of posts that have ids in the array `postIDs`.
    // No error is thrown if no post is found.
    ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error)
}

func NewPostStorageServiceImpl
func NewPostStorageServiceImpl(ctx context.Context, postStorageCache backend.Cache, postStorageDB backend.NoSQLDatabase) (PostStorageService, error)

Creates a PostStorageService instance that manages the post backends.

type PostStorageServiceImpl

Implementation of PostStorageService

type PostStorageServiceImpl struct {
    CacheHits int64
    NumReqs   int64
    CacheMiss int64
    // contains filtered or unexported fields
}

func (*PostStorageServiceImpl) ReadPost
func (p *PostStorageServiceImpl) ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)

Implements PostStorageService interface

func (*PostStorageServiceImpl) ReadPosts
func (p *PostStorageServiceImpl) ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error)

Implements PostStorageService interface

func (*PostStorageServiceImpl) StorePost
func (p *PostStorageServiceImpl) StorePost(ctx context.Context, reqID int64, post Post) error

Implements PostStorageService interface

type PostType

The type of the post.

type PostType int64

type SocialGraphService

The SocialGraphService interface

type SocialGraphService interface {
    // Returns the user IDs of all the followers of the user with user id `userID`.
    // Returns an error if user with `userID` doesn't exist in database.
    GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)
    // Returns the user IDs of all the followees of the user with user id `userID`.
    // Returns an error if user with `userID` doesn't exist in database.
    GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)
    // Creates a follower-followee relationship between users with IDs `userID`-`followeeID`.
    Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
    // Removes the follower-followee relationship between users with IDs `userID`-`followeeID`.
    Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
    // Creates a follower-followee relationship between users with usernames `userUsername`-`followeeUsername`.
    FollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error
    // Removes the follower-followee relationship between users with usernames `userUsername`-`followeeUsername`.
    UnfollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error
    // Inserts a new user with `userID` in the database.
    InsertUser(ctx context.Context, reqID int64, userID int64) error
}

func NewSocialGraphServiceImpl
func NewSocialGraphServiceImpl(ctx context.Context, socialGraphCache backend.Cache, socialGraphDB backend.NoSQLDatabase, userIDService UserIDService) (SocialGraphService, error)

Creates a SocialGraphService instance that maintains the social graph backends.

type SocialGraphServiceImpl

Implementation of SocialGraphService

type SocialGraphServiceImpl struct {
    // contains filtered or unexported fields
}

func (*SocialGraphServiceImpl) Follow
func (s *SocialGraphServiceImpl) Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) FollowWithUsername
func (s *SocialGraphServiceImpl) FollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) GetFollowees
func (s *SocialGraphServiceImpl) GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) GetFollowers
func (s *SocialGraphServiceImpl) GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) InsertUser
func (s *SocialGraphServiceImpl) InsertUser(ctx context.Context, reqID int64, userID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) Unfollow
func (s *SocialGraphServiceImpl) Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) UnfollowWithUsername
func (s *SocialGraphServiceImpl) UnfollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error

Implements SocialGraphService interface

type TextService

The TextService interface

type TextService interface {
    // Parses the raw `text` to return an edited text with the urls replaced with shortened urls, usermention objects to be stored with the post, and the url objects to be stored with the post.
    ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error)
}

func NewTextServiceImpl
func NewTextServiceImpl(ctx context.Context, urlShortenService UrlShortenService, userMentionService UserMentionService) (TextService, error)

Creates a TextService instance for parsing texts in created posts.

type TextServiceImpl

Implementation of TextService

type TextServiceImpl struct {
    // contains filtered or unexported fields
}

func (*TextServiceImpl) ComposeText
func (t *TextServiceImpl) ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error)

Implements TextService interface

type URL

The format of a url stored in the url-shorten database

type URL struct {
    ShortenedUrl string
    ExpandedUrl  string
}

type UniqueIdService

The UniqueIdService interface

type UniqueIdService interface {
    // Returns a newly generated unique id to be used as a post's unique identifier.
    ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error)
}

func NewUniqueIdServiceImpl
func NewUniqueIdServiceImpl(ctx context.Context) (UniqueIdService, error)

Implements UniqueIdService interface

type UniqueIdServiceImpl

Implementation of UserTimelineService

type UniqueIdServiceImpl struct {
    // contains filtered or unexported fields
}

func (*UniqueIdServiceImpl) ComposeUniqueId
func (u *UniqueIdServiceImpl) ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error)

Implements UniqueIdService interface

type UrlShortenService

The UrlShortenService interface

type UrlShortenService interface {
    // Converts raw `urls` into shortened urls to be used within the application. Returns the list of shortened urls.
    ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error)
    // Converts the list of shortened urls into their extended forms.
    GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error)
}

func NewUrlShortenServiceImpl
func NewUrlShortenServiceImpl(ctx context.Context, urlShortenDB backend.NoSQLDatabase) (UrlShortenService, error)

Creates a UrlShortenService instance for converting raw urls to shortened urls and vice versa.

type UrlShortenServiceImpl

Implementation of UrlShortenService

type UrlShortenServiceImpl struct {
    // contains filtered or unexported fields
}

func (*UrlShortenServiceImpl) ComposeUrls
func (u *UrlShortenServiceImpl) ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error)

Implements ComposeUrls interface

func (*UrlShortenServiceImpl) GetExtendedUrls
func (u *UrlShortenServiceImpl) GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error)

Implements UrlShortenService interface. Currently not implemented as the original DSB application doesn't implement this function either.

type User

The format of a user stored in the user database

type User struct {
    UserID    int64
    FirstName string
    LastName  string
    Username  string
    PwdHashed string
    Salt      string
}

type UserIDService

The UserIDService interface

type UserIDService interface {
    // Returns the userID of the user associated with the `username`.
    // Returns an error if no user exists with the given `username`.
    GetUserId(ctx context.Context, reqID int64, username string) (int64, error)
}

func NewUserIDServiceImpl
func NewUserIDServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserIDService, error)

Creates a UserIDService instance for looking up users with usernames.

type UserIDServiceImpl

Implementation of UserIDService

type UserIDServiceImpl struct {
    // contains filtered or unexported fields
}

func (*UserIDServiceImpl) GetUserId
func (u *UserIDServiceImpl) GetUserId(ctx context.Context, reqID int64, username string) (int64, error)

Implements UserIDService interface

type UserInfo

The format of a user's info stored in the social-graph

type UserInfo struct {
    UserID    int64
    Followers []FollowerInfo
    Followees []FolloweeInfo
}

type UserMention

The format of a usermention stored as part of a post

type UserMention struct {
    UserID   int64
    Username string
}

type UserMentionService

The UserMentionService interface

type UserMentionService interface {
    // Composes UserMention objects to be stored in a post by converting raw usernames.
    // Returns an error if any name in the `usernames` array is not registered.
    ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error)
}

func NewUserMentionServiceImpl
func NewUserMentionServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserMentionService, error)

Creates a UserMentionService instance that is responsible for converting usernames to usermention objects

type UserMentionServiceImpl

Implementation of UserMentionService

type UserMentionServiceImpl struct {
    // contains filtered or unexported fields
}

func (*UserMentionServiceImpl) ComposeUserMentions
func (u *UserMentionServiceImpl) ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error)

Implements the UserMentionService interface

type UserPosts

The format of a user's timeline stored in the backend.

type UserPosts struct {
    UserID int64
    Posts  []PostInfo
}

type UserService

The UserService interface

type UserService interface {
    // Logs in a user using the user's `username` and `password`
    // Returns an error if the username is not registered or if the provided password doesn't match the stored password.
    Login(ctx context.Context, reqID int64, username string, password string) (string, error)
    // Registers a new user with a given `userID`.
    // Returns an error if the `userID` is already taken.
    RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string, userID int64) error
    // Registers a new user. A random `userID` is generated by the service.
    RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string) error
    // Creates and returns a creator object to be included in a Post. The Creator object is created using the `userID`.
    ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)
    // Creates and returns a creator object to be included in a Post. The service looks up the userID of the user with the given `username`.
    // Returns an error if the user with the given `username` is not registered.
    ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)
}

func NewUserServiceImpl
func NewUserServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase, socialGraphService SocialGraphService, secret string) (UserService, error)

Implementation of UserService

type UserServiceImpl

Implementation of UserService

type UserServiceImpl struct {
    // contains filtered or unexported fields
}

func (*UserServiceImpl) ComposeCreatorWithUserId
func (u *UserServiceImpl) ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)

Implements UserService interface

func (*UserServiceImpl) ComposeCreatorWithUsername
func (u *UserServiceImpl) ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)

Implements UserService interface

func (*UserServiceImpl) Login
func (u *UserServiceImpl) Login(ctx context.Context, reqID int64, username string, password string) (string, error)

Implements UserService interface

func (*UserServiceImpl) RegisterUser
func (u *UserServiceImpl) RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string) error

Implements UserService interface

func (*UserServiceImpl) RegisterUserWithId
func (u *UserServiceImpl) RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string, userID int64) error

Implements UserService interface

type UserTimelineService

The UserTimelineService interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].

type UserTimelineService interface {
    // Reads the timeline of the user that has the id `userID`.
    // The return value is represented by the slice: post_ids[start:stop].
    ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)
    // Adds a new post to the user timeline of the user that has the id `userID`
    // The new post ID is placed at the 0th position in the post ids array.
    //    post_ids = []int64{`postID`, post_ids...)
    WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error
}

func NewUserTimelineServiceImpl
func NewUserTimelineServiceImpl(ctx context.Context, userTimelineCache backend.Cache, userTimelineDB backend.NoSQLDatabase, postStorageService PostStorageService) (UserTimelineService, error)

Creates a UserTimelineService instance for managing the user timelines for the various users.

type UserTimelineServiceImpl

Implementation of UserTimelineService

type UserTimelineServiceImpl struct {
    CacheHits   int64
    CacheMiss   int64
    NumRequests int64
    // contains filtered or unexported fields
}

func (*UserTimelineServiceImpl) ReadUserTimeline
func (u *UserTimelineServiceImpl) ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)

Implements UserTimelineService interface

func (*UserTimelineServiceImpl) WriteUserTimeline
func (u *UserTimelineServiceImpl) WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error

Implements UserTimelineService interface

type Wrk2APIService

The Wrk2APIService (Frontend) interface

type Wrk2APIService interface {
    // Reads the home timeline of the user with `userId`.
    // Returns the list of posts[start, stop] from the timeline.
    ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
    // Reads the user timeline of the user with `userId`.
    // Returns the list of posts[start, stop] from the timeline.
    ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
    // Creates a Follow-Link between users `userId`-`followeeID`.
    // If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`.
    // Returns an error if no pairs are provided.
    Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error
    // Removes a Follow-Link between users `userId`-`followeeID`.
    // If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`.
    // Returns an error if no pairs are provided.
    Unfollow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error
    // Registers a new user with the given `userId`.
    Register(ctx context.Context, firstName string, lastName string, username string, password string, userId int64) error
    // Composes a new post give the provided arguments.
    // Returns the created post's ID and the ids of the mentioned users.
    ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error)
}

func NewWrk2APIServiceImpl
func NewWrk2APIServiceImpl(ctx context.Context, userService UserService, composePostService ComposePostService, userTimelineService UserTimelineService, homeTimelineService HomeTimelineService, socialGraphService SocialGraphService) (Wrk2APIService, error)

Creates a Wrk2APIService instance to act as the gateway to internal services.

type Wrk2APIServiceImpl

Implementation of Wrk2APIService

type Wrk2APIServiceImpl struct {
    // contains filtered or unexported fields
}

func (*Wrk2APIServiceImpl) ComposePost
func (w *Wrk2APIServiceImpl) ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Follow
func (w *Wrk2APIServiceImpl) Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) ReadHomeTimeline
func (w *Wrk2APIServiceImpl) ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) ReadUserTimeline
func (w *Wrk2APIServiceImpl) ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Register
func (w *Wrk2APIServiceImpl) Register(ctx context.Context, firstName string, lastName string, username string, password string, userId int64) error

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Unfollow
func (w *Wrk2APIServiceImpl) Unfollow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error

Implements Wrk2APIService interface

Generated by gomarkdoc

Documentation

Index

Constants

View Source
const (
	POST int64 = iota
	REPOST
	REPLY
	DM
)

Enums aren't supported atm. So just use integers instead.

Variables

This section is empty.

Functions

Types

type ComposePostService

type ComposePostService interface {
	// Compose a post from the provided arguments
	ComposePost(ctx context.Context, reqID int64, username string, userID int64, text string, mediaIDs []int64, mediaTypes []string, postType int64) (int64, []int64, error)
}

The ComposePostService interface

func NewComposePostServiceImpl

func NewComposePostServiceImpl(ctx context.Context, postStorageService PostStorageService, userTimelineService UserTimelineService, userService UserService, uniqueIDService UniqueIdService, mediaService MediaService, textService TextService, homeTimelineService HomeTimelineService) (ComposePostService, error)

Creates a ComposePostService instance that creates a post from the provided arguments and connects to the various internal services to store the newly created post and update the state.

type ComposePostServiceImpl

type ComposePostServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of ComposePostService

func (*ComposePostServiceImpl) ComposePost

func (c *ComposePostServiceImpl) ComposePost(ctx context.Context, reqID int64, username string, userID int64, text string, mediaIDs []int64, mediaTypes []string, postType int64) (int64, []int64, error)

ComposePost implements ComposePostService

type Creator

type Creator struct {
	UserID   int64
	Username string
}

The format of a creator stored as part of a post

type FolloweeInfo

type FolloweeInfo struct {
	FolloweeID int64
	Timestamp  int64
}

The format of a followee's info stored in the user info in the social-graph

type FollowerInfo

type FollowerInfo struct {
	FollowerID int64
	Timestamp  int64
}

The format of a follower's info stored in the user info in the social-graph

type HomeTimelineService

type HomeTimelineService interface {
	// Reads the timeline of the user that has the id `userID`.
	// The return value is represented by the slice: post_ids[start:stop].
	ReadHomeTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)
	// Adds a new post to the home timeline of the following users:
	// (i)   user with id `userID`,
	// (ii)  all the followers of the user with `userID`
	// (iii) all the mentioned users in the post listed in the `userMentionIDs`.
	// The new post ID is placed at the nth position in the post ids array.
	//    post_ids = append(post_ids, `postID`)
	WriteHomeTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64, userMentionIDs []int64) error
}

The HomeTimelineService Interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].

func NewHomeTimelineServiceImpl

func NewHomeTimelineServiceImpl(ctx context.Context, homeTimelineCache backend.Cache, postStorageService PostStorageService, socialGraphService SocialGraphService) (HomeTimelineService, error)

Creates a HomeTimelineService instance that maintains the home timelines for the various users.

type HomeTimelineServiceImpl

type HomeTimelineServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of HomeTimelineService

func (*HomeTimelineServiceImpl) ReadHomeTimeline

func (h *HomeTimelineServiceImpl) ReadHomeTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)

Implements HomeTimelineService interface

func (*HomeTimelineServiceImpl) WriteHomeTimeline

func (h *HomeTimelineServiceImpl) WriteHomeTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64, userMentionIDs []int64) error

Implements HomeTimelineService interface

type LoginObj

type LoginObj struct {
	UserID   int64
	Password string
	Salt     string
}

The format of a Login object.

type Media

type Media struct {
	MediaID   int64
	MediaType string
}

The format of a media stored as part of a post.

type MediaService

type MediaService interface {
	// Creates and returns a list of Media objects from the provided `mediaTypes` and `mediaIds` arguments.
	// Returns an error if the length of mediaTypes and mediaIds do not match.
	ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error)
}

The MediaService interface

func NewMediaServiceImpl

func NewMediaServiceImpl(ctx context.Context) (MediaService, error)

Creates a MediaService instance that creates media objects

type MediaServiceImpl

type MediaServiceImpl struct{}

Implementation of MediaService

func (*MediaServiceImpl) ComposeMedia

func (m *MediaServiceImpl) ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error)

Implements MediaService interface

type Post

type Post struct {
	PostID       int64
	Creator      Creator
	ReqID        int64
	Text         string
	UserMentions []UserMention
	Medias       []Media
	Urls         []URL
	Timestamp    int64
	PostType     int64
}

type PostInfo

type PostInfo struct {
	PostID    int64
	Timestamp int64
}

The format of a single post in a user's timeline stored in the backend.

type PostStorageService

type PostStorageService interface {
	// Stores a new `post` in the relevant backends.
	StorePost(ctx context.Context, reqID int64, post Post) error
	// Returns the post with id `postID`
	// If no post with id `postID` exists in the database, an error is returned.
	ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)
	// Returns a list of posts that have ids in the array `postIDs`.
	// No error is thrown if no post is found.
	ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error)
}

The PostStorageService interface

func NewPostStorageServiceImpl

func NewPostStorageServiceImpl(ctx context.Context, postStorageCache backend.Cache, postStorageDB backend.NoSQLDatabase) (PostStorageService, error)

Creates a PostStorageService instance that manages the post backends.

type PostStorageServiceImpl

type PostStorageServiceImpl struct {
	CacheHits int64
	NumReqs   int64
	CacheMiss int64
	// contains filtered or unexported fields
}

Implementation of PostStorageService

func (*PostStorageServiceImpl) ReadPost

func (p *PostStorageServiceImpl) ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)

Implements PostStorageService interface

func (*PostStorageServiceImpl) ReadPosts

func (p *PostStorageServiceImpl) ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error)

Implements PostStorageService interface

func (*PostStorageServiceImpl) StorePost

func (p *PostStorageServiceImpl) StorePost(ctx context.Context, reqID int64, post Post) error

Implements PostStorageService interface

type PostType

type PostType int64

The type of the post.

type SocialGraphService

type SocialGraphService interface {
	// Returns the user IDs of all the followers of the user with user id `userID`.
	// Returns an error if user with `userID` doesn't exist in database.
	GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)
	// Returns the user IDs of all the followees of the user with user id `userID`.
	// Returns an error if user with `userID` doesn't exist in database.
	GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)
	// Creates a follower-followee relationship between users with IDs `userID`-`followeeID`.
	Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
	// Removes the follower-followee relationship between users with IDs `userID`-`followeeID`.
	Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
	// Creates a follower-followee relationship between users with usernames `userUsername`-`followeeUsername`.
	FollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error
	// Removes the follower-followee relationship between users with usernames `userUsername`-`followeeUsername`.
	UnfollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error
	// Inserts a new user with `userID` in the database.
	InsertUser(ctx context.Context, reqID int64, userID int64) error
}

The SocialGraphService interface

func NewSocialGraphServiceImpl

func NewSocialGraphServiceImpl(ctx context.Context, socialGraphCache backend.Cache, socialGraphDB backend.NoSQLDatabase, userIDService UserIDService) (SocialGraphService, error)

Creates a SocialGraphService instance that maintains the social graph backends.

type SocialGraphServiceImpl

type SocialGraphServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of SocialGraphService

func (*SocialGraphServiceImpl) Follow

func (s *SocialGraphServiceImpl) Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) FollowWithUsername

func (s *SocialGraphServiceImpl) FollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) GetFollowees

func (s *SocialGraphServiceImpl) GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) GetFollowers

func (s *SocialGraphServiceImpl) GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) InsertUser

func (s *SocialGraphServiceImpl) InsertUser(ctx context.Context, reqID int64, userID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) Unfollow

func (s *SocialGraphServiceImpl) Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error

Implements SocialGraphService interface

func (*SocialGraphServiceImpl) UnfollowWithUsername

func (s *SocialGraphServiceImpl) UnfollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error

Implements SocialGraphService interface

type TextService

type TextService interface {
	// Parses the raw `text` to return an edited text with the urls replaced with shortened urls, usermention objects to be stored with the post, and the url objects to be stored with the post.
	ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error)
}

The TextService interface

func NewTextServiceImpl

func NewTextServiceImpl(ctx context.Context, urlShortenService UrlShortenService, userMentionService UserMentionService) (TextService, error)

Creates a TextService instance for parsing texts in created posts.

type TextServiceImpl

type TextServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of TextService

func (*TextServiceImpl) ComposeText

func (t *TextServiceImpl) ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error)

Implements TextService interface

type URL

type URL struct {
	ShortenedUrl string
	ExpandedUrl  string
}

The format of a url stored in the url-shorten database

type UniqueIdService

type UniqueIdService interface {
	// Returns a newly generated unique id to be used as a post's unique identifier.
	ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error)
}

The UniqueIdService interface

func NewUniqueIdServiceImpl

func NewUniqueIdServiceImpl(ctx context.Context) (UniqueIdService, error)

Implements UniqueIdService interface

type UniqueIdServiceImpl

type UniqueIdServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of UserTimelineService

func (*UniqueIdServiceImpl) ComposeUniqueId

func (u *UniqueIdServiceImpl) ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error)

Implements UniqueIdService interface

type UrlShortenService

type UrlShortenService interface {
	// Converts raw `urls` into shortened urls to be used within the application. Returns the list of shortened urls.
	ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error)
	// Converts the list of shortened urls into their extended forms.
	GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error)
}

The UrlShortenService interface

func NewUrlShortenServiceImpl

func NewUrlShortenServiceImpl(ctx context.Context, urlShortenDB backend.NoSQLDatabase) (UrlShortenService, error)

Creates a UrlShortenService instance for converting raw urls to shortened urls and vice versa.

type UrlShortenServiceImpl

type UrlShortenServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of UrlShortenService

func (*UrlShortenServiceImpl) ComposeUrls

func (u *UrlShortenServiceImpl) ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error)

Implements ComposeUrls interface

func (*UrlShortenServiceImpl) GetExtendedUrls

func (u *UrlShortenServiceImpl) GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error)

Implements UrlShortenService interface. Currently not implemented as the original DSB application doesn't implement this function either.

type User

type User struct {
	UserID    int64
	FirstName string
	LastName  string
	Username  string
	PwdHashed string
	Salt      string
}

The format of a user stored in the user database

type UserIDService

type UserIDService interface {
	// Returns the userID of the user associated with the `username`.
	// Returns an error if no user exists with the given `username`.
	GetUserId(ctx context.Context, reqID int64, username string) (int64, error)
}

The UserIDService interface

func NewUserIDServiceImpl

func NewUserIDServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserIDService, error)

Creates a UserIDService instance for looking up users with usernames.

type UserIDServiceImpl

type UserIDServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of UserIDService

func (*UserIDServiceImpl) GetUserId

func (u *UserIDServiceImpl) GetUserId(ctx context.Context, reqID int64, username string) (int64, error)

Implements UserIDService interface

type UserInfo

type UserInfo struct {
	UserID    int64
	Followers []FollowerInfo
	Followees []FolloweeInfo
}

The format of a user's info stored in the social-graph

type UserMention

type UserMention struct {
	UserID   int64
	Username string
}

The format of a usermention stored as part of a post

type UserMentionService

type UserMentionService interface {
	// Composes UserMention objects to be stored in a post by converting raw usernames.
	// Returns an error if any name in the `usernames` array is not registered.
	ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error)
}

The UserMentionService interface

func NewUserMentionServiceImpl

func NewUserMentionServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserMentionService, error)

Creates a UserMentionService instance that is responsible for converting usernames to usermention objects

type UserMentionServiceImpl

type UserMentionServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of UserMentionService

func (*UserMentionServiceImpl) ComposeUserMentions

func (u *UserMentionServiceImpl) ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error)

Implements the UserMentionService interface

type UserPosts

type UserPosts struct {
	UserID int64
	Posts  []PostInfo
}

The format of a user's timeline stored in the backend.

type UserService

type UserService interface {
	// Logs in a user using the user's `username` and `password`
	// Returns an error if the username is not registered or if the provided password doesn't match the stored password.
	Login(ctx context.Context, reqID int64, username string, password string) (string, error)
	// Registers a new user with a given `userID`.
	// Returns an error if the `userID` is already taken.
	RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string, userID int64) error
	// Registers a new user. A random `userID` is generated by the service.
	RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string) error
	// Creates and returns a creator object to be included in a Post. The Creator object is created using the `userID`.
	ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)
	// Creates and returns a creator object to be included in a Post. The service looks up the userID of the user with the given `username`.
	// Returns an error if the user with the given `username` is not registered.
	ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)
}

The UserService interface

func NewUserServiceImpl

func NewUserServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase, socialGraphService SocialGraphService, secret string) (UserService, error)

Implementation of UserService

type UserServiceImpl

type UserServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of UserService

func (*UserServiceImpl) ComposeCreatorWithUserId

func (u *UserServiceImpl) ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)

Implements UserService interface

func (*UserServiceImpl) ComposeCreatorWithUsername

func (u *UserServiceImpl) ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)

Implements UserService interface

func (*UserServiceImpl) Login

func (u *UserServiceImpl) Login(ctx context.Context, reqID int64, username string, password string) (string, error)

Implements UserService interface

func (*UserServiceImpl) RegisterUser

func (u *UserServiceImpl) RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string) error

Implements UserService interface

func (*UserServiceImpl) RegisterUserWithId

func (u *UserServiceImpl) RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string, userID int64) error

Implements UserService interface

type UserTimelineService

type UserTimelineService interface {
	// Reads the timeline of the user that has the id `userID`.
	// The return value is represented by the slice: post_ids[start:stop].
	ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)
	// Adds a new post to the user timeline of the user that has the id `userID`
	// The new post ID is placed at the 0th position in the post ids array.
	//    post_ids = []int64{`postID`, post_ids...)
	WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error
}

The UserTimelineService interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].

func NewUserTimelineServiceImpl

func NewUserTimelineServiceImpl(ctx context.Context, userTimelineCache backend.Cache, userTimelineDB backend.NoSQLDatabase, postStorageService PostStorageService) (UserTimelineService, error)

Creates a UserTimelineService instance for managing the user timelines for the various users.

type UserTimelineServiceImpl

type UserTimelineServiceImpl struct {
	CacheHits   int64
	CacheMiss   int64
	NumRequests int64
	// contains filtered or unexported fields
}

Implementation of UserTimelineService

func (*UserTimelineServiceImpl) ReadUserTimeline

func (u *UserTimelineServiceImpl) ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)

Implements UserTimelineService interface

func (*UserTimelineServiceImpl) WriteUserTimeline

func (u *UserTimelineServiceImpl) WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error

Implements UserTimelineService interface

type Wrk2APIService

type Wrk2APIService interface {
	// Reads the home timeline of the user with `userId`.
	// Returns the list of posts[start, stop] from the timeline.
	ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
	// Reads the user timeline of the user with `userId`.
	// Returns the list of posts[start, stop] from the timeline.
	ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
	// Creates a Follow-Link between users `userId`-`followeeID`.
	// If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`.
	// Returns an error if no pairs are provided.
	Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error
	// Removes a Follow-Link between users `userId`-`followeeID`.
	// If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`.
	// Returns an error if no pairs are provided.
	Unfollow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error
	// Registers a new user with the given `userId`.
	Register(ctx context.Context, firstName string, lastName string, username string, password string, userId int64) error
	// Composes a new post give the provided arguments.
	// Returns the created post's ID and the ids of the mentioned users.
	ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error)
}

The Wrk2APIService (Frontend) interface

func NewWrk2APIServiceImpl

func NewWrk2APIServiceImpl(ctx context.Context, userService UserService, composePostService ComposePostService, userTimelineService UserTimelineService, homeTimelineService HomeTimelineService, socialGraphService SocialGraphService) (Wrk2APIService, error)

Creates a Wrk2APIService instance to act as the gateway to internal services.

type Wrk2APIServiceImpl

type Wrk2APIServiceImpl struct {
	// contains filtered or unexported fields
}

Implementation of Wrk2APIService

func (*Wrk2APIServiceImpl) ComposePost

func (w *Wrk2APIServiceImpl) ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Follow

func (w *Wrk2APIServiceImpl) Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) ReadHomeTimeline

func (w *Wrk2APIServiceImpl) ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) ReadUserTimeline

func (w *Wrk2APIServiceImpl) ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Register

func (w *Wrk2APIServiceImpl) Register(ctx context.Context, firstName string, lastName string, username string, password string, userId int64) error

Implements Wrk2APIService interface

func (*Wrk2APIServiceImpl) Unfollow

func (w *Wrk2APIServiceImpl) Unfollow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error

Implements Wrk2APIService interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL