controllers

package
v0.0.0-...-ad296c0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

* Create and get notes

Index

Constants

This section is empty.

Variables

View Source
var Authenticate = func(w http.ResponseWriter, r *http.Request) {

	account := &models.Account{}

	err := json.NewDecoder(r.Body).Decode(account)
	if err != nil {
		u.Respond(w, u.Message(false, "Invalid request"))
		return
	}

	resp := models.Login(account.Email, account.Password)
	u.Respond(w, resp)
}
View Source
var CreateAccount = func(w http.ResponseWriter, r *http.Request) {

	account := &models.Account{}

	err := json.NewDecoder(r.Body).Decode(account)
	if err != nil {
		u.Respond(w, u.Message(false, "Invalid request"))
		return
	}

	resp := account.Create()
	u.Respond(w, resp)
}
View Source
var CreateNote = func(w http.ResponseWriter, r *http.Request) {

	user := r.Context().Value("user").(uint)
	note := &models.Note{}

	err := json.NewDecoder(r.Body).Decode(note)
	if err != nil {
		u.Respond(w, u.Message(false, "Error while decoding request body"))
		return
	}

	note.UserId = user
	resp := note.Create()
	u.Respond(w, resp)
}
View Source
var GetNotesFor = func(w http.ResponseWriter, r *http.Request) {

	id := r.Context().Value("user").(uint)
	data := models.GetNotes(id)
	resp := u.Message(true, "success")
	resp["data"] = data
	u.Respond(w, resp)
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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