models

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: GPL-3.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const ROLE_ADMIN = 1

const ROLE_DEV =

View Source
const ROLE_BYMER = 2
View Source
const ROLE_FOLLOWER = 3
View Source
const ROLE_VISITOR = 4

Variables

View Source
var RoleName = [5]string{
	"Author",
	"Admin",
	"Bymer",
	"Follower",
	"Visitor",
}

Functions

func ChangeAclOnPlaylist

func ChangeAclOnPlaylist(user uint, userToPromote uint, playlistId uint, role uint) map[string]interface{}

TODO(Cas où l'utilisateur dont l'acl est changé n'appartient pas à la playlist ????) TODO(Cas où le front ne peut envoyer qu'un email et pas un id) TODO(Roles sont rentré à la main dans la db, dans l'ordre croissant d'authorité (1 > 4)) TODO(Le front peut-il directement utilisé ces 'valeurs' d'autorité en dure, sans avoir besoin de les fetch dans la db ?)

func DownVoteSong

func DownVoteSong(songid uint, user uint, notifyOnUpdate func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string) map[string]interface{}

func GetDB

func GetDB() *gorm.DB

returns a handle to the DB object

func Login

func Login(email, password string) map[string]interface{}

func RefreshSongVotes

func RefreshSongVotes(userId uint, songid uint, notifyOnUpdate func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string)

func UpVoteSong

func UpVoteSong(songid uint, user uint, notifyOnUpdate func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string) map[string]interface{}

func UpdatePassword

func UpdatePassword(user uint, password string) map[string]interface{}

Types

type Account

type Account struct {
	Model
	Email             string                  `json:"email",gorm:"type:text;unique;not null"`
	Password          string                  `json:"password"`
	TokenVersion      uint                    `json:"token_version"`
	Picture           string                  `json:"picture"`
	Playlists         []Playlist              `gorm:"ForeignKey:UserId"`
	FollowedPlaylists []*Playlist             `gorm:"many2many:account_playlist"`
	Acl               []PlaylistAccessControl `gorm:"ForeignKey:UserId"`
}

a struct to rep user account

func GetUser

func GetUser(u uint) *Account

func (*Account) Create

func (account *Account) Create() map[string]interface{}

func (*Account) DeleteAccount

func (account *Account) DeleteAccount(user uint) map[string]interface{}

func (*Account) UpdateAccount

func (account *Account) UpdateAccount() map[string]interface{}

func (*Account) Validate

func (account *Account) Validate() (map[string]interface{}, bool)

Validate incoming user details...

func (*Account) ValidatePassword

func (account *Account) ValidatePassword() (map[string]interface{}, bool)

type AccountPlaylist

type AccountPlaylist struct {
	AccountId  uint `json:"account_id"`
	PlaylistId uint `json:"playlist_id"`
}

func GetFollowers

func GetFollowers(playlistId uint) []*AccountPlaylist

type Model

type Model struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Playlist

type Playlist struct {
	Model
	Name          string                  `json:"name"`
	UserId        uint                    `json:"user_id"`
	SongsNumber   int                     `json:"songs_number"`
	Songs         []Song                  `gorm:"ForeignKey:PlaylistId"`
	Follower      []*Account              `gorm:"many2many:account_playlist;"`
	FollowerCount int                     `json:"follower_count"`
	Acl           []PlaylistAccessControl `gorm:"ForeignKey:PlaylistId"`
}

func GetPlaylistById

func GetPlaylistById(u uint, filter *PlaylistFilter) *Playlist

func GetPlaylistFromSong

func GetPlaylistFromSong(song *Song) *Playlist

func (*Playlist) Create

func (playlist *Playlist) Create(user uint) map[string]interface{}

func (*Playlist) DeletePlaylist

func (playlist *Playlist) DeletePlaylist(user uint, playlistId uint, notifyOnDelete func(userId uint, playlistId uint, message string), messageOnDelete string) map[string]interface{}

func (*Playlist) Join

func (playlist *Playlist) Join(user uint, playlistId uint) map[string]interface{}

TODO(variable POST optionel pour choisir le ROLE de l'user (BYMER ou FOllOWER), BYMER by default)

func (*Playlist) LeavePlaylist

func (playlist *Playlist) LeavePlaylist(user uint, playlistId uint) map[string]interface{}

func (*Playlist) UpdatePlaylist

func (playlist *Playlist) UpdatePlaylist(user uint, playlistId uint, newPlaylist *Playlist) map[string]interface{}

func (*Playlist) Validate

func (playlist *Playlist) Validate() (map[string]interface{}, bool)

type PlaylistAccessControl

type PlaylistAccessControl struct {
	CreatedAt  time.Time
	UpdatedAt  time.Time
	UserId     uint `gorm:"unique_index:idx_user_playlist",json:"user_id"`
	PlaylistId uint `gorm:"unique_index:idx_user_playlist",json:"playlist_id"`
	RoleId     uint `json:"role_id"`
}

type PlaylistFilter

type PlaylistFilter struct {
	ShowSongs    bool
	ShowFollower bool
	ShowAcl      bool
}

type PlaylistOwned

type PlaylistOwned struct {
	Playlist
	Owned bool `json:"owned"`
}

func GetPlaylistsByUser

func GetPlaylistsByUser(user uint) []*PlaylistOwned

type Ranking

type Ranking struct {
	SongId   uint `json:"song_id"`
	VoteUp   int  `json:"vote_up"`
	VoteDown int  `json:"vote_down"`
	Score    int  `json:"score"`
}

Not a model used to hold part of the song model

func GetSongRankingById

func GetSongRankingById(songid uint) *Ranking

func GetSongsRanking

func GetSongsRanking(playlist uint) []*Ranking

type Role

type Role struct {
	ID   uint                    `gorm:"primary_key"`
	Name string                  `json:"name"`
	Acl  []PlaylistAccessControl `gorm:"ForeignKey:RoleId"`
}

func GetRole

func GetRole(user uint, playlistId uint) (*Role, string)

type Song

type Song struct {
	Model
	Name       string `json:"name"`
	PlaylistId uint   `json:"playlist_id"`
	ExternalId string `json:"external_id"`
	VoteUp     int    `json:"vote_up"`
	VoteDown   int    `json:"vote_down"`
	Score      int    `json:"score"`
	Status     string `json:"status"`
}

func (*Song) Create

func (song *Song) Create(user uint, notifyOnUpdate func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string) map[string]interface{}

func (*Song) DeleteSong

func (song *Song) DeleteSong(user uint, songId uint, notifyOnDelete func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string) map[string]interface{}

func (*Song) UpdateSong

func (song *Song) UpdateSong(user uint, songId uint, newSong *Song, notifyOnUpdate func(userId uint, playlistId uint, message string), messageOnUpdate func(playlistId uint, userId uint) string) map[string]interface{}

func (*Song) Validate

func (song *Song) Validate(user uint) (map[string]interface{}, bool)

type SongExtended

type SongExtended struct {
	Song
	PersonalVote *bool `json:"personal_vote"`
}

func GetSongs

func GetSongs(playlist uint, userId uint) []*SongExtended

type Table

type Table interface {
	Validate() (map[string]interface{}, bool)
}

type Token

type Token struct {
	UserId       uint
	TokenVersion uint
	jwt.StandardClaims
}

JWT claims struct

type Vote

type Vote struct {
	Model
	UpVote   bool `json:"up_vote"`
	DownVote bool `json:"down_vote"`
	UserId   uint `json:"user_id"`
	SongId   uint `json:"song_id"`
}

func GetPersonalVoteBySongId

func GetPersonalVoteBySongId(songid uint, user uint) *Vote

func GetVotesBySongId

func GetVotesBySongId(songid uint) []*Vote

Jump to

Keyboard shortcuts

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