controllers

package
v0.0.0-...-606800a Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthController

type AuthController struct {
	DB               *models.StereoDoseDB
	Store            *sessions.CookieStore
	Config           *oauth2.Config
	StereodoseConfig *config.Config
}

AuthController is a collection of RESTful Handlers for authentication

func NewAuthController

func NewAuthController(db *models.StereoDoseDB, store *sessions.CookieStore, config *config.Config) *AuthController

NewAuthController takes a StereodoseDB, CookieStore, and App Config returns an AuthController

func (*AuthController) Callback

func (a *AuthController) Callback(w http.ResponseWriter, r *http.Request) error

Callback is a handler function that the user is redirected to in the OAuth flow In this step of authorization, we exchange a code for an access token and we query the user's profile on Spotify to get their identity

func (*AuthController) GetMyAccessToken

func (a *AuthController) GetMyAccessToken(w http.ResponseWriter, r *http.Request) error

GetMyAccessToken will return the Spotify Access token associated with the user's current session It probably would've have been better if I embedded this into a JWT and ditched cookies... TODO: perhaps it is better design to encapsulate the refresh logic here as well

func (*AuthController) Login

Login is the handler that you can send the user to initiate an authorization code flow

func (*AuthController) Logout

Logout ultimately deletes the user's session Since these sessions are stateless, all we have to do is set the max-age to less than 0

func (*AuthController) MobileLogin

func (a *AuthController) MobileLogin(w http.ResponseWriter, r *http.Request) error

MobileLogin is here to support the iOS app. Because Spotify basically constrains iOS developers to using only their SDK and not the WebAPI for authentication, we have to create this seperate endpoint It will take a Spotify access token, and then create a Stereodose session. The response is simply a 200 and a set-cookie header

func (*AuthController) Refresh

func (a *AuthController) Refresh(w http.ResponseWriter, r *http.Request) error

Refresh will update the Spotify API Access Token for the user's session TODO: check the refresh token and save it (it might be a new refresh token)

func (*AuthController) TokenSwap

func (a *AuthController) TokenSwap(w http.ResponseWriter, r *http.Request) error

TokenSwap was created to support the iOS app. The Spotify iOS documentation refers to a "token swap" API endpoint which is essentially the same as the OAuth callback or redirect URL. The difference here is that instead of 302 redirecting on the callback, we simply return a 200 response with the JSON returned from the Spotify code exchange

type CategoriesController

type CategoriesController struct{}

CategoriesController contains all of the Handler functions related to playlist categories. Like Weed/Chill

func NewCategoriesController

func NewCategoriesController() *CategoriesController

NewCategoriesController returns a pointer to a CategoriesController

func (*CategoriesController) GetAvailableCategories

func (c *CategoriesController) GetAvailableCategories(w http.ResponseWriter, r *http.Request) error

GetAvailableCategories sends a JSON object with available categories to use The server will deny requests to tag playlists with invalid categories

type FeedbackController

type FeedbackController struct {
	DB    *models.StereoDoseDB
	Store *sessions.CookieStore
}

FeedbackController has REST methods to perform operations on the Feedback resource

func NewFeedbackController

func NewFeedbackController(db *models.StereoDoseDB, store *sessions.CookieStore) *FeedbackController

NewFeedbackController returns a pointer to NewFeedbackController

func (*FeedbackController) CreateFeedback

func (f *FeedbackController) CreateFeedback(w http.ResponseWriter, r *http.Request) error

CreateFeedback will take a JSON payload of Feedback and write to the database The intention is that we leave off the authentication middleware because I don't want to require that users are authenticated to provide feedback But if they are, I am going to record who they are and other user-specific attributes

type Health

type Health struct {
	GoRoutines          int
	CPUs                int
	HealthyDBConnection bool
}

Health is the struct that ultimately turns into JSON output from this controller

type HealthController

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

HealthController has methods to self-examine the server's health

