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,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