style: fix code error handling

This commit is contained in:
LinkinStar 2022-10-21 17:54:46 +08:00
parent 95c59afed0
commit 5a01fb9fe1
7 changed files with 12 additions and 9 deletions

View File

@ -38,7 +38,7 @@ func NewFollowRepo(
}
func (ar *FollowRepo) Follow(ctx context.Context, objectId, userId string) error {
activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(nil, objectId, "follow")
activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(ctx, objectId, "follow")
if err != nil {
return err
}

View File

@ -44,13 +44,13 @@ func NewAnswerRepo(
func (ar *answerRepo) AddAnswer(ctx context.Context, answer *entity.Answer) (err error) {
ID, err := ar.uniqueIDRepo.GenUniqueIDStr(ctx, answer.TableName())
if err != nil {
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
answer.ID = ID
_, err = ar.data.DB.Insert(answer)
if err != nil {
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return nil
}

View File

@ -44,7 +44,7 @@ func (cr *collectionRepo) AddCollection(ctx context.Context, collection *entity.
func (cr *collectionRepo) RemoveCollection(ctx context.Context, id string) (err error) {
_, err = cr.data.DB.Where("id =?", id).Delete(&entity.Collection{})
if err != nil {
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return nil
}

View File

@ -3,9 +3,9 @@ package schema
// FollowReq follow object request
type FollowReq struct {
// object id
ObjectID string `validate:"required"form:"object_id" json:"object_id"`
ObjectID string `validate:"required" form:"object_id" json:"object_id"`
// is cancel
IsCancel bool `validate:"omitempty"form:"is_cancel" json:"is_cancel"`
IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"`
}
// FollowResp response object's follows and current user follow status

View File

@ -1,8 +1,8 @@
package schema
type VoteReq struct {
ObjectID string `validate:"required"form:"object_id" json:"object_id"` // id
IsCancel bool `validate:"omitempty"form:"is_cancel" json:"is_cancel"` // is cancel
ObjectID string `validate:"required" form:"object_id" json:"object_id"` // id
IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"` // is cancel
}
type VoteDTO struct {

View File

@ -198,6 +198,9 @@ func (es *EmailService) ChangeEmailTemplate(changeEmailUrl string) (title, body
}
tmpl, err = template.New("email_change_body").Parse(ec.ChangeBody)
if err != nil {
return "", "", err
}
err = tmpl.Execute(bodyBuf, templateData)
if err != nil {
return "", "", err

View File

@ -89,5 +89,5 @@ func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (res
ss.objectSearch.Parse(dto)
resp, total, err = ss.objectSearch.Search(ctx)
}
return resp, total, extra, nil
return resp, total, extra, err
}