-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tag): tag相关 service和dao处理逻辑,及所有模块共有的字段回调
- Loading branch information
1 parent
7cbbef2
commit 6ccfc9d
Showing
6 changed files
with
254 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dao | ||
|
||
import "github.com/jinzhu/gorm" | ||
|
||
type Dao struct { | ||
engine *gorm.DB | ||
} | ||
|
||
func New(engine *gorm.DB) *Dao { | ||
return &Dao{engine: engine} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Package dao dao 层进行了数据访问对象的封装,并针对业务所需的字段进行了处理。 | ||
package dao | ||
|
||
import ( | ||
"github.com/golang-minibear2333/gin-blog/internal/model" | ||
"github.com/golang-minibear2333/gin-blog/pkg/app" | ||
) | ||
|
||
func (d *Dao) CountTag(name string, state uint8) (int, error) { | ||
tag := model.Tag{Name: name, State: state} | ||
return tag.Count(d.engine) | ||
} | ||
|
||
func (d *Dao) GetTagList(name string, state uint8, page, pageSize int) ([]*model.Tag, error) { | ||
tag := model.Tag{Name: name, State: state} | ||
pageOffset := app.GetPageOffset(page, pageSize) | ||
return tag.List(d.engine, pageOffset, pageSize) | ||
} | ||
|
||
func (d *Dao) CreateTag(name string, state uint8, createdBy string) error { | ||
tag := model.Tag{ | ||
Name: name, | ||
State: state, | ||
Model: &model.Model{CreatedBy: createdBy}, | ||
} | ||
|
||
return tag.Create(d.engine) | ||
} | ||
|
||
func (d *Dao) UpdateTag(id uint32, name string, state uint8, modifiedBy string) error { | ||
tag := model.Tag{ | ||
Name: name, | ||
State: state, | ||
Model: &model.Model{ID: id, ModifiedBy: modifiedBy}, | ||
} | ||
|
||
return tag.Update(d.engine) | ||
} | ||
|
||
func (d *Dao) DeleteTag(id uint32) error { | ||
tag := model.Tag{Model: &model.Model{ID: id}} | ||
return tag.Delete(d.engine) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"github.com/golang-minibear2333/gin-blog/global" | ||
"github.com/golang-minibear2333/gin-blog/internal/dao" | ||
) | ||
|
||
type Service struct { | ||
ctx context.Context | ||
dao *dao.Dao | ||
} | ||
|
||
func New(ctx context.Context) Service { | ||
svc := Service{ctx: ctx} | ||
svc.dao = dao.New(global.DBEngine) | ||
return svc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters