api

package
v0.0.0-...-0422bbd Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionCookie = "session"
	CookieAge     = 60 * 60 * 24 // 1 day
)

Variables

This section is empty.

Functions

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem)

func MakeHandler

func MakeHandler(mh apiHandler) http.HandlerFunc

MakeHandler is a higher-order function that wraps an apiHandler function and returns an http.HandlerFunc. Its purpose is to centralice error handling and being able to return errors from out handler functions.

It handles any errors returned by the apiHandler and logs them using slog.

Types

type AuthHandler

type AuthHandler struct {
	UserStore *db.UserStore
	// contains filtered or unexported fields
}

func NewAuthHandler

func NewAuthHandler(store *db.UserStore, decoder *schema.Decoder, emailService *models.EmailService) *AuthHandler

func (*AuthHandler) HandleAuthenticate

func (h *AuthHandler) HandleAuthenticate(w http.ResponseWriter, r *http.Request) error

func (*AuthHandler) HandleChangePassword

func (h *AuthHandler) HandleChangePassword(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleEmailToken

func (h *AuthHandler) HandleEmailToken(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleForgotPassword

func (h *AuthHandler) HandleForgotPassword(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleGetUser

func (h *AuthHandler) HandleGetUser(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleHome

func (h *AuthHandler) HandleHome(w http.ResponseWriter, r *http.Request) error

func (*AuthHandler) HandleLogin

func (h *AuthHandler) HandleLogin(w http.ResponseWriter, r *http.Request) error

func (*AuthHandler) HandleLogout

func (h *AuthHandler) HandleLogout(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleNewUser

func (h *AuthHandler) HandleNewUser(w http.ResponseWriter, r *http.Request) error

func (*AuthHandler) HandleResetPassword

func (h *AuthHandler) HandleResetPassword(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleRoot

func (h *AuthHandler) HandleRoot(w http.ResponseWriter, r *http.Request)

type TasksHandler

type TasksHandler struct {
	TaskStore db.TaskStore
	// contains filtered or unexported fields
}

func NewTasksHandler

func NewTasksHandler(store db.TaskStore, decoder *schema.Decoder) *TasksHandler

NewTasksHandler creates a new TasksHandler instance.

It takes a TaskStore as a parameter and returns a pointer to a TasksHandler.

func (*TasksHandler) HandleDeleteTask

func (h *TasksHandler) HandleDeleteTask(w http.ResponseWriter, r *http.Request)

HandleDeleteTask handles the deletion of a task. It takes the echo.Context as a parameter and returns an error.

This will delete the task and update the tasks view. If there is an error during the deletion or update, it returns an error.

func (*TasksHandler) HandleEditTask

func (h *TasksHandler) HandleEditTask(w http.ResponseWriter, r *http.Request)

HandleEditTask handles the request to edit a task. It retrieves the task ID from the URL, fetches the task from the task store, and renders the task view with the provided context and response writer. If any error occurs during the process, it returns the corresponding HTTP status code and error message.

func (*TasksHandler) HandleGetTasks

func (h *TasksHandler) HandleGetTasks(w http.ResponseWriter, r *http.Request)

HandleGetTasks handles the GET /tasks endpoint.

It fetches tasks from the task store and returns the tasks along with their count and completed count.

ctx - the echo context for handling the HTTP request and response.

Returns an error if there was a problem fetching the tasks or rendering the response.

func (*TasksHandler) HandlePostTask

func (h *TasksHandler) HandlePostTask(w http.ResponseWriter, r *http.Request)

HandlePostTask handles the POST request for creating a new task.

It takes in the echo.Context object as a parameter. Adds a task to the database and displays a response message. It returns an error if there was an issue handling the request.

func (*TasksHandler) HandlePutTask

func (h *TasksHandler) HandlePutTask(w http.ResponseWriter, r *http.Request)

HandlePutTask handles the PUT request for updating a task. It parses the request context, validates the task ID, and updates the task title. If successful, it returns a success toast message. If there are any errors, it returns an error toast message.

func (*TasksHandler) HandleToggleTask

func (h *TasksHandler) HandleToggleTask(w http.ResponseWriter, r *http.Request)

HandleToggleTask toggles the status of a task based on the provided ID.

Parameters: - ctx: the echo context.

Returns: - An error.

Jump to

Keyboard shortcuts

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