feat: invitation accept screen and api
This commit is contained in:
1 parent
310cfd528e
commit
55525c06d6
23 files changed
+2043
-11
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/hash"
|
||||
"RenewCMS/internal/domain/invite"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GetInviteUseCase struct {
|
||||
inviteRepository invite.Repository
|
||||
hasher hash.Hasher
|
||||
}
|
||||
|
||||
func NewGetInviteUseCase(inviteRepository invite.Repository, hasher hash.Hasher) *GetInviteUseCase {
|
||||
return &GetInviteUseCase{inviteRepository, hasher}
|
||||
}
|
||||
|
||||
func (g *GetInviteUseCase) GetInvite(code string) (invite.Invite, error) {
|
||||
return findUsableInvite(g.inviteRepository, g.hasher, code, time.Now())
|
||||
}
|
||||
|
||||
func findUsableInvite(inviteRepository invite.Repository, hasher hash.Hasher, code string, now time.Time) (invite.Invite, error) {
|
||||
if code == "" {
|
||||
return invite.Invite{}, invite.ErrInviteInvalid
|
||||
}
|
||||
|
||||
for _, candidate := range inviteRepository.GetAll() {
|
||||
if candidate.AcceptedAt != nil {
|
||||
continue
|
||||
}
|
||||
if hasher.Compare(candidate.HashedCode, code) != nil {
|
||||
continue
|
||||
}
|
||||
if candidate.StatusAt(now) == invite.StatusExpired {
|
||||
return invite.Invite{}, invite.ErrInviteExpired
|
||||
}
|
||||
return candidate, nil
|
||||
}
|
||||
|
||||
return invite.Invite{}, invite.ErrInviteInvalid
|
||||
}
|
||||
Reference in new issue
Block a user