Skip to content

Commit ea88c84

Browse files
committed
refactor(internal): change initialization of services
1 parent 531c138 commit ea88c84

66 files changed

Lines changed: 610 additions & 749 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/codexgo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/bastean/codexgo/v4/internal/app/cli"
1111
"github.com/bastean/codexgo/v4/internal/app/server"
12+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/log"
1213
"github.com/bastean/codexgo/v4/internal/pkg/service"
13-
"github.com/bastean/codexgo/v4/internal/pkg/service/record/log"
1414
)
1515

1616
var (

internal/app/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/joho/godotenv"
88

9-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
10-
"github.com/bastean/codexgo/v4/internal/pkg/service/record/log"
9+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/log"
10+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
1111
)
1212

1313
const (

internal/app/server/component/page/dashboard/page.dashboard.templ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dashboard
33
import (
44
"github.com/bastean/codexgo/v4/internal/app/server/component/layout"
55
"github.com/bastean/codexgo/v4/internal/app/server/component/scripts"
6-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
6+
"github.com/bastean/codexgo/v4/pkg/context/user/application/read"
77
)
88

99
script PageInit() {
@@ -39,7 +39,7 @@ script Logout() {
3939
window.location.replace("/");
4040
}
4141

42-
templ Page(attributes *user.ReadResponseAttributes) {
42+
templ Page(attributes *read.ResponseAttributes) {
4343
@layout.Index(scripts.Head{}, scripts.Body{}) {
4444
<div class="ui centered grid container" style="height: 100%;">
4545
<div class="sixteen wide column">

internal/app/server/component/page/dashboard/page.dashboard_templ.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/app/server/handler/page/dashboard.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"github.com/bastean/codexgo/v4/internal/app/server/service/errs"
88
"github.com/bastean/codexgo/v4/internal/app/server/service/format"
99
"github.com/bastean/codexgo/v4/internal/app/server/service/key"
10-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/query"
11-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
12-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
10+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/query"
11+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
12+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
13+
"github.com/bastean/codexgo/v4/pkg/context/user/application/read"
1314
)
1415

1516
func Dashboard(c *gin.Context) {
@@ -20,22 +21,22 @@ func Dashboard(c *gin.Context) {
2021
return
2122
}
2223

23-
attributes := new(user.ReadQueryAttributes)
24+
attributes := new(read.QueryAttributes)
2425

2526
attributes.ID = format.ToString(id)
2627

27-
response, err := query.Bus.Ask(query.New(
28-
user.ReadQueryKey,
28+
response, err := query.Bus.Ask(messages.New(
29+
read.QueryKey,
2930
attributes,
30-
new(user.ReadQueryMeta),
31+
new(read.QueryMeta),
3132
))
3233

3334
if err != nil {
3435
errs.AbortByErrWithRedirect(c, errors.BubbleUp(err, "Dashboard"), "/")
3536
return
3637
}
3738

38-
found, ok := response.Attributes.(*user.ReadResponseAttributes)
39+
found, ok := response.Attributes.(*read.ResponseAttributes)
3940

4041
if !ok {
4142
errs.AbortByErrWithRedirect(c, errs.Assertion("Dashboard"), "/")

internal/app/server/handler/user/create.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77

88
"github.com/bastean/codexgo/v4/internal/app/server/service/errs"
99
"github.com/bastean/codexgo/v4/internal/app/server/service/reply"
10-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/command"
11-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
12-
"github.com/bastean/codexgo/v4/internal/pkg/service/id"
13-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
10+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/command"
11+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
12+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
13+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/services"
14+
"github.com/bastean/codexgo/v4/pkg/context/user/application/create"
1415
)
1516

1617
func Create(c *gin.Context) {
17-
attributes := new(user.CreateCommandAttributes)
18+
attributes := new(create.CommandAttributes)
1819

1920
err := c.BindJSON(attributes)
2021

@@ -23,13 +24,13 @@ func Create(c *gin.Context) {
2324
return
2425
}
2526

26-
attributes.Verify = id.Generate()
27-
attributes.ID = id.Generate()
27+
attributes.Verify = services.GenerateID()
28+
attributes.ID = services.GenerateID()
2829

29-
err = command.Bus.Dispatch(command.New(
30-
user.CreateCommandKey,
30+
err = command.Bus.Dispatch(messages.New(
31+
create.CommandKey,
3132
attributes,
32-
new(user.CreateCommandMeta),
33+
new(create.CommandMeta),
3334
))
3435

3536
if err != nil {

internal/app/server/handler/user/delete.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"github.com/bastean/codexgo/v4/internal/app/server/service/format"
1111
"github.com/bastean/codexgo/v4/internal/app/server/service/key"
1212
"github.com/bastean/codexgo/v4/internal/app/server/service/reply"
13-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/command"
14-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
15-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
13+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/command"
14+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
15+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
16+
"github.com/bastean/codexgo/v4/pkg/context/user/application/delete"
1617
)
1718

1819
func Delete(c *gin.Context) {
@@ -23,7 +24,7 @@ func Delete(c *gin.Context) {
2324
return
2425
}
2526

26-
attributes := new(user.DeleteCommandAttributes)
27+
attributes := new(delete.CommandAttributes)
2728

2829
err := c.BindJSON(attributes)
2930

@@ -34,10 +35,10 @@ func Delete(c *gin.Context) {
3435

3536
attributes.ID = format.ToString(id)
3637

37-
err = command.Bus.Dispatch(command.New(
38-
user.DeleteCommandKey,
38+
err = command.Bus.Dispatch(messages.New(
39+
delete.CommandKey,
3940
attributes,
40-
new(user.DeleteCommandMeta),
41+
new(delete.CommandMeta),
4142
))
4243

4344
if err != nil {

internal/app/server/handler/user/login.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import (
1010
"github.com/bastean/codexgo/v4/internal/app/server/service/errs"
1111
"github.com/bastean/codexgo/v4/internal/app/server/service/key"
1212
"github.com/bastean/codexgo/v4/internal/app/server/service/reply"
13-
"github.com/bastean/codexgo/v4/internal/pkg/service/authentication/jwt"
14-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/query"
15-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
16-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
13+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/query"
14+
"github.com/bastean/codexgo/v4/internal/pkg/service/authentication"
15+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
16+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
17+
"github.com/bastean/codexgo/v4/pkg/context/shared/infrastructure/authentications/jwt"
18+
"github.com/bastean/codexgo/v4/pkg/context/user/application/login"
1719
)
1820

1921
func Login(c *gin.Context) {
20-
attributes := new(user.LoginQueryAttributes)
22+
attributes := new(login.QueryAttributes)
2123

2224
err := c.BindJSON(attributes)
2325

@@ -26,25 +28,25 @@ func Login(c *gin.Context) {
2628
return
2729
}
2830

29-
response, err := query.Bus.Ask(query.New(
30-
user.LoginQueryKey,
31+
response, err := query.Bus.Ask(messages.New(
32+
login.QueryKey,
3133
attributes,
32-
new(user.LoginQueryMeta),
34+
new(login.QueryMeta),
3335
))
3436

3537
if err != nil {
3638
errs.AbortByErr(c, errors.BubbleUp(err, "Login"))
3739
return
3840
}
3941

40-
found, ok := response.Attributes.(*user.LoginResponseAttributes)
42+
found, ok := response.Attributes.(*login.ResponseAttributes)
4143

4244
if !ok {
4345
errs.AbortByErr(c, errs.Assertion("Login"))
4446
return
4547
}
4648

47-
token, err := jwt.Generate(jwt.Payload{
49+
token, err := authentication.JWT.Generate(jwt.Payload{
4850
key.Exp: time.Now().Add((24 * time.Hour) * 7).Unix(),
4951
key.UserID: found.ID,
5052
})

internal/app/server/handler/user/update.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
"github.com/bastean/codexgo/v4/internal/app/server/service/format"
1010
"github.com/bastean/codexgo/v4/internal/app/server/service/key"
1111
"github.com/bastean/codexgo/v4/internal/app/server/service/reply"
12-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/command"
13-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
14-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
12+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/command"
13+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
14+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
15+
"github.com/bastean/codexgo/v4/pkg/context/user/application/update"
1516
)
1617

1718
func Update(c *gin.Context) {
@@ -22,7 +23,7 @@ func Update(c *gin.Context) {
2223
return
2324
}
2425

25-
attributes := new(user.UpdateCommandAttributes)
26+
attributes := new(update.CommandAttributes)
2627

2728
err := c.BindJSON(attributes)
2829

@@ -33,10 +34,10 @@ func Update(c *gin.Context) {
3334

3435
attributes.ID = format.ToString(id)
3536

36-
err = command.Bus.Dispatch(command.New(
37-
user.UpdateCommandKey,
37+
err = command.Bus.Dispatch(messages.New(
38+
update.CommandKey,
3839
attributes,
39-
new(user.UpdateCommandMeta),
40+
new(update.CommandMeta),
4041
))
4142

4243
if err != nil {

internal/app/server/handler/user/verify.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77

88
"github.com/bastean/codexgo/v4/internal/app/server/service/errs"
99
"github.com/bastean/codexgo/v4/internal/app/server/service/key"
10-
"github.com/bastean/codexgo/v4/internal/pkg/service/communication/command"
11-
"github.com/bastean/codexgo/v4/internal/pkg/service/errors"
12-
"github.com/bastean/codexgo/v4/internal/pkg/service/module/user"
10+
"github.com/bastean/codexgo/v4/internal/pkg/adapter/command"
11+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
12+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
13+
"github.com/bastean/codexgo/v4/pkg/context/user/application/verify"
1314
)
1415

1516
func Verify(c *gin.Context) {
@@ -27,15 +28,15 @@ func Verify(c *gin.Context) {
2728
return
2829
}
2930

30-
attributes := &user.VerifyCommandAttributes{
31+
attributes := &verify.CommandAttributes{
3132
Verify: token,
3233
ID: id,
3334
}
3435

35-
err := command.Bus.Dispatch(command.New(
36-
user.VerifyCommandKey,
36+
err := command.Bus.Dispatch(messages.New(
37+
verify.CommandKey,
3738
attributes,
38-
new(user.VerifyCommandMeta),
39+
new(verify.CommandMeta),
3940
))
4041

4142
if err != nil {

0 commit comments

Comments
 (0)