controllers

package
v0.0.0-...-a2066d2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Unlicense Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const GUEST_ROLE = "guest"

Variables

This section is empty.

Functions

func FakeLogin

func FakeLogin(t *testing.T) (*LoginOutput, *PublicController, *gin.Engine)

Creates fake data both in the database and the returned structure that can be used in tests.

If encounters error fails the test. Database should be cleaned up manually after calling this function. Controller and router can be used in further tests

func SetupRouter

func SetupRouter(c *PublicController) *gin.Engine

We need separate function for router setup to do testing properly

func SetupTestRouter

func SetupTestRouter(t *testing.T, controller *PublicController) *gin.Engine

Types

type GuestInput

type GuestInput struct {
	Name     string `json:"name" binding:"required"`
	DeviceId *uint  `json:"device_id" binding:"required"`
}

type GuestOutput

type GuestOutput struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int64  `json:"expires_at"`
}

type LoginInput

type LoginInput struct {
	Username string `form:"username"`
	Password string `form:"password" binding:"required"`
	Email    string `form:"email"`
	DeviceId *uint  `form:"device_id" binding:"required"`
}

type LoginOutput

type LoginOutput struct {
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	ExpiresAt    int64    `json:"expires_at"`
	Roles        []string `json:"role"`
}

type PublicController

type PublicController struct {
	DB              *sql.DB
	AccessTokenCfg  models.AccessTokenCfg
	RefreshTokenCfg models.RefreshTokenCfg
	GuestServiceURL url.URL
	LoginServiceURL url.URL
	Client          models.HTTPClient
}

func NewController

func NewController(tokensConfig models.TokensCfg, servicesConfig models.ExternalServicesConfig, client models.HTTPClient, db *sql.DB) *PublicController

func SetupTestController

func SetupTestController(t *testing.T, client models.HTTPClient) *PublicController

func (*PublicController) Auth

func (p *PublicController) Auth(c *gin.Context)

Checks if token specified in Authorization header is valid

func (*PublicController) Guest

func (p *PublicController) Guest(c *gin.Context)

Guest registers new guest and returns tokens

func (*PublicController) HealthCheck

func (p *PublicController) HealthCheck(c *gin.Context)

HealthCheck checks if the server is healthy

func (*PublicController) Login

func (p *PublicController) Login(c *gin.Context)

Function that is responsible for user authorization.

In response to a successful authorization request, returns access token and refresh token, as well as the time of death of the access token

func (*PublicController) Refresh

func (p *PublicController) Refresh(c *gin.Context)

type RefreshOutput

type RefreshOutput struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int64  `json:"expires_at"`
}

Jump to

Keyboard shortcuts

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