model

package
v0.0.0-...-f5986cb Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package model contains all model structures.

Index

Constants

View Source
const (
	// AccessTokenCollectionName is a collection name for access tokens.
	AccessTokenCollectionName = "accesstokens"

	// AccessTokenScopeAudio is a scope required for
	// an "/audio/:id" route.
	AccessTokenScopeAudio = "audio"

	// AccessTokenScopeInfo is a scope required for
	// the rest of "/api/:method" routes
	AccessTokenScopeInfo = "info"
)
View Source
const (
	// AuthorCollectionName is a collection name for authors.
	AuthorCollectionName = "authors"

	// AuthorSortName is a sorting parameter for authors filter route.
	AuthorSortName = "name"

	// AuthorSortDate is a sorting parameter for authors filter route.
	AuthorSortDate = "date"

	// AuthorSortRatingAverage is a sorting parameter for authors filter route.
	AuthorSortRatingAverage = "rating_average"

	// AuthorSortRatingCount is a sorting parameter for authors filter route.
	AuthorSortRatingCount = "rating_count"

	// AuthorFilterTypeFavorite is a filter type for authors filter route.
	AuthorFilterTypeFavorite = "favorite"

	//AuthorFilterTypeFavoriteCategories is a filter type for authors filter route.
	AuthorFilterTypeFavoriteCategories = "favorite_categories"
)
View Source
const (
	// CategoryCollectionName is a collection name for authors.
	CategoryCollectionName = "storycategories"

	// CategorySortTitle is a sorting parameter for categories filter route.
	CategorySortTitle = "title"

	// CategorySortRatingAverage is a sorting parameter for categories filter route.
	CategorySortRatingAverage = "rating_average"

	// CategorySortRatingCount is a sorting parameter for categories filter route.
	CategorySortRatingCount = "rating_count"

	// CategoryFilterTypeFavorite is a filter type for categories filter route.
	CategoryFilterTypeFavorite = "favorite"
)
View Source
const (
	// ContentTypeAuthor is a content type constant for authors.
	ContentTypeAuthor = "author"

	// ContentTypeCategory is a content type constant for categories.
	ContentTypeCategory = "category"

	// ContentTypeStory is a content type constant for stories.
	ContentTypeStory = "story"

	// ContentActionFavorite is an action for mark content as a favorite.
	ContentActionFavorite = "favorite"

	// ContentActionFavoriteRemove is an action for unmark content as a favorite.
	ContentActionFavoriteRemove = "favorite_remove"

	// ContentActionListened is an action for mark content as a listened.
	ContentActionListened = "listened"

	// ContentActionListenedRemove is an action for unmark content as a listened.
	ContentActionListenedRemove = "listened_remove"

	// ContentSortAsc is a sorting type constant (ascending).
	ContentSortAsc = "asc"

	// ContentSortDesc is a sorting type constant (descending).
	ContentSortDesc = "desc"

	// MinRating for any content
	MinRating byte = 1

	// MaxRating for any content
	MaxRating byte = 5
)
View Source
const (
	// StoryCollectionName is a collection name for stories.
	StoryCollectionName = "stories"

	// StorySortTypeTitle is a sorting parameter for stories filter route.
	StorySortTypeTitle = "title"

	// StorySortTypeDuration is a sorting parameter for stories filter route.
	StorySortTypeDuration = "duration"

	// StorySortTypeDate is a sorting parameter for stories filter route.
	StorySortTypeDate = "date"

	// StorySortTypeRatingAverage is a sorting parameter for stories filter route.
	StorySortTypeRatingAverage = "rating_average"

	// StorySortTypeRatingCount is a sorting parameter for stories filter route.
	StorySortTypeRatingCount = "rating_count"

	// StoryFilterTypeListened is a filter type for stories filter route.
	StoryFilterTypeListened = "listened"

	// StoryFilterTypeNotListened is a filter type for stories filter route.
	StoryFilterTypeNotListened = "not_listened"

	// StoryFilterTypeFavorite is a filter type for stories filter route.
	StoryFilterTypeFavorite = "favorite"

	// StoryFilterTypeFavoriteAuthors is a filter type for stories filter route.
	StoryFilterTypeFavoriteAuthors = "favorite_authors"

	// StoryFilterTypeFavoriteCategories is a filter type for stories filter route.
	StoryFilterTypeFavoriteCategories = "favorite_categories"
)
View Source
const (
	// RatingCollectionName is a collection name for rating actions items.
	RatingCollectionName = "ratingitems"
)
View Source
const (
	// UserCollectionName is a collection name for users.
	UserCollectionName = "users"
)

