Skip to content

Commit

Permalink
Move msg package to repo layer
Browse files Browse the repository at this point in the history
It does not make sense to me to have such a specific package be in the `pkg` dir.
  • Loading branch information
leomorpho committed Sep 24, 2024
1 parent 2ca6289 commit 6623182
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 25 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ See [goship.run](https://goship.run).
| |-- funcmap # Custom template functions
| |-- htmx # HTMX lifecycle helpers
| |-- middleware # Middleware for the app
| |-- msg # Show custom messages in the UI, TODO: move
| |-- repos # Repositories
| |-- routes # Think of these as the controllers in a traditional MVC framework
| |-- services # Services on the Container struct
Expand Down Expand Up @@ -187,6 +186,15 @@ To apply the migrations, either run `make migrate` or do a `make reset` to start

Create a new file in `routes/` and add your route. A route is a standard Echo handler with some added goodies. Once you've added handlers for your route, you can hook it up to the router in `routes/routes.go`, where the route should be registered to be reachable from the web.

## Set Action Messages

Following an action (POST/DELETE/GET/etc), a msg can be shown to the user. For example, a success message can shown with `msg.Success("An email confirmation was sent!")` upon user registration. The following message types are currently available:
- success
- info
- warning
- danger

See `pkg/repos/msg/msg.go` for more info.

## Realtime and Notifications

Expand Down
8 changes: 3 additions & 5 deletions pkg/controller/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import (
"time"

"github.com/a-h/templ"
"github.com/labstack/echo/v4"
echomw "github.com/labstack/echo/v4/middleware"
"github.com/mikestefanello/pagoda/ent"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/domain"
"github.com/mikestefanello/pagoda/pkg/htmx"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"
"github.com/mikestefanello/pagoda/templates"

echomw "github.com/labstack/echo/v4/middleware"

"github.com/labstack/echo/v4"
)

type (
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
echomw "github.com/labstack/echo/v4/middleware"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"
"github.com/mikestefanello/pagoda/pkg/tests"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"net/http"
"strconv"

"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/mikestefanello/pagoda/ent"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"
"github.com/mikestefanello/pagoda/pkg/repos/profilerepo"
"github.com/mikestefanello/pagoda/pkg/repos/subscriptions"
"github.com/mikestefanello/pagoda/pkg/services"
"github.com/rs/zerolog/log"

"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
)

// LoadAuthenticatedUser loads the authenticated user, if one, and stores in context
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions pkg/routes/clear_site_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package routes
import (
"time"

"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"

"github.com/labstack/echo/v4"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/repos/msg"
)

type (
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (

"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/types"
"github.com/mikestefanello/pagoda/templates"
"github.com/mikestefanello/pagoda/templates/layouts"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/delete_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/domain"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/repos/profilerepo"
"github.com/mikestefanello/pagoda/pkg/repos/subscriptions"
"github.com/mikestefanello/pagoda/pkg/types"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/forgot_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/mikestefanello/pagoda/ent/user"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/types"
"github.com/mikestefanello/pagoda/templates"
"github.com/mikestefanello/pagoda/templates/emails"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/mikestefanello/pagoda/ent/user"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/repos/profilerepo"
"github.com/mikestefanello/pagoda/pkg/types"
"github.com/mikestefanello/pagoda/templates"
Expand Down
2 changes: 1 addition & 1 deletion pkg/routes/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package routes

import (
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/labstack/echo/v4"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/domain"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/repos/notifierrepo"
"github.com/mikestefanello/pagoda/pkg/repos/profilerepo"
"github.com/mikestefanello/pagoda/pkg/repos/subscriptions"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/push_notifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/domain"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/repos/notifierrepo"
"github.com/mikestefanello/pagoda/pkg/types"
"github.com/mikestefanello/pagoda/templates"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/domain"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/repos/notifierrepo"
"github.com/mikestefanello/pagoda/pkg/repos/profilerepo"
"github.com/mikestefanello/pagoda/pkg/repos/subscriptions"
Expand Down
3 changes: 2 additions & 1 deletion pkg/routes/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"github.com/mikestefanello/pagoda/ent"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"

"github.com/mikestefanello/pagoda/pkg/types"
"github.com/mikestefanello/pagoda/templates"
"github.com/mikestefanello/pagoda/templates/layouts"
Expand Down
2 changes: 1 addition & 1 deletion pkg/routes/verify_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/mikestefanello/pagoda/ent/user"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/msg"
"github.com/mikestefanello/pagoda/pkg/repos/msg"
)

type verifyEmail struct {
Expand Down

0 comments on commit 6623182

Please sign in to comment.