@@ -39,6 +39,7 @@ type IProposalService interface {
3939 CreateProposal (ctx context.Context , req * dto.CreateProposalReq ) (* dto.CreateProposalResp , error )
4040 ListProposals (ctx context.Context , req * dto.ListProposalReq ) (* dto.ListProposalResp , error )
4141 GetProposal (ctx context.Context , req * dto.GetProposalReq ) (resp * dto.GetProposalResp , err error )
42+ UpdateProposal (ctx context.Context , req * dto.UpdateProposalReq ) (* dto.UpdateProposalResp , error )
4243}
4344
4445type ProposalService struct {
@@ -216,3 +217,45 @@ func (s *ProposalService) GetProposal(ctx context.Context, req *dto.GetProposalR
216217 Proposal : vo ,
217218 }, nil
218219}
220+
221+ // UpdateProposal 更新提案
222+ func (s * ProposalService ) UpdateProposal (ctx context.Context , req * dto.UpdateProposalReq ) (* dto.UpdateProposalResp , error ) {
223+ //鉴权
224+ userId , ok := ctx .Value (consts .CtxUserID ).(string )
225+ if ! ok || userId == "" {
226+ return nil , errorx .New (errno .ErrUserNotLogin )
227+ }
228+ //查询提案
229+ proposal , err := s .ProposalRepo .FindByID (ctx , req .ProposalID )
230+ if err != nil {
231+ logs .CtxErrorf (ctx , "[ProposalRepo] [FindByID] error: %v, proposalId: %s" , err , req .ProposalID )
232+ return nil , errorx .WrapByCode (err , errno .ErrProposalFindFailed , errorx .KV ("proposalId" , req .ProposalID ))
233+ }
234+ if proposal == nil {
235+ logs .CtxWarnf (ctx , "[ProposalRepo] [FindByID] proposal not found, proposalId: %s" , req .ProposalID )
236+ return nil , errorx .New (errno .ErrProposalNotFound , errorx .KV ("key" , consts .ReqProposalID ), errorx .KV ("value" , req .ProposalID ))
237+ }
238+
239+ //更新提案字段
240+ proposal .Title = req .Title
241+ proposal .Content = req .Content
242+ courseModel , err := s .CourseAssembler .ToCourseDB (ctx , req .Course )
243+ if err != nil {
244+ return nil , errorx .WrapByCode (err , errno .ErrCourseCvtFailed ,
245+ errorx .KV ("src" , "course vo" ), errorx .KV ("dst" , "course model" ),
246+ )
247+ }
248+ proposal .Course = courseModel
249+ proposal .UpdatedAt = time .Now ()
250+
251+ // 执行更新
252+ if err = s .ProposalRepo .UpdateProposal (ctx , proposal ); err != nil {
253+ logs .CtxErrorf (ctx , "[ProposalRepo] [UpdateProposal] error: %v, proposalId: %s" , err , req .ProposalID )
254+ return nil , errorx .WrapByCode (err , errno .ErrProposalUpdateFailed , errorx .KV ("proposalId" , req .ProposalID ))
255+ }
256+
257+ return & dto.UpdateProposalResp {
258+ Resp : dto .Success (),
259+ ProposalID : proposal .ID ,
260+ }, nil
261+ }
0 commit comments