正在显示
8 个修改的文件
包含
61 行增加
和
25 行删除
| @@ -166,7 +166,7 @@ type ( | @@ -166,7 +166,7 @@ type ( | ||
| 166 | CompanyId int64 `json:",optional"` | 166 | CompanyId int64 `json:",optional"` |
| 167 | AuthorId int64 `json:",optional"` // 发布人 | 167 | AuthorId int64 `json:",optional"` // 发布人 |
| 168 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 168 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 169 | - Content []string `json:"content"` // 填写的内容 | 169 | + Section []string `json:"section"` // 填写的内容 |
| 170 | Title string `json:"title"` // 标题 | 170 | Title string `json:"title"` // 标题 |
| 171 | Images []string `json:"images"` // 图片 | 171 | Images []string `json:"images"` // 图片 |
| 172 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 172 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -186,7 +186,7 @@ type ( | @@ -186,7 +186,7 @@ type ( | ||
| 186 | CompanyId int64 `json:",optional"` | 186 | CompanyId int64 `json:",optional"` |
| 187 | AuthorId int64 `json:",optional"` // 发布人 | 187 | AuthorId int64 `json:",optional"` // 发布人 |
| 188 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 188 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 189 | - Content []string `json:"content"` // 填写的内容 | 189 | + Section []string `json:"section"` // 填写的内容 |
| 190 | Title string `json:"title"` // 标题 | 190 | Title string `json:"title"` // 标题 |
| 191 | Images []string `json:"images"` // 图片 | 191 | Images []string `json:"images"` // 图片 |
| 192 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 192 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -215,7 +215,7 @@ type ( | @@ -215,7 +215,7 @@ type ( | ||
| 215 | MiniArticleDraftItem { | 215 | MiniArticleDraftItem { |
| 216 | Id int64 `json:"id"` | 216 | Id int64 `json:"id"` |
| 217 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 217 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 218 | - Content []string `json:"content"` // 填写的内容 | 218 | + Section []string `json:"section"` // 填写的内容 |
| 219 | Title string `json:"title"` // 标题 | 219 | Title string `json:"title"` // 标题 |
| 220 | Images []string `json:"images"` // 图片 | 220 | Images []string `json:"images"` // 图片 |
| 221 | CreatedAt int64 `json:"createdAt"` | 221 | CreatedAt int64 `json:"createdAt"` |
| @@ -233,7 +233,7 @@ type ( | @@ -233,7 +233,7 @@ type ( | ||
| 233 | MiniArticleDraftGetMeResponse { | 233 | MiniArticleDraftGetMeResponse { |
| 234 | Id int64 `json:"id"` // | 234 | Id int64 `json:"id"` // |
| 235 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 235 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 236 | - Content []string `json:"content"` // 填写的内容 | 236 | + Section []string `json:"Section"` // 填写的内容 |
| 237 | Title string `json:"title"` // 标题 | 237 | Title string `json:"title"` // 标题 |
| 238 | Images []string `json:"images"` // 图片 | 238 | Images []string `json:"images"` // 图片 |
| 239 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 239 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -7,6 +7,8 @@ import ( | @@ -7,6 +7,8 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 10 | ) | 12 | ) |
| 11 | 13 | ||
| 12 | func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 14 | func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
| @@ -16,13 +18,11 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -16,13 +18,11 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
| 16 | httpx.ErrorCtx(r.Context(), w, err) | 18 | httpx.ErrorCtx(r.Context(), w, err) |
| 17 | return | 19 | return |
| 18 | } | 20 | } |
| 19 | - | ||
| 20 | l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx) | 21 | l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx) |
| 22 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 23 | + req.AuthorId = token.UserId | ||
| 24 | + req.CompanyId = token.CompanyId | ||
| 21 | resp, err := l.MiniUpdateArticleDraft(&req) | 25 | resp, err := l.MiniUpdateArticleDraft(&req) |
| 22 | - if err != nil { | ||
| 23 | - httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | - } else { | ||
| 25 | - httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | - } | 26 | + result.HttpResult(r, w, resp, err) |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| @@ -37,7 +37,7 @@ func (l *MiniCreateArticleDraftLogic) MiniCreateArticleDraft(req *types.MiniArti | @@ -37,7 +37,7 @@ func (l *MiniCreateArticleDraftLogic) MiniCreateArticleDraft(req *types.MiniArti | ||
| 37 | DeletedAt: 0, | 37 | DeletedAt: 0, |
| 38 | Version: 0, | 38 | Version: 0, |
| 39 | Template: req.Template, | 39 | Template: req.Template, |
| 40 | - Content: req.Content, | 40 | + Content: req.Section, |
| 41 | AuthorId: req.AuthorId, | 41 | AuthorId: req.AuthorId, |
| 42 | Title: req.Title, | 42 | Title: req.Title, |
| 43 | Images: []domain.Image{}, | 43 | Images: []domain.Image{}, |
| @@ -40,7 +40,7 @@ func (l *MiniGetArticleDraftMeLogic) MiniGetArticleDraftMe(req *types.MiniArticl | @@ -40,7 +40,7 @@ func (l *MiniGetArticleDraftMeLogic) MiniGetArticleDraftMe(req *types.MiniArticl | ||
| 40 | resp = &types.MiniArticleDraftGetMeResponse{ | 40 | resp = &types.MiniArticleDraftGetMeResponse{ |
| 41 | Id: draftInfo.Id, | 41 | Id: draftInfo.Id, |
| 42 | Template: draftInfo.Template, | 42 | Template: draftInfo.Template, |
| 43 | - Content: draftInfo.Content, | 43 | + Section: draftInfo.Content, |
| 44 | Title: draftInfo.Title, | 44 | Title: draftInfo.Title, |
| 45 | Images: []string{}, | 45 | Images: []string{}, |
| 46 | WhoRead: draftInfo.WhoRead, | 46 | WhoRead: draftInfo.WhoRead, |
| @@ -49,7 +49,7 @@ func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.Mini | @@ -49,7 +49,7 @@ func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.Mini | ||
| 49 | resp.List[i] = types.MiniArticleDraftItem{ | 49 | resp.List[i] = types.MiniArticleDraftItem{ |
| 50 | Id: draftList[i].Id, | 50 | Id: draftList[i].Id, |
| 51 | Template: draftList[i].Template, | 51 | Template: draftList[i].Template, |
| 52 | - Content: draftList[i].Content, | 52 | + Section: draftList[i].Content, |
| 53 | Title: draftList[i].Title, | 53 | Title: draftList[i].Title, |
| 54 | Images: images, | 54 | Images: images, |
| 55 | } | 55 | } |
| @@ -5,6 +5,8 @@ import ( | @@ -5,6 +5,8 @@ import ( | ||
| 5 | 5 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 8 | 10 | ||
| 9 | "github.com/zeromicro/go-zero/core/logx" | 11 | "github.com/zeromicro/go-zero/core/logx" |
| 10 | ) | 12 | ) |
| @@ -24,7 +26,38 @@ func NewMiniUpdateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont | @@ -24,7 +26,38 @@ func NewMiniUpdateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont | ||
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArticleDraftUpdateRequest) (resp *types.MiniArticleDraftUpdateResponse, err error) { | 28 | func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArticleDraftUpdateRequest) (resp *types.MiniArticleDraftUpdateResponse, err error) { |
| 27 | - // todo: add your logic here and delete this line | 29 | + var conn = l.svcCtx.DefaultDBConn() |
| 28 | 30 | ||
| 31 | + draftInfo, err := l.svcCtx.ArticleDraftRepository.FindOne(l.ctx, conn, req.Id) | ||
| 32 | + if err != nil { | ||
| 33 | + return nil, xerr.NewErrMsgErr("更新草稿失败", err) | ||
| 34 | + } | ||
| 35 | + if draftInfo.AuthorId != req.AuthorId { | ||
| 36 | + if err != nil { | ||
| 37 | + return nil, xerr.NewErrMsg("更新草稿失败") | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + draftInfo.Content = req.Section | ||
| 41 | + draftInfo.Title = req.Title | ||
| 42 | + draftInfo.Location = domain.Location{ | ||
| 43 | + Longitude: req.Location.Longitude, | ||
| 44 | + Latitude: req.Location.Latitude, | ||
| 45 | + Descript: req.Location.Descript, | ||
| 46 | + } | ||
| 47 | + draftInfo.WhoRead = req.WhoRead | ||
| 48 | + draftInfo.WhoReview = req.WhoReview | ||
| 49 | + draftInfo.Images = []domain.Image{} | ||
| 50 | + for _, val := range req.Images { | ||
| 51 | + draftInfo.Images = append(draftInfo.Images, domain.Image{ | ||
| 52 | + Url: val, | ||
| 53 | + }) | ||
| 54 | + } | ||
| 55 | + _, err = l.svcCtx.ArticleDraftRepository.Update(l.ctx, conn, draftInfo) | ||
| 56 | + if err != nil { | ||
| 57 | + return nil, xerr.NewErrMsgErr("更新草稿失败", err) | ||
| 58 | + } | ||
| 59 | + resp = &types.MiniArticleDraftUpdateResponse{ | ||
| 60 | + Id: draftInfo.Id, | ||
| 61 | + } | ||
| 29 | return | 62 | return |
| 30 | } | 63 | } |
| @@ -150,7 +150,7 @@ type MiniArticleDraftCreateRequest struct { | @@ -150,7 +150,7 @@ type MiniArticleDraftCreateRequest struct { | ||
| 150 | CompanyId int64 `json:",optional"` | 150 | CompanyId int64 `json:",optional"` |
| 151 | AuthorId int64 `json:",optional"` // 发布人 | 151 | AuthorId int64 `json:",optional"` // 发布人 |
| 152 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 152 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 153 | - Content []string `json:"content"` // 填写的内容 | 153 | + Section []string `json:"section"` // 填写的内容 |
| 154 | Title string `json:"title"` // 标题 | 154 | Title string `json:"title"` // 标题 |
| 155 | Images []string `json:"images"` // 图片 | 155 | Images []string `json:"images"` // 图片 |
| 156 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 156 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -167,7 +167,7 @@ type MiniArticleDraftUpdateRequest struct { | @@ -167,7 +167,7 @@ type MiniArticleDraftUpdateRequest struct { | ||
| 167 | CompanyId int64 `json:",optional"` | 167 | CompanyId int64 `json:",optional"` |
| 168 | AuthorId int64 `json:",optional"` // 发布人 | 168 | AuthorId int64 `json:",optional"` // 发布人 |
| 169 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 169 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 170 | - Content []string `json:"content"` // 填写的内容 | 170 | + Section []string `json:"section"` // 填写的内容 |
| 171 | Title string `json:"title"` // 标题 | 171 | Title string `json:"title"` // 标题 |
| 172 | Images []string `json:"images"` // 图片 | 172 | Images []string `json:"images"` // 图片 |
| 173 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 173 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -192,11 +192,12 @@ type MiniArticleDraftSearchMeResponse struct { | @@ -192,11 +192,12 @@ type MiniArticleDraftSearchMeResponse struct { | ||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | type MiniArticleDraftItem struct { | 194 | type MiniArticleDraftItem struct { |
| 195 | - Id int64 `json:"id"` | ||
| 196 | - Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | ||
| 197 | - Content []string `json:"content"` // 填写的内容 | ||
| 198 | - Title string `json:"title"` // 标题 | ||
| 199 | - Images []string `json:"images"` // 图片 | 195 | + Id int64 `json:"id"` |
| 196 | + Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | ||
| 197 | + Section []string `json:"section"` // 填写的内容 | ||
| 198 | + Title string `json:"title"` // 标题 | ||
| 199 | + Images []string `json:"images"` // 图片 | ||
| 200 | + CreatedAt int64 `json:"createdAt"` | ||
| 200 | } | 201 | } |
| 201 | 202 | ||
| 202 | type MiniArticleDraftGetMeRequest struct { | 203 | type MiniArticleDraftGetMeRequest struct { |
| @@ -208,7 +209,7 @@ type MiniArticleDraftGetMeRequest struct { | @@ -208,7 +209,7 @@ type MiniArticleDraftGetMeRequest struct { | ||
| 208 | type MiniArticleDraftGetMeResponse struct { | 209 | type MiniArticleDraftGetMeResponse struct { |
| 209 | Id int64 `json:"id"` // | 210 | Id int64 `json:"id"` // |
| 210 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 | 211 | Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式 |
| 211 | - Content []string `json:"content"` // 填写的内容 | 212 | + Section []string `json:"Section"` // 填写的内容 |
| 212 | Title string `json:"title"` // 标题 | 213 | Title string `json:"title"` // 标题 |
| 213 | Images []string `json:"images"` // 图片 | 214 | Images []string `json:"images"` // 图片 |
| 214 | WhoRead []int64 `json:"whoRead"` // 谁可以看 | 215 | WhoRead []int64 `json:"whoRead"` // 谁可以看 |
| @@ -2,6 +2,7 @@ package models | @@ -2,6 +2,7 @@ package models | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "time" | ||
| 5 | 6 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 7 | "gorm.io/gorm" | 8 | "gorm.io/gorm" |
| @@ -31,13 +32,14 @@ func (m *ArticleDraft) TableName() string { | @@ -31,13 +32,14 @@ func (m *ArticleDraft) TableName() string { | ||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | func (m *ArticleDraft) BeforeCreate(tx *gorm.DB) (err error) { | 34 | func (m *ArticleDraft) BeforeCreate(tx *gorm.DB) (err error) { |
| 34 | - // m.CreatedAt = time.Now().Unix() | ||
| 35 | - // m.UpdatedAt = time.Now().Unix() | 35 | + nowTime := time.Now().Unix() |
| 36 | + m.CreatedAt = nowTime | ||
| 37 | + m.UpdatedAt = nowTime | ||
| 36 | return | 38 | return |
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | func (m *ArticleDraft) BeforeUpdate(tx *gorm.DB) (err error) { | 41 | func (m *ArticleDraft) BeforeUpdate(tx *gorm.DB) (err error) { |
| 40 | - // m.UpdatedAt = time.Now().Unix() | 42 | + m.UpdatedAt = time.Now().Unix() |
| 41 | return | 43 | return |
| 42 | } | 44 | } |
| 43 | 45 |
-
请 注册 或 登录 后发表评论