Skip to content

Commit

Permalink
feat: move service interfaces to contract folder
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoclair committed Dec 23, 2023
1 parent 9bd1ff8 commit 9ee378a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 36 deletions.
6 changes: 3 additions & 3 deletions application/rest/routes/accountroute/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/IQ-tech/go-mapper"
"github.com/diegoclair/go_boilerplate/application/rest/routeutils"
"github.com/diegoclair/go_boilerplate/application/rest/viewmodel"
"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/domain/service"

"github.com/labstack/echo/v4"
)
Expand All @@ -18,11 +18,11 @@ var (
)

type Controller struct {
accountService service.AccountService
accountService contract.AccountService
mapper mapper.Mapper
}

func NewController(accountService service.AccountService, mapper mapper.Mapper) *Controller {
func NewController(accountService contract.AccountService, mapper mapper.Mapper) *Controller {
once.Do(func() {
instance = &Controller{
accountService: accountService,
Expand Down
6 changes: 3 additions & 3 deletions application/rest/routes/authroute/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/IQ-tech/go-mapper"
"github.com/diegoclair/go_boilerplate/application/rest/routeutils"
"github.com/diegoclair/go_boilerplate/application/rest/viewmodel"
"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/domain/service"
"github.com/diegoclair/go_boilerplate/infra/auth"
"github.com/twinj/uuid"

Expand All @@ -22,12 +22,12 @@ var (
)

type Controller struct {
authService service.AuthService
authService contract.AuthService
mapper mapper.Mapper
authToken auth.AuthToken
}

func NewController(authService service.AuthService, mapper mapper.Mapper, authToken auth.AuthToken) *Controller {
func NewController(authService contract.AuthService, mapper mapper.Mapper, authToken auth.AuthToken) *Controller {
once.Do(func() {
instance = &Controller{
authService: authService,
Expand Down
6 changes: 3 additions & 3 deletions application/rest/routes/transferroute/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/IQ-tech/go-mapper"
"github.com/diegoclair/go_boilerplate/application/rest/routeutils"
"github.com/diegoclair/go_boilerplate/application/rest/viewmodel"
"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/domain/service"

"github.com/labstack/echo/v4"
)
Expand All @@ -18,11 +18,11 @@ var (
)

type Controller struct {
transferService service.TransferService
transferService contract.TransferService
mapper mapper.Mapper
}

func NewController(transferService service.TransferService, mapper mapper.Mapper) *Controller {
func NewController(transferService contract.TransferService, mapper mapper.Mapper) *Controller {
once.Do(func() {
instance = &Controller{
transferService: transferService,
Expand Down
25 changes: 25 additions & 0 deletions domain/contract/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package contract

import (
"context"

"github.com/diegoclair/go_boilerplate/domain/entity"
)

type AccountService interface {
CreateAccount(ctx context.Context, account entity.Account) (err error)
AddBalance(ctx context.Context, accountUUID string, amount float64) (err error)
GetAccounts(ctx context.Context, take, skip int64) (accounts []entity.Account, totalRecords int64, err error)
GetAccountByUUID(ctx context.Context, accountUUID string) (account entity.Account, err error)
}

type AuthService interface {
Login(ctx context.Context, cpf, secret string) (account entity.Account, err error)
CreateSession(ctx context.Context, session entity.Session) (err error)
GetSessionByUUID(ctx context.Context, sessionUUID string) (session entity.Session, err error)
}

type TransferService interface {
CreateTransfer(ctx context.Context, transfer entity.Transfer) (err error)
GetTransfers(ctx context.Context) (transfers []entity.Transfer, err error)
}
3 changes: 2 additions & 1 deletion domain/service/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"log/slog"

"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/infra/logger"
"github.com/diegoclair/go_boilerplate/util/crypto"
Expand All @@ -18,7 +19,7 @@ type accountService struct {
svc *service
}

func newAccountService(svc *service) AccountService {
func newAccountService(svc *service) contract.AccountService {
return &accountService{
svc: svc,
}
Expand Down
3 changes: 2 additions & 1 deletion domain/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"log/slog"

"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/util/crypto"
"github.com/diegoclair/go_utils-lib/v2/resterrors"
Expand All @@ -18,7 +19,7 @@ type authService struct {
svc *service
}

func newAuthService(svc *service) AuthService {
func newAuthService(svc *service) contract.AuthService {
return &authService{
svc: svc,
}
Expand Down
27 changes: 3 additions & 24 deletions domain/service/service.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package service

import (
"context"

"github.com/diegoclair/go_boilerplate/domain/contract"
"github.com/diegoclair/go_boilerplate/domain/entity"
"github.com/diegoclair/go_boilerplate/infra/config"
"github.com/diegoclair/go_boilerplate/infra/logger"
)

type Services struct {
AccountService AccountService
AuthService AuthService
TransferService TransferService
AccountService contract.AccountService
AuthService contract.AuthService
TransferService contract.TransferService
}

// New to get instace of all services
Expand Down Expand Up @@ -44,21 +41,3 @@ func newService(dm contract.DataManager, cfg *config.Config, cache contract.Cach

return svc
}

type AccountService interface {
CreateAccount(ctx context.Context, account entity.Account) (err error)
AddBalance(ctx context.Context, accountUUID string, amount float64) (err error)
GetAccounts(ctx context.Context, take, skip int64) (accounts []entity.Account, totalRecords int64, err error)
GetAccountByUUID(ctx context.Context, accountUUID string) (account entity.Account, err error)
}

type AuthService interface {
Login(ctx context.Context, cpf, secret string) (account entity.Account, err error)
CreateSession(ctx context.Context, session entity.Session) (err error)
GetSessionByUUID(ctx context.Context, sessionUUID string) (session entity.Session, err error)
}

type TransferService interface {
CreateTransfer(ctx context.Context, transfer entity.Transfer) (err error)
GetTransfers(ctx context.Context) (transfers []entity.Transfer, err error)
}
2 changes: 1 addition & 1 deletion domain/service/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type transferService struct {
svc *service
}

func newTransferService(svc *service) TransferService {
func newTransferService(svc *service) contract.TransferService {
return &transferService{
svc: svc,
}
Expand Down

0 comments on commit 9ee378a

Please sign in to comment.