|
|
|
@ -15,7 +15,7 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TODO function should accept and a pointer to an interface allowing for mocking in tests.
|
|
|
|
|
func handleHome(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, snippetService *model.SnippetService) http.Handler {
|
|
|
|
|
func handleHome(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, snippetService model.SnippetServiceInterface) http.Handler {
|
|
|
|
|
return http.HandlerFunc(
|
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
// Retrieve Snippets from DB
|
|
|
|
@ -63,7 +63,7 @@ func handleHome(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleSnippetView(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, snippetService *model.SnippetService) http.Handler {
|
|
|
|
|
func handleSnippetView(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, snippetService model.SnippetServiceInterface) http.Handler {
|
|
|
|
|
return http.HandlerFunc(
|
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
id, err := strconv.Atoi(r.PathValue("id"))
|
|
|
|
@ -151,7 +151,7 @@ func handleSnippetCreateGet(tc *TemplateCache, sm *scs.SessionManager) http.Hand
|
|
|
|
|
// snippetCreate handles display of the form used to create snippets
|
|
|
|
|
//
|
|
|
|
|
// curl -iL -d "" http://localhost:5001/snippet/create
|
|
|
|
|
func handleSnippetCreatePost(logger *slog.Logger, tc *TemplateCache, formDecoder *form.Decoder, sm *scs.SessionManager, snippetService *model.SnippetService) http.Handler {
|
|
|
|
|
func handleSnippetCreatePost(logger *slog.Logger, tc *TemplateCache, formDecoder *form.Decoder, sm *scs.SessionManager, snippetService model.SnippetServiceInterface) http.Handler {
|
|
|
|
|
return http.HandlerFunc(
|
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
// example of a custom header. Must be done before calling WriteHeader
|
|
|
|
@ -291,7 +291,7 @@ func handleUserSignupGet(tc *TemplateCache, sm *scs.SessionManager) http.Handler
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleUserSignupPost(logger *slog.Logger, tc *TemplateCache, fd *form.Decoder, sm *scs.SessionManager, userService *model.UserService) http.Handler {
|
|
|
|
|
func handleUserSignupPost(logger *slog.Logger, tc *TemplateCache, fd *form.Decoder, sm *scs.SessionManager, userService model.UserServiceInterface) http.Handler {
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
// Check that the provided name, email address and password are not blank.
|
|
|
|
@ -355,7 +355,7 @@ func handleUserLoginGet(tc *TemplateCache, sm *scs.SessionManager) http.Handler
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleUserLoginPost(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, fd *form.Decoder, userService *model.UserService) http.Handler {
|
|
|
|
|
func handleUserLoginPost(logger *slog.Logger, tc *TemplateCache, sm *scs.SessionManager, fd *form.Decoder, userService model.UserServiceInterface) http.Handler {
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
// parse form
|
|
|
|
|
err := r.ParseForm()
|
|
|
|
|