func NewHealthController

func NewHealthController(db *models.StereoDoseDB) *HealthController

NewHealthController returns a pointer to a HealthController

func (*HealthController) CheckHealth

func (h *HealthController) CheckHealth(w http.ResponseWriter, r *http.Request) error

CheckHealth is an AppHandler that returns the status of the app's health

type PlaylistsController

type PlaylistsController struct {
	DB     *models.StereoDoseDB
	Bucket *blob.Bucket
}

PlaylistsController is a collection of RESTful Handlers for Playlists

func NewPlaylistsController

func NewPlaylistsController(db *models.StereoDoseDB, b *blob.Bucket) *PlaylistsController

NewPlaylistsController returns a pointer to PlaylistsController

func (*PlaylistsController) Comment

Comment parses the JSON body and saves a user comment to the database the JSON body looks like this: { "text": "wow this playlist is cool" }

func (*PlaylistsController) CreatePlaylist

func (p *PlaylistsController) CreatePlaylist(w http.ResponseWriter, r *http.Request) error

CreatePlaylist reads the SpotifyID from the POST body It then calls the spotify API to get the full info and store in the local DB

func (*PlaylistsController) DeleteComment

func (p *PlaylistsController) DeleteComment(w http.ResponseWriter, r *http.Request) error

DeleteComment removes a comment from a playlist and soft deletes in the database

func (*PlaylistsController) DeletePlaylist

func (p *PlaylistsController) DeletePlaylist(w http.ResponseWriter, r *http.Request) error

DeletePlaylist takes the id variable from the url path It performs a hard delete of the playlist from the DB, but a soft delete on likes and comments Only admins may perform this operation

func (*PlaylistsController) GetMyPlaylists

func (p *PlaylistsController) GetMyPlaylists(w http.ResponseWriter, r *http.Request) error

GetMyPlaylists returns all of the playlists added to Stereodose that belong to the requesting user

func (*PlaylistsController) GetPlaylistByID

func (p *PlaylistsController) GetPlaylistByID(w http.ResponseWriter, r *http.Request) error

GetPlaylistByID reads the id variable from the url path and sends a JSON response

func (*PlaylistsController) GetPlaylists

func (p *PlaylistsController) GetPlaylists(w http.ResponseWriter, r *http.Request) error

GetPlaylists will return a subset of all the playlists in the DB based on query parameters

func (*PlaylistsController) GetRandomPlaylist

func (p *PlaylistsController) GetRandomPlaylist(w http.ResponseWriter, r *http.Request) error

GetRandomPlaylist will inspect the category and subcategory query parameters and return a Playlist filled with randomly selected tracks

func (*PlaylistsController) Like

Like will add a like to the playlist in the database Like checks to see if the user had already liked the playlist

func (*PlaylistsController) Unlike

Unlike removes a like from a playlist TODO: could improve the performance of this by looking up the Like by ID instead of searching through all of the user's likes

func (*PlaylistsController) UploadImage

func (p *PlaylistsController) UploadImage(w http.ResponseWriter, r *http.Request) error

UploadImage saves an image the corresponds to a playlist The actual data is saved to cloud bucket storage Permalinks are returned to the client. The following request (CreatePlaylist) saves the playlist along with the permalinks to the database.

type UsersController

type UsersController struct {
	DB *models.StereoDoseDB
}

UsersController contains methods for reading user data

func NewUsersController

func NewUsersController(db *models.StereoDoseDB) *UsersController

NewUsersController returns a pointer to UsersController

func (*UsersController) GetByID

GetByID grabs the user ID from the path parameter fetches from the database and returns JSON to the client

func (*UsersController) GetUserLikes

func (u *UsersController) GetUserLikes(w http.ResponseWriter, r *http.Request) error

GetUserLikes returns just an array of likes for a particular user

func (*UsersController) Me

Me returns the requesting and authenticated user's data

Jump to

Keyboard shortcuts

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