2026-03-11 22:50:36 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-03-19 16:55:49 +00:00
|
|
|
"errors"
|
2026-03-27 06:08:55 -07:00
|
|
|
"fmt"
|
2026-03-11 22:50:36 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
2026-03-12 23:49:16 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
2026-03-19 16:55:49 +00:00
|
|
|
)
|
2026-03-11 22:50:36 +00:00
|
|
|
|
|
|
|
|
type createReviewPool struct {
|
2026-03-19 16:55:49 +00:00
|
|
|
Status string `json:"status"`
|
|
|
|
|
TaskID int32 `json:"task_id"`
|
|
|
|
|
Updates *platform.PoolUpdate `json:"updates"`
|
2026-03-11 22:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 06:08:55 -07:00
|
|
|
func postReviewPool(ctx context.Context, r *http.Request, user platform.User, req createReviewPool) (string, *nhttp.ErrorWithStatus) {
|
|
|
|
|
id, err := platform.ReviewPoolCreate(ctx, user, req.TaskID, req.Status, req.Updates)
|
2026-03-19 16:55:49 +00:00
|
|
|
|
2026-03-11 22:50:36 +00:00
|
|
|
if err != nil {
|
2026-03-19 16:55:49 +00:00
|
|
|
if errors.As(err, &platform.ErrorNotFound{}) {
|
2026-03-27 06:08:55 -07:00
|
|
|
return "", nhttp.NewErrorStatus(http.StatusNotFound, "review task %d not found", req.TaskID)
|
2026-03-11 22:50:36 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
return "", nhttp.NewError("failed to set review: %w", err)
|
2026-03-11 22:50:36 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
return fmt.Sprintf("/review/%d", id), nil
|
2026-03-11 22:50:36 +00:00
|
|
|
}
|