handlers

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package handlers Segmentify API.

Documentation for Segmentify API.

Schemes: http BasePath: / Version: 0.0.1 Contact: Dmitriy Krasnov<dk.peyuaa@gmail.com>

Consumes: - application/json

Produces: - application/json swagger:meta

Index

Constants

View Source
const (
	MaxUserID = 2147483647
)

Variables

View Source
var (
	// ErrInternalServer is an error message returned when something goes wrong
	// that do not depend on the user input
	// We don't want to expose the details of the error to the user, instead we log it
	ErrInternalServer = &GenericError{Message: "Dont worry, we are working on it!"}
)

Functions

This section is empty.

Types

type GenericError

type GenericError struct {
	Message string `json:"message"`
}

GenericError is a generic error message returned by a server

type KeySegment

type KeySegment struct{}

KeySegment is a key used for the Segment object in the context

type KeyUserSegments

type KeyUserSegments struct{}

KeyUserSegments is a key used for UserSegments object in the context

type Segments

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

Segments is a struct that defines the handlers for the segments

func NewSegments

func NewSegments(l *log.Logger, v *data.Validation, d *data.SegmentifyDB) *Segments

NewSegments returns a new Segments struct

func (*Segments) ChangeUsersSegments

func (s *Segments) ChangeUsersSegments(rw http.ResponseWriter, r *http.Request)

ChangeUsersSegments changes the segments of a user First it checks that all segments exist Then it adds the segments to the user Then it removes the segments from the user If add and delete segments contains the same segment, behavior is undefined. Don't do that.

func (*Segments) CreateSegment

func (s *Segments) CreateSegment(rw http.ResponseWriter, r *http.Request)

CreateSegment creates a new segment in the database

func (*Segments) Delete

func (s *Segments) Delete(rw http.ResponseWriter, r *http.Request)

Delete handles DELETE requests and mark segment as deleted in the database The reason why we don't delete the segment from the database is that we want to keep the history of the already used segments

func (*Segments) GetActiveSegments

func (s *Segments) GetActiveSegments(rw http.ResponseWriter, r *http.Request)

GetActiveSegments returns the active segments for the user

func (*Segments) GetBySlug

func (s *Segments) GetBySlug(rw http.ResponseWriter, r *http.Request)

GetBySlug returns a segment from the database by slug

func (*Segments) GetSegments

func (s *Segments) GetSegments(rw http.ResponseWriter, r *http.Request)

GetSegments returns the active segments from the database

func (*Segments) MiddlewareValidateSegment

func (s *Segments) MiddlewareValidateSegment(next http.Handler) http.Handler

MiddlewareValidateSegment validates the segment in the request and calls next if ok

func (*Segments) MiddlewareValidateUser

func (s *Segments) MiddlewareValidateUser(next http.Handler) http.Handler

MiddlewareValidateUser validates the user segments request and calls next if ok

func (*Segments) UserHistory

func (s *Segments) UserHistory(rw http.ResponseWriter, r *http.Request)

UserHistory returns the user's segments history for the specified period

type ValidationError

type ValidationError struct {
	Messages []string `json:"messages"`
}

ValidationError is a collection of validation error messages

Jump to

Keyboard shortcuts

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