server

package
v0.0.0-...-934788e Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID       string `json:"fuser_id"`
	Time     int64  `json:"time"`
	Item     string `json:"item"`
	Calories int    `json:"calories"`
}

Entry : Describes an entry in our "Entries" table

type Server

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

Server : Contains the app's database and offers an interface to interact with it.

func New

func New(cfg *config.EnvConfig) *Server

New : Instantiate server

func (*Server) AddEntry

func (s *Server) AddEntry(entry Entry) error

AddEntry : add an entry to the database

func (*Server) AddUser

func (s *Server) AddUser(user User) error

AddUser : insert user into database

func (*Server) GetEntries

func (s *Server) GetEntries(id string) (*[]Entry, error)

GetEntries : return a list of entries from a Users table

func (*Server) GetUser

func (s *Server) GetUser(id string) (*User, error)

GetUser : return a user from a Users table based on a given id

func (*Server) GetUsersInTimezone

func (s *Server) GetUsersInTimezone(tz int) (*map[*User]int, error)

GetUsersInTimezone : return all users in given timezone Returns a map with Users as keys and their total event calories as values Example usage:

	users, _ := b.server.GetUsersInTimezone(-8)
 for u, v := range *users {
		// do things
	}

func (*Server) SumCalories

func (s *Server) SumCalories(id string) (int, error)

SumCalories : return sum of calories from entries for specific user Example usage:

calories, _ := b.server.SumCalories(c.facebookID)
log.Print(strconv.Itoa(calories))

func (*Server) UpdateUserTimezone

func (s *Server) UpdateUserTimezone(user User) error

UpdateUserTimezone updates the timezone value of the given user

type ServerLayer

type ServerLayer interface {
	AddUser(User) error
	AddEntry(Entry) error
	GetUser(string) (*User, error)
	GetUsersInTimezone(int) (*map[*User]int, error)
	GetEntries(string) (*[]Entry, error)
	SumCalories(string) (int, error)
	UpdateUserTimezone(User) error
}

ServerLayer : Interface to interact with database

type User

type User struct {
	ID       string `json:"user_id"`
	MaxCal   int    `json:"max_cal"`
	Timezone int    `json:"timezone"`
	Name     string `json:"name"`
}

User : Describes an entry in our "Users" table

Jump to

Keyboard shortcuts

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