@@ -209,6 +209,9 @@ func (m *Memory) CreatePost(_ context.Context, post *Post) error {
|
||||
if err := preparePost(post); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := preparePostImages(post); err != nil {
|
||||
return err
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if _, ok := m.users[post.AuthorID]; !ok {
|
||||
@@ -287,6 +290,10 @@ func (m *Memory) UpdatePost(_ context.Context, post *Post) error {
|
||||
if body == "" {
|
||||
return fmt.Errorf("%w: body is required", ErrInvalidPost)
|
||||
}
|
||||
post.Body = body
|
||||
if err := preparePostImages(post); err != nil {
|
||||
return err
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
existing, ok := m.posts[post.ID]
|
||||
@@ -294,6 +301,7 @@ func (m *Memory) UpdatePost(_ context.Context, post *Post) error {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
existing.Body = body
|
||||
existing.Images = append([]PostImage(nil), post.Images...)
|
||||
existing.UpdatedAt = time.Now().UTC().Format(time.RFC3339Nano)
|
||||
*post = *clonePostWithAuthor(existing, m.users)
|
||||
return nil
|
||||
@@ -451,6 +459,7 @@ func clonePost(post *Post) *Post {
|
||||
parentID := *post.ParentID
|
||||
cp.ParentID = &parentID
|
||||
}
|
||||
cp.Images = append([]PostImage(nil), post.Images...)
|
||||
cp.Replies = nil
|
||||
return &cp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user