feat(API): user invitations and emails
This commit is contained in:
1 parent
7aae704d0a
commit
acdef18b37
17 files changed
+1687
-7
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package mappers
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/invite"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
)
|
||||
|
||||
func InviteToDomain(m models.Invite) invite.Invite {
|
||||
return invite.Invite{
|
||||
ID: m.ID,
|
||||
Email: m.Email,
|
||||
HashedCode: m.HashedCode,
|
||||
ExpiresAt: m.ExpiresAt,
|
||||
InvitedBy: m.InvitedBy,
|
||||
AcceptedAt: m.AcceptedAt,
|
||||
CreatedAt: m.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func InviteToModel(i invite.Invite) models.Invite {
|
||||
return models.Invite{
|
||||
ID: i.ID,
|
||||
Email: i.Email,
|
||||
HashedCode: i.HashedCode,
|
||||
ExpiresAt: i.ExpiresAt,
|
||||
InvitedBy: i.InvitedBy,
|
||||
AcceptedAt: i.AcceptedAt,
|
||||
CreatedAt: i.CreatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Invite struct {
|
||||
ID uint32 `gorm:"primaryKey;autoIncrement"`
|
||||
Email string `gorm:"index;not null"`
|
||||
HashedCode string `gorm:"not null"`
|
||||
ExpiresAt time.Time
|
||||
InvitedBy uint32 `gorm:"not null"`
|
||||
AcceptedAt *time.Time
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
domainInvite "RenewCMS/internal/domain/invite"
|
||||
"RenewCMS/internal/infrastructure/persistence/mappers"
|
||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InviteRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewInviteRepository(db *gorm.DB) *InviteRepository {
|
||||
return &InviteRepository{db}
|
||||
}
|
||||
|
||||
func (i *InviteRepository) Create(invite domainInvite.Invite) (domainInvite.Invite, error) {
|
||||
model := mappers.InviteToModel(invite)
|
||||
model.ID = 0
|
||||
if err := i.db.Create(&model).Error; err != nil {
|
||||
return domainInvite.Invite{}, err
|
||||
}
|
||||
|
||||
return mappers.InviteToDomain(model), nil
|
||||
}
|
||||
|
||||
func (i *InviteRepository) GetAll() []domainInvite.Invite {
|
||||
var invites []entity.Invite
|
||||
i.db.Model(&entity.Invite{}).Find(&invites)
|
||||
|
||||
var domainInvites []domainInvite.Invite
|
||||
for _, localInvite := range invites {
|
||||
domainInvites = append(domainInvites, mappers.InviteToDomain(localInvite))
|
||||
}
|
||||
|
||||
return domainInvites
|
||||
}
|
||||
|
||||
func (i *InviteRepository) Delete(id uint32) error {
|
||||
result := i.db.Delete(&entity.Invite{}, id)
|
||||
return deleteOrNotFound(result, domainInvite.ErrInviteNotFound)
|
||||
}
|
||||
|
||||
var _ domainInvite.Repository = &InviteRepository{}
|
||||
Reference in new issue
Block a user