/
service.go
43 lines (34 loc) · 1014 Bytes
/
service.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
package article
//Service is another abstraction over repository
type Service interface {
CreateArticle(article *Article) (*Article, error)
GetUserArticles(userID uint32) (*[]Article, error)
GetAllArticles() (*[]Article, error)
GetArticleByID(ID uint32) (*Article, error)
DeleteArticle(ID uint32) (bool, error)
}
type service struct {
repo Repository
}
//NewService impl
func NewService(r Repository) Service {
return &service{repo: r}
}
func (s *service) GetRepo() Repository {
return s.repo
}
func (s service) CreateArticle(article *Article) (*Article, error) {
return s.repo.CreateArticle(article)
}
func (s service) GetUserArticles(userID uint32) (*[]Article, error) {
return s.repo.GetUserArticles(userID)
}
func (s service) GetAllArticles() (*[]Article, error) {
return s.repo.GetAllArticles()
}
func (s service) GetArticleByID(ID uint32) (*Article, error) {
return s.repo.GetArticlebyID(ID)
}
func (s service) DeleteArticle(ID uint32) (bool, error) {
return s.repo.DeleteArticle(ID)
}