2024-06-03 17:31:25 +00:00
|
|
|
package database
|
2024-02-16 14:16:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-16 20:51:09 +00:00
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
2024-02-16 14:16:50 +00:00
|
|
|
)
|
|
|
|
|
2024-02-17 15:35:53 +00:00
|
|
|
// OtterSpace provides an interface for interacting with the OtterSpace API.
|
|
|
|
// It includes methods for connecting to the API, adding and linking users, posts, and sources,
|
|
|
|
// and retrieving information about users and posts.
|
2024-02-16 20:57:54 +00:00
|
|
|
type OtterSpace interface {
|
2024-02-17 15:35:53 +00:00
|
|
|
// Connect sets up a connection to the OtterSpace API endpoint using the provided username and password.
|
|
|
|
// It returns an error if the connection cannot be established.
|
2024-06-03 19:31:44 +00:00
|
|
|
Connect(ctx context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// AddUserWithRelationToSource adds a new user to the OtterSpace database and associates them with a source.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the newly created user and an error if the operation fails.
|
|
|
|
AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// AddSource adds a new source to the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
AddSource(ctx context.Context, anthroveSource *models.Source) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// AddPost adds a new post to the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
AddPost(ctx context.Context, anthrovePost *models.Post) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// AddTagWithRelationToPost adds a new tag to the OtterSpace database and associates it with a post.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.Tag) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.PostReference) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// LinkUserWithPost establishes a link between a user and a post in the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
LinkUserWithPost(ctx context.Context, anthroveUser *models.User, anthrovePost *models.Post) error
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// CheckUserPostLink checks if a link between a user and a post exists in the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns true if the link exists, false otherwise, and an error if the operation fails.
|
2024-02-16 22:11:42 +00:00
|
|
|
CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace database by its Anthrove ID.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.Post) (*models.Post, bool, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// CheckPostNodeExistsBySourceURL checks if a post node exists in the OtterSpace database by its source URL.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.Post, bool, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace database by its source ID.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.Post, bool, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// GetUserFavoriteCount retrieves the count of a user's favorite posts from the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the count and an error if the operation fails.
|
2024-02-16 20:28:26 +00:00
|
|
|
GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// GetUserSourceLinks retrieves the links between a user and sources in the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.UserSource, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// GetSpecifiedUserSourceLink GetUserSourceLinks retrieves the links between a user and a specific source in the OtterSpace database.
|
2024-05-04 22:17:18 +00:00
|
|
|
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.UserSource, error)
|
2024-05-04 22:17:18 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// GetAnthroveUser retrieves a user from the OtterSpace database by their ID.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns the user and an error if the operation fails.
|
2024-06-22 20:06:36 +00:00
|
|
|
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.User, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
|
2024-06-03 17:31:25 +00:00
|
|
|
// GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace database.
|
2024-02-17 15:35:53 +00:00
|
|
|
// It returns a slice of user IDs and an error if the operation fails.
|
2024-02-16 14:16:50 +00:00
|
|
|
GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error)
|
2024-05-10 08:57:51 +00:00
|
|
|
|
2024-05-15 09:18:01 +00:00
|
|
|
// GetUserFavoritePostsWithPagination gets all user favorites with relation and sources for the given user
|
2024-06-22 20:06:36 +00:00
|
|
|
GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error)
|
2024-05-15 13:18:23 +00:00
|
|
|
|
|
|
|
// GetUserTagsTroughFavedPosts returns a list of Tags that the user hs favorites through a post
|
2024-06-22 20:06:36 +00:00
|
|
|
GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error)
|
2024-05-15 13:31:17 +00:00
|
|
|
|
|
|
|
// GetAllTags returns a list of Tags that the user hs favorites through a post
|
2024-06-22 20:06:36 +00:00
|
|
|
GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error)
|
2024-05-15 13:44:34 +00:00
|
|
|
|
|
|
|
// GetAllSources returns a list of Sources in the database
|
2024-06-22 20:06:36 +00:00
|
|
|
GetAllSources(ctx context.Context) ([]models.Source, error)
|
2024-05-21 09:48:03 +00:00
|
|
|
|
|
|
|
// GetSourceByURL returns the Source Node based on the URL
|
2024-06-22 20:06:36 +00:00
|
|
|
GetSourceByURL(ctx context.Context, sourceUrl string) (*models.Source, error)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|