Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 425234a

Browse files
committed
Add email template using packr2
1 parent 81cc559 commit 425234a

File tree

16 files changed

+375
-64
lines changed

16 files changed

+375
-64
lines changed

Gopkg.lock

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

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
[[constraint]]
1010
branch = "master"
1111
name = "github.com/mwitkow/go-proto-validators"
12+
13+
[[constraint]]
14+
name = "github.com/gobuffalo/packr"
15+
version = "2.0.3"

app/di/client_component.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import (
77
"github.com/pkg/errors"
88

99
"github.com/ProgrammingLab/prolab-accounts/app/config"
10+
"github.com/ProgrammingLab/prolab-accounts/infra/email"
11+
"github.com/ProgrammingLab/prolab-accounts/static"
1012
)
1113

1214
// ClientComponent is an interface of api clients
1315
type ClientComponent interface {
1416
HydraClient(ctx context.Context) *hydra.CodeGenSDK
17+
EmailSender(ctx context.Context) email.Sender
1518
}
1619

1720
// NewClientComponent returns new client component
@@ -21,8 +24,15 @@ func NewClientComponent(cfg *config.Config) (ClientComponent, error) {
2124
return nil, err
2225
}
2326

27+
e, err := static.LoadEmailTemplates()
28+
if err != nil {
29+
return nil, err
30+
}
31+
2432
return &clientComponentImpl{
33+
cfg: cfg,
2534
hydraCli: h,
35+
emails: e,
2636
}, nil
2737
}
2838

@@ -38,9 +48,15 @@ func newHydraClient(cfg *config.Config) (*hydra.CodeGenSDK, error) {
3848
}
3949

4050
type clientComponentImpl struct {
51+
cfg *config.Config
4152
hydraCli *hydra.CodeGenSDK
53+
emails *static.EmailAsset
4254
}
4355

4456
func (c *clientComponentImpl) HydraClient(ctx context.Context) *hydra.CodeGenSDK {
4557
return c.hydraCli
4658
}
59+
60+
func (c *clientComponentImpl) EmailSender(ctx context.Context) email.Sender {
61+
return email.NewSender(ctx, c.cfg, c.emails)
62+
}

app/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Run() error {
6060
server.NewPingServiceServer(store),
6161
server.NewRoleServiceServer(store),
6262
server.NewDepartmentServiceServer(store),
63-
server.NewInvitationServiceServer(),
63+
server.NewInvitationServiceServer(store, cli),
6464
),
6565
)
6666

app/server/invitations_server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"google.golang.org/grpc/status"
1010

1111
api_pb "github.com/ProgrammingLab/prolab-accounts/api"
12+
"github.com/ProgrammingLab/prolab-accounts/app/di"
1213
)
1314

1415
// InvitationServiceServer is a composite interface of api_pb.InvitationServiceServer and grapiserver.Server.
@@ -18,11 +19,16 @@ type InvitationServiceServer interface {
1819
}
1920

2021
// NewInvitationServiceServer creates a new InvitationServiceServer instance.
21-
func NewInvitationServiceServer() InvitationServiceServer {
22-
return &invitationServiceServerImpl{}
22+
func NewInvitationServiceServer(store di.StoreComponent, cli di.ClientComponent) InvitationServiceServer {
23+
return &invitationServiceServerImpl{
24+
StoreComponent: store,
25+
ClientComponent: cli,
26+
}
2327
}
2428

2529
type invitationServiceServerImpl struct {
30+
di.StoreComponent
31+
di.ClientComponent
2632
}
2733

2834
func (s *invitationServiceServerImpl) ListInvitations(ctx context.Context, req *api_pb.ListInvitationsRequest) (*api_pb.ListInvitationsResponse, error) {

gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ package accounts
22

33
//go:generate gex --build
44
//go:generate gex sqlboiler psql
5+
//go:generate packr2

infra/email/email.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package email
2+
3+
import (
4+
"context"
5+
6+
"github.com/ProgrammingLab/prolab-accounts/static"
7+
8+
"github.com/ProgrammingLab/prolab-accounts/app/config"
9+
"github.com/ProgrammingLab/prolab-accounts/infra/record"
10+
)
11+
12+
// Sender represents interface of email sender
13+
type Sender interface {
14+
SendInvitationEmail(email string, req *record.Invitation) error
15+
}
16+
17+
// NewSender creates new sender
18+
func NewSender(ctx context.Context, cfg *config.Config, asset *static.EmailAsset) Sender {
19+
return &senderImpl{
20+
ctx: ctx,
21+
cfg: cfg,
22+
asset: asset,
23+
}
24+
}
25+
26+
type senderImpl struct {
27+
ctx context.Context
28+
cfg *config.Config
29+
asset *static.EmailAsset
30+
}
31+
32+
// SendInvitationEmail sends invitation email
33+
func (s *senderImpl) SendInvitationEmail(email string, inv *record.Invitation) error {
34+
return nil
35+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package invitationstore
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
7+
"github.com/ProgrammingLab/prolab-accounts/infra/record"
8+
"github.com/ProgrammingLab/prolab-accounts/infra/store"
9+
)
10+
11+
type invitationStoreImpl struct {
12+
ctx context.Context
13+
db *sql.DB
14+
}
15+
16+
// NewInvitationStore returns new invitation store
17+
func NewInvitationStore(ctx context.Context, db *sql.DB) store.InvitationStore {
18+
return &invitationStoreImpl{
19+
ctx: ctx,
20+
db: db,
21+
}
22+
}
23+
24+
func (s *invitationStoreImpl) ListInvitations() ([]*record.Invitation, error) {
25+
panic("not implemented")
26+
}
27+
28+
func (s *invitationStoreImpl) GetInvitation(id int64) (*record.Invitation, error) {
29+
panic("not implemented")
30+
}
31+
32+
func (s *invitationStoreImpl) CreateInvitation(email string) (*record.Invitation, error) {
33+
panic("not implemented")
34+
}
35+
36+
func (s *invitationStoreImpl) DeleteInvitation(id int64) error {
37+
panic("not implemented")
38+
}

infra/store/invitation_store.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package store
2+
3+
import (
4+
"github.com/ProgrammingLab/prolab-accounts/infra/record"
5+
)
6+
7+
// InvitationStore provides invitations
8+
type InvitationStore interface {
9+
ListInvitations() ([]*record.Invitation, error)
10+
GetInvitation(id int64) (*record.Invitation, error)
11+
CreateInvitation(email string) (*record.Invitation, error)
12+
DeleteInvitation(id int64) error
13+
}

0 commit comments

Comments
 (0)