data

package
v0.0.0-...-bc5bc59 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const UserIdKey string = "user_id"

Variables

This section is empty.

Functions

func AuthUserId

func AuthUserId(tokenString string) (uint64, error)

func GetBearerToken

func GetBearerToken(r *http.Request) (string, error)

func GetSchema

func GetSchema(db Database) *graphql.Schema

func HandleTodoistCallback

func HandleTodoistCallback(db Database) http.Handler

func HandleTodoistLogin

func HandleTodoistLogin(db Database) http.Handler

func Login

func Login(db Database, username string, password string) (string, error)

func ServeCreateUser

func ServeCreateUser(db Database) func(rest.ResponseWriter, *rest.Request)

func ServeLogin

func ServeLogin(db Database) func(rest.ResponseWriter, *rest.Request)

func ServeVerifyToken

func ServeVerifyToken(db Database) func(rest.ResponseWriter, *rest.Request)

func SyncTodoist

func SyncTodoist(db Database, userId uint64, oauthToken string) error

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	AccessToken string `json:"access_token"`
	Error       string `json:"error"`
}

type Action

type Action struct {
	Id     string     `json:"id" gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	Kind   ActionKind `json:"kind" gorm:"not_null"`
	When   *time.Time `json:"when" gorm:"not_null"`
	TaskId string     `json:"task_id" gorm:"not_null;type:uuid"`
}

type ActionKind

type ActionKind int
const (
	ActionProgress ActionKind = iota
	ActionDefer
	ActionDone
)

type Database

type Database interface {
	Close() error
	GetTask(taskId string, userId uint64, kind *TaskKind) (*Task, error)
	GetTasks(userId uint64, kind *TaskKind) ([]Task, error)
	AddTask(task *Task, userId uint64) error
	DeleteTask(taskId string, userId uint64) (bool, error)
	UpdateTask(taskId string, userId uint64, attrs map[string]interface{}) (*Task, error)
	CreateUser(username string, password string) (*User, error)
	GetUserById(id uint64) (*User, error)
	GetUserByUsername(username string) (*User, error)
	AddAction(action *Action, userId uint64) error
	DeleteAction(id string, userId uint64) error
}

func InitDatabase

func InitDatabase(dialect string, host string, user string, dbName string) Database

type DuetClaims

type DuetClaims struct {
	jwt.StandardClaims
}

func VerifyToken

func VerifyToken(tokenString string) (*DuetClaims, error)

type Interval

type Interval int
const (
	Daily Interval = iota
	Weekly
	Monthly
)

type Task

type Task struct {
	// Common fields
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt *time.Time
	Id        string   `json:"id" gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	Kind      TaskKind `json:"kind" gorm:"not_null"`
	Title     string   `json:"title" gorm:"not_null"`
	Done      bool     `json:"done" gorm:"not_null;default:false"`
	UserId    uint64   `json:"user_id" gorm:"not_null"`
	Actions   []Action `json:"actions" gorm:"ForeignKey:TaskId"`
	// Task Fields
	StartDate *time.Time `json:"start_date"`
	EndDate   *time.Time `json:"end_date"`
	// Habit Fields
	Interval  Interval `json:"interval"`
	Frequency int      `json:"frequency"`
}

type TaskKind

type TaskKind int
const (
	TaskEnum TaskKind = iota
	HabitEnum
)

type TodoistItem

type TodoistItem struct {
	Title   string `json:"content"`
	DueDate string `json:"due_date_utc"` // in format "Mon 07 Aug 2006 12:34:56 +0000"
	Checked int    `json:checked`        // 1 is true, 0 is false
}

type TodoistSync

type TodoistSync struct {
	SyncToken string        `json:"sync_token"`
	Items     []TodoistItem `json:"items"`
}

type User

type User struct {
	Id             uint64 `json:"id" gorm:"primary_key"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	DeletedAt      *time.Time
	Username       string `json:"username" gorm:"not_null;unique"`
	HashedPassword []byte `json:"-" gorm:"not_null"`
	Tasks          []Task `json:"-" gorm:"ForeignKey:UserId"`
}

Jump to

Keyboard shortcuts

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