Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09d31aabac | ||
|
|
b5c77cf8ca | ||
|
|
3045931492 | ||
|
|
928e643ab7 | ||
|
|
6b1f34db79 | ||
|
|
bd27b14a88 | ||
|
|
4bccdc2ded |
@@ -0,0 +1,13 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE log_post
|
||||||
|
DROP CONSTRAINT log_post_log_short_id_position_key,
|
||||||
|
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position) DEFERRABLE;
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE log_post
|
||||||
|
DROP CONSTRAINT log_post_log_short_id_position_key,
|
||||||
|
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position);
|
||||||
|
-- +goose StatementEnd
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"git.aiterp.net/rpdata/api/database/postgres/psqlcore"
|
"git.aiterp.net/rpdata/api/database/postgres/psqlcore"
|
||||||
"git.aiterp.net/rpdata/api/internal/generate"
|
"git.aiterp.net/rpdata/api/internal/generate"
|
||||||
"git.aiterp.net/rpdata/api/models"
|
"git.aiterp.net/rpdata/api/models"
|
||||||
@@ -253,9 +254,9 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = q.DeletePost(ctx, post.ID)
|
err = q.MovePost(ctx, psqlcore.MovePostParams{ID: post.ID, Position: -1})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("pre-delete move failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{
|
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{
|
||||||
@@ -264,12 +265,17 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
|
|||||||
FromPosition: int32(post.Position + 1),
|
FromPosition: int32(post.Position + 1),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("shift failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = q.DeletePost(ctx, post.ID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("delete failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("tx commit failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID)
|
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ WHERE id = @id;
|
|||||||
-- name: SelectComments :many
|
-- name: SelectComments :many
|
||||||
SELECT * FROM story_comment
|
SELECT * FROM story_comment
|
||||||
WHERE (@chapter_id = '' OR chapter_id = @chapter_id)
|
WHERE (@chapter_id = '' OR chapter_id = @chapter_id)
|
||||||
|
ORDER BY fictional_date, created_date
|
||||||
LIMIT NULLIF(@limit_size::INT, 0);
|
LIMIT NULLIF(@limit_size::INT, 0);
|
||||||
|
|
||||||
-- name: DeleteComment :exec
|
-- name: DeleteComment :exec
|
||||||
|
|||||||
+8
-1
@@ -56,7 +56,7 @@ func (s *AuthService) FindKey(ctx context.Context, id string) (*models.Key, erro
|
|||||||
return s.keys.Find(ctx, id)
|
return s.keys.Find(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindKey finds a key by id.
|
// FindUser finds a user by id.
|
||||||
func (s *AuthService) FindUser(ctx context.Context, id string) (*models.User, error) {
|
func (s *AuthService) FindUser(ctx context.Context, id string) (*models.User, error) {
|
||||||
return s.users.Find(ctx, id)
|
return s.users.Find(ctx, id)
|
||||||
}
|
}
|
||||||
@@ -154,6 +154,13 @@ func (s *AuthService) TokenFromContext(ctx context.Context) *models.Token {
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SpinOffContext adds the auth token to a background context.
|
||||||
|
func (s *AuthService) SpinOffContext(ctx context.Context) context.Context {
|
||||||
|
token := s.TokenFromContext(ctx)
|
||||||
|
|
||||||
|
return context.WithValue(context.Background(), contextKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
// RequestWithToken either returns the request, or the request with a new context that
|
// RequestWithToken either returns the request, or the request with a new context that
|
||||||
// has the token.
|
// has the token.
|
||||||
func (s *AuthService) RequestWithToken(r *http.Request) *http.Request {
|
func (s *AuthService) RequestWithToken(r *http.Request) *http.Request {
|
||||||
|
|||||||
+5
-4
@@ -484,15 +484,16 @@ func (s *LogService) EditPost(ctx context.Context, id string, update models.Post
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spinOffCtx := s.authService.SpinOffContext(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
l, err := s.logs.Find(context.Background(), post.LogID)
|
timeout, cancel := context.WithTimeout(spinOffCtx, time.Minute*10)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
l, err := s.logs.Find(timeout, post.LogID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout, cancel := context.WithTimeout(context.Background(), time.Minute*10)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
s.changeService.Submit(timeout, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post)
|
s.changeService.Submit(timeout, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post)
|
||||||
|
|
||||||
_, err = s.refreshLogCharacters(timeout, *l, nil, false)
|
_, err = s.refreshLogCharacters(timeout, *l, nil, false)
|
||||||
|
|||||||
Reference in New Issue
Block a user