mirror of https://gitee.com/answerdev/answer.git
style(simple): Properly handle unhandled errors
This commit is contained in:
parent
a4ad6b7fad
commit
6e1f4841f1
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/service"
|
"github.com/answerdev/answer/internal/service"
|
||||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ScheduledTaskManager scheduled task manager
|
// ScheduledTaskManager scheduled task manager
|
||||||
|
@ -31,10 +32,13 @@ func (s *ScheduledTaskManager) Run() {
|
||||||
fmt.Println("start cron")
|
fmt.Println("start cron")
|
||||||
s.questionService.SitemapCron(context.Background())
|
s.questionService.SitemapCron(context.Background())
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
c.AddFunc("0 */1 * * *", func() {
|
_, err := c.AddFunc("0 */1 * * *", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
fmt.Println("sitemap cron execution")
|
fmt.Println("sitemap cron execution")
|
||||||
s.questionService.SitemapCron(ctx)
|
s.questionService.SitemapCron(ctx)
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
c.Start()
|
c.Start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/service/uploader"
|
"github.com/answerdev/answer/internal/service/uploader"
|
||||||
"github.com/answerdev/answer/pkg/converter"
|
"github.com/answerdev/answer/pkg/converter"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AvatarMiddleware struct {
|
type AvatarMiddleware struct {
|
||||||
|
@ -52,7 +53,10 @@ func (am *AvatarMiddleware) AvatarThumb() gin.HandlerFunc {
|
||||||
ctx.Next()
|
ctx.Next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Writer.WriteString(string(avatarfile))
|
_, err = ctx.Writer.WriteString(string(avatarfile))
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -281,9 +281,7 @@ func (qc *QuestionController) AddQuestion(ctx *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errlist, ok := resp.([]*validator.FormErrorField)
|
errlist, ok := resp.([]*validator.FormErrorField)
|
||||||
if ok {
|
if ok {
|
||||||
for _, item := range errlist {
|
errFields = append(errFields, errlist...)
|
||||||
errFields = append(errFields, item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(errFields) > 0 {
|
if len(errFields) > 0 {
|
||||||
|
@ -335,9 +333,7 @@ func (qc *QuestionController) UpdateQuestion(ctx *gin.Context) {
|
||||||
|
|
||||||
errlist, err := qc.questionService.UpdateQuestionCheckTags(ctx, req)
|
errlist, err := qc.questionService.UpdateQuestionCheckTags(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, item := range errlist {
|
errFields = append(errFields, errlist...)
|
||||||
errFields = append(errFields, item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errFields) > 0 {
|
if len(errFields) > 0 {
|
||||||
|
|
|
@ -19,6 +19,9 @@ func (q *TemplateRenderController) TagInfo(ctx context.Context, req *schema.GetT
|
||||||
dto := &schema.GetTagInfoReq{}
|
dto := &schema.GetTagInfoReq{}
|
||||||
_ = copier.Copy(dto, req)
|
_ = copier.Copy(dto, req)
|
||||||
resp, err = q.tagService.GetTagInfo(ctx, dto)
|
resp, err = q.tagService.GetTagInfo(ctx, dto)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
searchQuestion := &schema.QuestionSearch{}
|
searchQuestion := &schema.QuestionSearch{}
|
||||||
searchQuestion.Page = req.Page
|
searchQuestion.Page = req.Page
|
||||||
searchQuestion.PageSize = req.PageSize
|
searchQuestion.PageSize = req.PageSize
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/service/uploader"
|
"github.com/answerdev/answer/internal/service/uploader"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserController user controller
|
// UserController user controller
|
||||||
|
@ -294,11 +295,13 @@ func (uc *UserController) UserVerifyEmailSend(ctx *gin.Context) {
|
||||||
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
|
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
|
||||||
})
|
})
|
||||||
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
|
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uc.actionService.ActionRecordAdd(ctx, schema.ActionRecordTypeEmail, ctx.ClientIP())
|
_, err := uc.actionService.ActionRecordAdd(ctx, schema.ActionRecordTypeEmail, ctx.ClientIP())
|
||||||
err := uc.userService.UserVerifyEmailSend(ctx, userInfo.UserID)
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
err = uc.userService.UserVerifyEmailSend(ctx, userInfo.UserID)
|
||||||
handler.HandleResponse(ctx, err, nil)
|
handler.HandleResponse(ctx, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,15 +27,12 @@ type AnswerActivityRepo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
acceptAction = "accept"
|
acceptAction = "accept"
|
||||||
acceptedAction = "accepted"
|
acceptedAction = "accepted"
|
||||||
acceptCancelAction = "accept_cancel"
|
|
||||||
acceptedCancelAction = "accepted_cancel"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
acceptActionList = []string{acceptAction, acceptedAction}
|
acceptActionList = []string{acceptAction, acceptedAction}
|
||||||
acceptCancelActionList = []string{acceptCancelAction, acceptedCancelAction}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewAnswerActivityRepo new repository
|
// NewAnswerActivityRepo new repository
|
||||||
|
|
|
@ -170,7 +170,6 @@ func (ar *authRepo) RemoveAllUserTokens(ctx context.Context, userID string) {
|
||||||
if err := ar.data.Cache.Del(ctx, key); err != nil {
|
if err := ar.data.Cache.Del(ctx, key); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuthRepo new repository
|
// NewAuthRepo new repository
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
"github.com/answerdev/answer/internal/service/action"
|
"github.com/answerdev/answer/internal/service/action"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// captchaRepo captcha repository
|
// captchaRepo captcha repository
|
||||||
|
@ -65,7 +66,7 @@ func (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err
|
||||||
func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha string, err error) {
|
func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha string, err error) {
|
||||||
captcha, err = cr.data.Cache.GetString(ctx, key)
|
captcha, err = cr.data.Cache.GetString(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
log.Debug(err)
|
||||||
}
|
}
|
||||||
// TODO: cache reflect should return empty when key not found
|
// TODO: cache reflect should return empty when key not found
|
||||||
return captcha, nil
|
return captcha, nil
|
||||||
|
|
|
@ -33,7 +33,6 @@ func Test_commentRepo_AddComment(t *testing.T) {
|
||||||
|
|
||||||
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_commentRepo_GetCommentPage(t *testing.T) {
|
func Test_commentRepo_GetCommentPage(t *testing.T) {
|
||||||
|
@ -55,7 +54,6 @@ func Test_commentRepo_GetCommentPage(t *testing.T) {
|
||||||
|
|
||||||
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_commentRepo_UpdateComment(t *testing.T) {
|
func Test_commentRepo_UpdateComment(t *testing.T) {
|
||||||
|
@ -77,5 +75,4 @@ func Test_commentRepo_UpdateComment(t *testing.T) {
|
||||||
|
|
||||||
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ package repo_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/repo/question"
|
"github.com/answerdev/answer/internal/repo/question"
|
||||||
"github.com/answerdev/answer/internal/repo/revision"
|
"github.com/answerdev/answer/internal/repo/revision"
|
||||||
"github.com/answerdev/answer/internal/repo/unique"
|
"github.com/answerdev/answer/internal/repo/unique"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var q = &entity.Question{
|
var q = &entity.Question{
|
||||||
|
@ -53,6 +54,7 @@ func Test_revisionRepo_AddRevision(t *testing.T) {
|
||||||
assert.NotEqual(t, "", q.ID)
|
assert.NotEqual(t, "", q.ID)
|
||||||
|
|
||||||
content, err := json.Marshal(q)
|
content, err := json.Marshal(q)
|
||||||
|
assert.NoError(t, err)
|
||||||
// auto update false
|
// auto update false
|
||||||
rev := getRev(q.ID, q.Title, string(content))
|
rev := getRev(q.ID, q.Title, string(content))
|
||||||
err = revisionRepo.AddRevision(context.TODO(), rev, false)
|
err = revisionRepo.AddRevision(context.TODO(), rev, false)
|
||||||
|
|
|
@ -92,7 +92,7 @@ func Test_tagRepo_GetTagListByName(t *testing.T) {
|
||||||
tagOnce.Do(addTagList)
|
tagOnce.Do(addTagList)
|
||||||
tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
|
|
||||||
gotTags, err := tagCommonRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, 1, false)
|
gotTags, err := tagCommonRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)
|
assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func Test_userBackyardRepo_GetUserInfo(t *testing.T) {
|
||||||
|
|
||||||
func Test_userBackyardRepo_GetUserPage(t *testing.T) {
|
func Test_userBackyardRepo_GetUserPage(t *testing.T) {
|
||||||
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||||
got, total, err := userBackyardRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "")
|
got, total, err := userBackyardRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "", false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(1), total)
|
assert.Equal(t, int64(1), total)
|
||||||
assert.Equal(t, "1", got[0].ID)
|
assert.Equal(t, "1", got[0].ID)
|
||||||
|
|
|
@ -76,28 +76,27 @@ func (rr *reportRepo) GetReportListPage(ctx context.Context, dto schema.GetRepor
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID get report by ID
|
// GetByID get report by ID
|
||||||
func (ar *reportRepo) GetByID(ctx context.Context, id string) (report entity.Report, exist bool, err error) {
|
func (rr *reportRepo) GetByID(ctx context.Context, id string) (report *entity.Report, exist bool, err error) {
|
||||||
report = entity.Report{}
|
report = &entity.Report{}
|
||||||
exist, err = ar.data.DB.ID(id).Get(&report)
|
exist, err = rr.data.DB.ID(id).Get(report)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateByID handle report by ID
|
|
||||||
func (ar *reportRepo) UpdateByID(
|
|
||||||
ctx context.Context,
|
|
||||||
id string,
|
|
||||||
handleData entity.Report,
|
|
||||||
) (err error) {
|
|
||||||
_, err = ar.data.DB.ID(id).Update(&handleData)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vr *reportRepo) GetReportCount(ctx context.Context) (count int64, err error) {
|
// UpdateByID handle report by ID
|
||||||
|
func (rr *reportRepo) UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error) {
|
||||||
|
_, err = rr.data.DB.ID(id).Update(&handleData)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr *reportRepo) GetReportCount(ctx context.Context) (count int64, err error) {
|
||||||
list := make([]*entity.Report, 0)
|
list := make([]*entity.Report, 0)
|
||||||
count, err = vr.data.DB.Where("status =?", entity.ReportStatusPending).FindAndCount(&list)
|
count, err = rr.data.DB.Where("status =?", entity.ReportStatusPending).FindAndCount(&list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
return count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package router
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestUIRouter_Register(t *testing.T) {
|
|
||||||
r := gin.Default()
|
|
||||||
|
|
||||||
NewUIRouter().Register(r)
|
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
req, _ := http.NewRequest("GET", "/", nil)
|
|
||||||
|
|
||||||
r.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUIRouter_Static(t *testing.T) {
|
|
||||||
r := gin.Default()
|
|
||||||
|
|
||||||
NewUIRouter().Register(r)
|
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
req, _ := http.NewRequest("GET", "/static/version.txt", nil)
|
|
||||||
|
|
||||||
r.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
|
||||||
assert.Equal(t, "OK", w.Body.String())
|
|
||||||
}
|
|
|
@ -148,6 +148,9 @@ func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *sc
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !exist {
|
||||||
|
break
|
||||||
|
}
|
||||||
objInfo = &schema.SimpleObjectInfo{
|
objInfo = &schema.SimpleObjectInfo{
|
||||||
ObjectID: answerInfo.ID,
|
ObjectID: answerInfo.ID,
|
||||||
ObjectCreatorUserID: answerInfo.UserID,
|
ObjectCreatorUserID: answerInfo.UserID,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/service/config"
|
"github.com/answerdev/answer/internal/service/config"
|
||||||
"github.com/answerdev/answer/pkg/htmltext"
|
"github.com/answerdev/answer/pkg/htmltext"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/pager"
|
"github.com/answerdev/answer/internal/base/pager"
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
|
@ -106,13 +107,13 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.
|
||||||
// HandleReported handle the reported object
|
// HandleReported handle the reported object
|
||||||
func (rs *ReportBackyardService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
|
func (rs *ReportBackyardService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
|
||||||
var (
|
var (
|
||||||
reported = entity.Report{}
|
reported *entity.Report
|
||||||
handleData = entity.Report{
|
handleData = entity.Report{
|
||||||
FlaggedContent: req.FlaggedContent,
|
FlaggedContent: req.FlaggedContent,
|
||||||
FlaggedType: req.FlaggedType,
|
FlaggedType: req.FlaggedType,
|
||||||
Status: entity.ReportStatusCompleted,
|
Status: entity.ReportStatusCompleted,
|
||||||
}
|
}
|
||||||
exist = false
|
exist bool
|
||||||
)
|
)
|
||||||
|
|
||||||
reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
|
reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
|
||||||
|
@ -159,6 +160,7 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
|
||||||
|
|
||||||
objIds, err = rs.commonRepo.GetObjectIDMap(r.ObjectID)
|
objIds, err = rs.commonRepo.GetObjectIDMap(r.ObjectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,11 +177,19 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
|
||||||
answerId, ok = objIds["answer"]
|
answerId, ok = objIds["answer"]
|
||||||
if ok {
|
if ok {
|
||||||
answer, _, err = rs.answerRepo.GetAnswer(ctx, answerId)
|
answer, _, err = rs.answerRepo.GetAnswer(ctx, answerId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commentId, ok = objIds["comment"]
|
commentId, ok = objIds["comment"]
|
||||||
if ok {
|
if ok {
|
||||||
cmt, _, err = rs.commentCommonRepo.GetComment(ctx, commentId)
|
cmt, _, err = rs.commentCommonRepo.GetComment(ctx, commentId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch r.OType {
|
switch r.OType {
|
||||||
|
@ -208,15 +218,20 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
|
||||||
ReasonType: r.ReportType,
|
ReasonType: r.ReportType,
|
||||||
}
|
}
|
||||||
err = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.ReportType, r.Reason)
|
err = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.ReportType, r.Reason)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if r.FlaggedType > 0 {
|
if r.FlaggedType > 0 {
|
||||||
r.FlaggedReason = &schema.ReasonItem{
|
r.FlaggedReason = &schema.ReasonItem{
|
||||||
ReasonType: r.FlaggedType,
|
ReasonType: r.FlaggedType,
|
||||||
}
|
}
|
||||||
_ = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.FlaggedType, r.FlaggedReason)
|
err = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.FlaggedType, r.FlaggedReason)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res[i] = r
|
res[i] = r
|
||||||
}
|
}
|
||||||
resp = &res
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
type ReportRepo interface {
|
type ReportRepo interface {
|
||||||
AddReport(ctx context.Context, report *entity.Report) (err error)
|
AddReport(ctx context.Context, report *entity.Report) (err error)
|
||||||
GetReportListPage(ctx context.Context, query schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error)
|
GetReportListPage(ctx context.Context, query schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error)
|
||||||
GetByID(ctx context.Context, id string) (report entity.Report, exist bool, err error)
|
GetByID(ctx context.Context, id string) (report *entity.Report, exist bool, err error)
|
||||||
UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error)
|
UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error)
|
||||||
GetReportCount(ctx context.Context) (count int64, err error)
|
GetReportCount(ctx context.Context) (count int64, err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func NewReportHandle(
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleObject this handle object status
|
// HandleObject this handle object status
|
||||||
func (rh *ReportHandle) HandleObject(ctx context.Context, reported entity.Report, req schema.ReportHandleReq) (err error) {
|
func (rh *ReportHandle) HandleObject(ctx context.Context, reported *entity.Report, req schema.ReportHandleReq) (err error) {
|
||||||
var (
|
var (
|
||||||
objectID = reported.ObjectID
|
objectID = reported.ObjectID
|
||||||
reportedUserID = reported.ReportedUserID
|
reportedUserID = reported.ReportedUserID
|
||||||
|
|
|
@ -318,7 +318,7 @@ func (sp *SearchParser) parseAccepted(query *string) (accepted bool) {
|
||||||
|
|
||||||
if strings.Contains(q, expr) {
|
if strings.Contains(q, expr) {
|
||||||
accepted = true
|
accepted = true
|
||||||
strings.ReplaceAll(q, expr, "")
|
q = strings.ReplaceAll(q, expr, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
*query = strings.TrimSpace(q)
|
*query = strings.TrimSpace(q)
|
||||||
|
|
|
@ -119,12 +119,14 @@ func (us *UploaderService) AvatarThumbFile(ctx *gin.Context, uploadPath, fileNam
|
||||||
return avatarfile, fmt.Errorf("img extension not exist")
|
return avatarfile, fmt.Errorf("img extension not exist")
|
||||||
}
|
}
|
||||||
err = imaging.Encode(&buf, new_image, FormatExts[fileSuffix])
|
err = imaging.Encode(&buf, new_image, FormatExts[fileSuffix])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return avatarfile, errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
return avatarfile, errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
thumbReader := bytes.NewReader(buf.Bytes())
|
thumbReader := bytes.NewReader(buf.Bytes())
|
||||||
dir.CreateDirIfNotExist(path.Join(us.serviceConfig.UploadPath, avatarThumbSubPath))
|
err = dir.CreateDirIfNotExist(path.Join(us.serviceConfig.UploadPath, avatarThumbSubPath))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||||
|
}
|
||||||
avatarFilePath := path.Join(avatarThumbSubPath, thumbFileName)
|
avatarFilePath := path.Join(avatarThumbSubPath, thumbFileName)
|
||||||
savefilePath := path.Join(us.serviceConfig.UploadPath, avatarFilePath)
|
savefilePath := path.Join(us.serviceConfig.UploadPath, avatarFilePath)
|
||||||
out, err := os.Create(savefilePath)
|
out, err := os.Create(savefilePath)
|
||||||
|
|
|
@ -180,6 +180,7 @@ func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWith
|
||||||
objInfo, err = vs.objectService.GetInfo(ctx, voteInfo.ObjectID)
|
objInfo, err = vs.objectService.GetInfo(ctx, voteInfo.ObjectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
item := schema.GetVoteWithPageResp{
|
item := schema.GetVoteWithPageResp{
|
||||||
|
|
Loading…
Reference in New Issue