Variables

AuthorFilterTypes contains all filter types for authors filter route.

AuthorSortCategories contains all sort parameters for authors filter route.

View Source
var CategoryFilterTypes = []string{CategoryFilterTypeFavorite}

CategoryFilterTypes contains all sort parameters for categories filter route.

CategorySortCategories contains all sort parameters for categories filter route.

ContentActions contains all available content actions.

View Source
var ContentSortTypes = []string{ContentSortAsc, ContentSortDesc}

ContentSortTypes contains all available sorting types.

ContentTypes contains all available content types.

View Source
var RegExpAuthorID = regexp.MustCompile("[a-zA-Z_0-9\\-]{2,36}")

RegExpAuthorID is a regexp for authors ids.

View Source
var RegExpAuthorName = regexp.MustCompile("[a-zA-Z_0-9 а-яА-ЯёЁ\\-—!?(),.:]{2,36}")

RegExpAuthorName is a regexp for authors names.

View Source
var RegExpCategoryID = regexp.MustCompile("[a-zA-Z_0-9\\-]{2,36}")

RegExpCategoryID is a regexp for categories ids.

View Source
var RegExpStoryID = regexp.MustCompile("[a-zA-Z0-9\\-_]+")

RegExpStoryID is a regexp for stories ids.

StoryFilterTypes contains all filter types for stories filter route.

StorySortCategories contains all sort parameters for stories filter route.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token  string    `json:"access_token" bson:"_id"`
	User   string    `json:"user"         bson:"user"`
	Date   time.Time `json:"date"         bson:"date"`
	Scopes []string  `json:"scopes"       bson:"scopes"`
}

AccessToken is an access token structure.

type AccountMarkContentBody

type AccountMarkContentBody struct {
	ID     *string `json:"id"     binding:"required"`
	Type   *string `json:"type"   binding:"required"`
	Action *string `json:"action" binding:"required"`
}

AccountMarkContentBody is a request body structure for "account.markContent" route.

type AccountRateContentBody

type AccountRateContentBody struct {
	ID     *string `json:"id"     binding:"required"`
	Type   *string `json:"type"   binding:"required"`
	Rating *byte   `json:"rating" binding:"required"`
}

AccountRateContentBody is a request body structure for "account.rateContent" route.

type AuthRefreshBody

type AuthRefreshBody struct {
	User         *string `json:"user"          binding:"required"`
	ClientID     *string `json:"client_id"     binding:"required"`
	ClientSecret *string `json:"client_secret" binding:"required"`
	RefreshToken *string `json:"refresh_token" binding:"required"`
}

AuthRefreshBody is a request body structure for "/auth/refresh" route.

type AuthVkBody

type AuthVkBody struct {
	ClientID     *string   `json:"client_id"     binding:"required"`
	ClientSecret *string   `json:"client_secret" binding:"required"`
	VkCode       *string   `json:"vk_code"       binding:"required"`
	Scopes       *[]string `json:"scopes"        binding:"required"`
}

AuthVkBody is a request body structure for "/auth/vk" route.

type Author

type Author struct {
	ID           string    `json:"id"            bson:"_id"`
	Name         string    `json:"name"          bson:"name"`
	Photo        string    `json:"photo"         bson:"photo"`
	Description  string    `json:"description"   bson:"description"`
	Date         time.Time `json:"date"          bson:"date"`
	Categories   []string  `json:"categories"    bson:"categories"`
	Rating       Rating    `json:"rating"        bson:"rating"`
	StoriesCount int64     `json:"stories_count"`
}

Author is an author structure.

type Category

type Category struct {
	ID           string `json:"id"     bson:"_id"`
	Title        string `json:"title"  bson:"title"`
	Image        string `json:"image"  bson:"image"`
	Rating       Rating `json:"rating" bson:"rating"`
	StoriesCount int64  `json:"stories_count"`
}

Category is a story category structure.

type ContentUserMetaInfo

type ContentUserMetaInfo struct {
	Favorite bool                       `json:"favorite,omitempty"`
	Listened bool                       `json:"listened,omitempty"`
	Rating   *ContentUserMetaInfoRating `json:"rating,omitempty"`
}

ContentUserMetaInfo is a meta information structure for a single content item.

type ContentUserMetaInfoRating

type ContentUserMetaInfoRating struct {
	Value byte      `json:"value"`
	Date  time.Time `json:"date"`
}

ContentUserMetaInfoRating is a rating information structure for a single content item.

type CountAggregate

type CountAggregate struct {
	ID    string `json:"id" bson:"_id"`
	Count int64  `json:"count" bson:"count"`
}

CountAggregate is an information about count of items for aggregation

type ItemsWrapper

type ItemsWrapper struct {
	Items interface{}          `json:"items"`
	Count int                  `json:"count"`
	Total int64                `json:"total"`
	Meta  *ContentUserMetaInfo `json:"meta,omitempty"`
}

ItemsWrapper is a wrapper for content filter or search response.

type JwtSettings

type JwtSettings struct {
	Secret   string
	Issuer   string
	Audience string
	TTL      time.Duration
}

JwtSettings is a project JWT settings structure, mapped from a config.

type NightStoryJwtClaims

type NightStoryJwtClaims struct {
	User string `json:"user"`
	jwt.StandardClaims
}

NightStoryJwtClaims is a token JWT claims structure.

func (NightStoryJwtClaims) VerifyUser

func (cl NightStoryJwtClaims) VerifyUser(db *mongo.Database) (*User, bool)

VerifyUser returns true if "user" from a token is exists, false otherwise even in case of an error.

type Rating

type Rating struct {
	Average float64 `json:"average" bson:"average"`
	Count   int     `json:"count"   bson:"count"`
}

Rating is a structure for a rating info for content.

type RatingItem

type RatingItem struct {
	User        string    `json:"user"         bson:"user"`
	ContentID   string    `json:"content_id"   bson:"content_id"`
	ContentType string    `json:"content_type" bson:"content_type"`
	Date        time.Time `json:"date"         bson:"date"`
	Rating      byte      `json:"rating"       bson:"rating"`
}

RatingItem is a structure with information about a content rate action.

type RefreshToken

type RefreshToken struct {
	Token  string    `json:"refresh_token" bson:"_id"`
	User   string    `json:"user"          bson:"user"`
	Date   time.Time `json:"date"          bson:"date"`
	Scopes []string  `json:"scopes"        bson:"scopes"`
}

RefreshToken is a refresh token structure.

type Story

type Story struct {
	ID             string    `json:"id"                bson:"_id"`
	Title          string    `json:"title"             bson:"title"`
	Authors        []string  `json:"authors"           bson:"authors"`
	Duration       int       `json:"duration"          bson:"duration"`
	Date           time.Time `json:"date"              bson:"date"`
	YouTubeVideoID string    `json:"youtube_video_id"  bson:"youtube_video_id"`
	Image          string    `json:"image"             bson:"image"`
	File           string    `json:"file"              bson:"file"`
	Categories     []string  `json:"categories"        bson:"categories"`
	Rating         Rating    `json:"rating"            bson:"rating"`
	IsFavorite     bool      `json:"is_favorite"`
	IsListened     bool      `json:"is_listened"`
}

Story is a story structure.

type User

type User struct {
	ID                 string    `json:"id"                  bson:"_id"`
	FavoriteStories    []string  `json:"favorite_stories"    bson:"favorite_stories"`
	FavoriteAuthors    []string  `json:"favorite_authors"    bson:"favorite_authors"`
	FavoriteCategories []string  `json:"favorite_categories" bson:"favorite_categories"`
	ListenedStories    []string  `json:"listened_stories"    bson:"listened_stories"`
	DateReg            time.Time `json:"date_reg"            bson:"date_reg"`
	Name               string    `json:"name"                bson:"name"`
	Photo              string    `json:"photo"               bson:"photo"`
	VkToken            string    `json:"vk_token"            bson:"vk_token"`
	VkID               int       `json:"vk_id"               bson:"vk_id"`
}

User is a service user structure.

Jump to

Keyboard shortcuts

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