mirror of https://gitee.com/answerdev/answer.git
Merge branch 'ai/0.4.0/tag' into 'test'
Ai/0.4.0/tag See merge request opensource/answer!240
This commit is contained in:
commit
b08e20ff99
|
@ -155,8 +155,8 @@ func (sc *SiteInfoController) UpdateSiteWrite(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
err := sc.siteInfoService.SaveSiteWrite(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
resp, err := sc.siteInfoService.SaveSiteWrite(ctx, req)
|
||||
handler.HandleResponse(ctx, err, resp)
|
||||
}
|
||||
|
||||
// UpdateSiteLegal update site legal info
|
||||
|
|
|
@ -51,7 +51,7 @@ func (tr *tagRepo) GetTagListByIDs(ctx context.Context, ids []string) (tagList [
|
|||
tagList = make([]*entity.Tag, 0)
|
||||
session := tr.data.DB.In("id", ids)
|
||||
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
|
||||
err = session.Find(&tagList)
|
||||
err = session.OrderBy("recommend desc,reserved desc,id desc").Find(&tagList)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (tr *tagRepo) GetTagListByName(ctx context.Context, name string, limit int,
|
|||
} else {
|
||||
session.UseBool("recommend")
|
||||
}
|
||||
err = session.Find(&tagList, cond)
|
||||
err = session.OrderBy("recommend desc,reserved desc,id desc").Find(&tagList, cond)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func (tr *tagRepo) GetTagListByNames(ctx context.Context, names []string) (tagLi
|
|||
tagList = make([]*entity.Tag, 0)
|
||||
session := tr.data.DB.In("slug_name", names)
|
||||
// session.Where(builder.Eq{"status": entity.TagStatusAvailable})
|
||||
err = session.Find(&tagList)
|
||||
err = session.OrderBy("recommend desc,reserved desc,id desc").Find(&tagList)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/base/validator"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service/export"
|
||||
|
@ -177,15 +178,27 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site
|
|||
}
|
||||
|
||||
// SaveSiteWrite save site configuration about write
|
||||
func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (err error) {
|
||||
err = s.tagCommonService.SetSiteWriteRecommendTag(ctx, req.RecommendTags, req.RequiredTag, req.UserID)
|
||||
func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (resp interface{}, err error) {
|
||||
errData, err := s.tagCommonService.SetSiteWriteRecommendTag(ctx, req.RecommendTags, req.RequiredTag, req.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
if len(errData) > 0 {
|
||||
resp = &validator.ErrorField{
|
||||
Key: "recommend_tags",
|
||||
Value: errData,
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
err = s.tagCommonService.SetSiteWriteReservedTag(ctx, req.ReservedTags, req.UserID)
|
||||
errData, err = s.tagCommonService.SetSiteWriteReservedTag(ctx, req.ReservedTags, req.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
if len(errData) > 0 {
|
||||
resp = &validator.ErrorField{
|
||||
Key: "reserved_tags",
|
||||
Value: errData,
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
content, _ := json.Marshal(req)
|
||||
|
@ -194,7 +207,7 @@ func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWri
|
|||
Content: string(content),
|
||||
Status: 1,
|
||||
}
|
||||
return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeWrite, data)
|
||||
return nil, s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeWrite, data)
|
||||
}
|
||||
|
||||
// SaveSiteLegal save site legal configuration
|
||||
|
|
|
@ -73,16 +73,16 @@ func (ts *TagCommonService) GetSiteWriteRecommendTag(ctx context.Context) (tags
|
|||
return tags, nil
|
||||
}
|
||||
|
||||
func (ts *TagCommonService) SetSiteWriteRecommendTag(ctx context.Context, tags []string, required bool, userID string) (err error) {
|
||||
func (ts *TagCommonService) SetSiteWriteRecommendTag(ctx context.Context, tags []string, required bool, userID string) (msg string, err error) {
|
||||
err = ts.UpdateTag(ctx, tags, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
return err.Error(), err
|
||||
}
|
||||
err = ts.SetTagsAttribute(ctx, tags, "recommend", true)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
return nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (ts *TagCommonService) GetSiteWriteReservedTag(ctx context.Context) (tags []string, err error) {
|
||||
|
@ -94,16 +94,16 @@ func (ts *TagCommonService) GetSiteWriteReservedTag(ctx context.Context) (tags [
|
|||
return tags, nil
|
||||
}
|
||||
|
||||
func (ts *TagCommonService) SetSiteWriteReservedTag(ctx context.Context, tags []string, userID string) (err error) {
|
||||
func (ts *TagCommonService) SetSiteWriteReservedTag(ctx context.Context, tags []string, userID string) (msg string, err error) {
|
||||
err = ts.UpdateTag(ctx, tags, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
return err.Error(), err
|
||||
}
|
||||
err = ts.SetTagsAttribute(ctx, tags, "reserved", true)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
return nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// SetTagsAttribute
|
||||
|
@ -215,6 +215,8 @@ func (ts *TagCommonService) BatchGetObjectTag(ctx context.Context, objectIds []s
|
|||
SlugName: tagInfo.SlugName,
|
||||
DisplayName: tagInfo.DisplayName,
|
||||
MainTagSlugName: tagInfo.MainTagSlugName,
|
||||
Recommend: tagInfo.Recommend,
|
||||
Reserved: tagInfo.Reserved,
|
||||
}
|
||||
objectIDTagMap[item.ObjectID] = append(objectIDTagMap[item.ObjectID], t)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue