feat(smoke): support reason tags on smoke logs
This commit is contained in:
@@ -24,15 +24,16 @@ type ListSmokeLogsQuery struct {
|
||||
}
|
||||
|
||||
type SmokeLogItem struct {
|
||||
ID int `json:"id"`
|
||||
UID int `json:"uid"`
|
||||
SmokeTime *time.Time `json:"smoke_time,omitempty"`
|
||||
SmokeAt *time.Time `json:"smoke_at,omitempty"`
|
||||
Remark string `json:"remark"`
|
||||
Level int64 `json:"level"`
|
||||
Num int `json:"num"`
|
||||
CreateTime *int64 `json:"createtime,omitempty"`
|
||||
UpdateTime *int64 `json:"updatetime,omitempty"`
|
||||
ID int `json:"id"`
|
||||
UID int `json:"uid"`
|
||||
SmokeTime *time.Time `json:"smoke_time,omitempty"`
|
||||
SmokeAt *time.Time `json:"smoke_at,omitempty"`
|
||||
Remark string `json:"remark"`
|
||||
ReasonTags smokemodel.StringSlice `json:"reason_tags,omitempty"`
|
||||
Level int64 `json:"level"`
|
||||
Num int `json:"num"`
|
||||
CreateTime *int64 `json:"createtime,omitempty"`
|
||||
UpdateTime *int64 `json:"updatetime,omitempty"`
|
||||
}
|
||||
|
||||
type ListSmokeLogsResult struct {
|
||||
@@ -45,12 +46,13 @@ type ListSmokeLogsResult struct {
|
||||
// SmokeLogUpsertInput 用于新增与更新戒烟记录。
|
||||
// 说明:更新时可只传部分字段(指针字段支持局部更新)。
|
||||
type SmokeLogUpsertInput struct {
|
||||
UID *int
|
||||
SmokeTime **time.Time
|
||||
SmokeAt **time.Time
|
||||
Remark *string
|
||||
Level *int64
|
||||
Num *int
|
||||
UID *int
|
||||
SmokeTime **time.Time
|
||||
SmokeAt **time.Time
|
||||
Remark *string
|
||||
ReasonTags *smokemodel.StringSlice
|
||||
Level *int64
|
||||
Num *int
|
||||
}
|
||||
|
||||
func (s *Service) ListSmokeLogs(ctx context.Context, query ListSmokeLogsQuery) (*ListSmokeLogsResult, error) {
|
||||
@@ -93,6 +95,7 @@ func (s *Service) ListSmokeLogs(ctx context.Context, query ListSmokeLogsQuery) (
|
||||
SmokeTime: row.SmokeTime,
|
||||
SmokeAt: row.SmokeAt,
|
||||
Remark: row.Remark,
|
||||
ReasonTags: row.ReasonTags,
|
||||
Level: row.Level,
|
||||
Num: row.Num,
|
||||
CreateTime: row.CreateTime,
|
||||
@@ -126,6 +129,7 @@ func (s *Service) GetSmokeLog(ctx context.Context, id int) (*SmokeLogItem, error
|
||||
SmokeTime: row.SmokeTime,
|
||||
SmokeAt: row.SmokeAt,
|
||||
Remark: row.Remark,
|
||||
ReasonTags: row.ReasonTags,
|
||||
Level: row.Level,
|
||||
Num: row.Num,
|
||||
CreateTime: row.CreateTime,
|
||||
@@ -164,6 +168,9 @@ func (s *Service) CreateSmokeLog(ctx context.Context, input SmokeLogUpsertInput)
|
||||
if input.Remark != nil {
|
||||
row.Remark = strings.TrimSpace(*input.Remark)
|
||||
}
|
||||
if input.ReasonTags != nil {
|
||||
row.ReasonTags = *input.ReasonTags
|
||||
}
|
||||
|
||||
if err := s.db.WithContext(ctx).Create(row).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -189,6 +196,9 @@ func (s *Service) UpdateSmokeLog(ctx context.Context, id int, input SmokeLogUpse
|
||||
if input.Remark != nil {
|
||||
updates["remark"] = strings.TrimSpace(*input.Remark)
|
||||
}
|
||||
if input.ReasonTags != nil {
|
||||
updates["reason_tags"] = *input.ReasonTags
|
||||
}
|
||||
if input.Level != nil {
|
||||
if *input.Level <= 0 {
|
||||
return nil, ErrInvalidInput
|
||||
|
||||
Reference in New Issue
Block a user