| 85 | } |
| 86 | |
| 87 | func (i *imlDocService) Save(ctx context.Context, input *SaveDoc) error { |
| 88 | info, err := i.store.First(ctx, map[string]interface{}{"sid": input.Sid}) |
| 89 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 90 | return err |
| 91 | } |
| 92 | userID := utils.UserId(ctx) |
| 93 | if info != nil { |
| 94 | info.Doc = input.Doc |
| 95 | info.Updater = userID |
| 96 | info.UpdateAt = time.Now() |
| 97 | return i.store.Save(ctx, info) |
| 98 | } |
| 99 | return i.store.Insert(ctx, &service.Doc{ |
| 100 | Sid: input.Sid, |
| 101 | Doc: input.Doc, |
| 102 | CreateAt: time.Now(), |
| 103 | UpdateAt: time.Now(), |
| 104 | Creator: userID, |
| 105 | Updater: userID, |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | func (i *imlDocService) Get(ctx context.Context, sid string) (*Doc, error) { |
| 110 | doc, err := i.store.First(ctx, map[string]interface{}{"sid": sid}) |