-
Notifications
You must be signed in to change notification settings - Fork 17
/
token.go
58 lines (48 loc) · 1.24 KB
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package service
import (
"github.com/google/uuid"
"github.com/gowok/ioc"
"github.com/hadihammurabi/belajar-go-rest-api/internal/entity"
"github.com/hadihammurabi/belajar-go-rest-api/pkg/repository"
)
// TokenService interface
type TokenService interface {
Create(*entity.Token) (*entity.Token, error)
FindByUserID(uuid.UUID) (*entity.Token, error)
FindByToken(string) (*entity.Token, error)
}
// tokenService struct
type tokenService struct {
repo *repository.Repository
}
// NewTokenService func
func NewTokenService() TokenService {
repo := ioc.Get(repository.Repository{})
return tokenService{
repo,
}
}
// Create func
func (u tokenService) Create(token *entity.Token) (*entity.Token, error) {
tokenFromTable, err := u.repo.Token.Create(token)
if err != nil {
return nil, err
}
return tokenFromTable, nil
}
// FindByUserID func
func (u tokenService) FindByUserID(id uuid.UUID) (*entity.Token, error) {
tokenFromTable, err := u.repo.Token.FindByUserID(id)
if err != nil {
return nil, err
}
return tokenFromTable, nil
}
// FindByToken func
func (u tokenService) FindByToken(token string) (*entity.Token, error) {
tokenFromTable, err := u.repo.Token.FindByToken(token)
if err != nil {
return nil, err
}
return tokenFromTable, nil
}