models

package
v0.0.0-...-13cec93 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BioRx = regexp.MustCompile(`^[a-zA-Z0-9,._:;?!\x27\- ]*$`)
)

Functions

func AreTheSame

func AreTheSame(follower_id string, followed_id string) bool

func Conversion

func Conversion(id_A string, id_B string, db database.AppDatabase) (string, string, error)

func IsLikingHimself

func IsLikingHimself(photo_id string, user_id string, db database.AppDatabase) (bool, error)

func IsValidUUID

func IsValidUUID(id string) bool

Types

type Comment

type Comment struct {
	// Id of the comment
	CommentId string `json:"commentId,omitempty"`
	// Date and time of creation of the comment following RFC3339
	Created_in string `json:"created_in,omitempty"`
	// Content of the comment
	Body string `json:"body,omitempty"`
	// Username of the user that created the comment
	Author string `json:"author,omitempty"`
	// Date and time of when the comment was modified following RFC3339
	Modified_in string `json:"modified_in,omitempty"`
	// States if a comment is a reply to another comment or not
	IsReplyComment bool `json:"isReplyComment,omitempty"` // Should be removed. ParentID is enough. ParentID === ""
	// Id of the parent comment, "" if top-level comment
	ParentId string `json:"parentId,omitempty"`
	// Profile picture of the author
	Profile_pic string `json:"profile_pic,omitempty"`
}

Attributes of a comment

func (*Comment) FromDatabase

func (c *Comment) FromDatabase(comment database.Comment_db, db database.AppDatabase)

func (*Comment) IsValid

func (c *Comment) IsValid() bool

func (*Comment) ToDatabase

func (comment *Comment) ToDatabase(db database.AppDatabase) database.Comment_db

ToDatabase returns the profile in a database-compatible representation

type Photo

type Photo struct {
	PhotoId string `json:"photoId,omitempty"`
	// Date and time of creation following RFC3339
	Timestamp string `json:"timestamp,omitempty"`
	// Number of likes
	LikesCount uint32 `json:"likes_count"`
	// Number of comments
	CommentsCount uint32 `json:"comments_count"`
	// URL of the image just uploaded. | Accepting only http/https URLs and .png/.jpg/.jpeg extensions.
	Image string `json:"image,omitempty"`
	// A written description or explanation about a photo to provide more context
	Caption string `json:"caption,omitempty"`
	// Username of the user
	Username string `json:"username,omitempty"`
}

Attributes of a photo

func (*Photo) FromDatabase

func (p *Photo) FromDatabase(photo database.Photo_db, db database.AppDatabase)

func (*Photo) IsValid

func (p *Photo) IsValid() bool

IsValid checks the validity of the content. In particular, coordinates should be in their range of validity, and the status should be either FountainStatusGood or FountainStatusFaulty. Note that the ID is not checked, as fountains read from requests have zero IDs as the user won't send us the ID in that way.

func (*Photo) ToDatabase

func (photo *Photo) ToDatabase(db database.AppDatabase) database.Photo_db

ToDatabase returns the profile in a database-compatible representation

type Post

type Post struct {
	PhotoId string `json:"photoId,omitempty"`
	// Date and time of creation following RFC3339
	Timestamp string `json:"timestamp,omitempty"`
	// Number of likes
	LikesCount uint32 `json:"likes_count"`
	// Number of comments
	CommentsCount uint32 `json:"comments_count"`
	// URL of the image just uploaded. | Accepting only http/https URLs and .png/.jpg/.jpeg extensions.
	Image string `json:"image,omitempty"`
	// A written description or explanation about a photo to provide more context
	Caption string `json:"caption,omitempty"`
	// Username of the user
	Username string `json:"username,omitempty"`
	// Profile picture of the author
	Profile_pic string `json:"profile_pic,omitempty"`
}

Attributes of a photo

func (*Post) FromDatabase

func (p *Post) FromDatabase(photo database.Photo_db, db database.AppDatabase)

func (*Post) IsValid

func (p *Post) IsValid() bool

IsValid checks the validity of the content. In particular, the caption should have a max length of 150 and should match its regex. Same for the image, and the username should be smaller than 16 characters and greater or equal than 3.

func (*Post) ToDatabase

func (photo *Post) ToDatabase(db database.AppDatabase) database.Photo_db

ToDatabase returns the profile in a database-compatible representation

type Profile

type Profile struct {

	// ID of the user
	ID string `json:"user_id"`
	// Name of the user
	Username string `json:"username"`
	// Number of photos in the profile of the user
	PicturesCount uint32 `json:"pictures_count"`
	// Number of users that follow the profile
	FollowersCount uint32 `json:"followers_count"`
	// number of users that the user follows
	FollowsCount uint32 `json:"follows_count"`
	// URL of the profile picture. Accepting only http/https URLs and .png/.jpg/.jpeg extensions.
	ProfilePictureUrl string `json:"profile_picture_url,omitempty"`
	// Biography of the profile. Just allowing alphanumeric characters and basic punctuation.
	Bio string `json:"bio,omitempty"`
}

Represents the information seen in the Profile Page of a user

func (*Profile) FromDatabase

func (p *Profile) FromDatabase(profile database.Profile_db, db database.AppDatabase)

FromDatabase populates the struct with data from the database, overwriting all values. You might think this is code duplication, which is correct. However, it's "good" code duplication because it allows us to uncouple the database and API packages. Suppose we were using the "database.Fountain" struct inside the API package; in that case, we were forced to conform either the API specifications to the database package or the other way around. However, very often, the database structure is different from the structure of the REST API. Also, in this way the database package is freely usable by other packages without the assumption that structs from the database should somehow be JSON-serializable (or, in general, serializable).

func (*Profile) IsValid

func (p *Profile) IsValid() bool

IsValid checks the validity of the content. In particular, coordinates should be in their range of validity, and the status should be either FountainStatusGood or FountainStatusFaulty. Note that the ID is not checked, as fountains read from requests have zero IDs as the user won't send us the ID in that way.

func (*Profile) ToDatabase

func (profile *Profile) ToDatabase() database.Profile_db

ToDatabase returns the profile in a database-compatible representation

type Short_profile

type Short_profile struct {
	// list of username + profile picture
	S_p []Short_profile_api `json:"short_profile"`
	// condition that assess whether the logged user follow the profile
	Cond bool `json:"cond"`
}

It's shown when viewing list of followers, likers...

func (*Short_profile) FromDatabase

func (p *Short_profile) FromDatabase(profile []database.Short_profile_db, my_name string)

type Short_profile_api

type Short_profile_api struct {

	// Name of the user
	Username string `json:"username"`
	// URL of the profile picture. Accepting only http/https URLs and .png/.jpg/.jpeg extensions.
	ProfilePictureUrl string `json:"profilePictureUrl"`
}

It's shown when viewing list of followers, likers...

type Username

type Username struct {

	// Name of the user
	Username string `json:"username"`
}

func (Username) IsValid

func (u Username) IsValid() bool

Jump to

Keyboard shortcuts

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