summaryrefslogtreecommitdiff
path: root/makima/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server')
-rw-r--r--makima/src/server/handlers/orders.rs85
-rw-r--r--makima/src/server/mod.rs1
-rw-r--r--makima/src/server/openapi.rs7
3 files changed, 12 insertions, 81 deletions
diff --git a/makima/src/server/handlers/orders.rs b/makima/src/server/handlers/orders.rs
index c43c406..cddf6a6 100644
--- a/makima/src/server/handlers/orders.rs
+++ b/makima/src/server/handlers/orders.rs
@@ -11,7 +11,7 @@ use axum::{
use uuid::Uuid;
use crate::db::models::{
- ConvertToStepRequest, CreateOrderRequest, DirectiveStep, LinkContractRequest,
+ CreateOrderRequest, DirectiveStep,
LinkDirectiveRequest, Order, OrderListQuery, OrderListResponse, UpdateOrderRequest,
};
use crate::db::repository;
@@ -32,7 +32,7 @@ use crate::server::state::SharedState;
("type" = Option<String>, Query, description = "Filter by order type"),
("priority" = Option<String>, Query, description = "Filter by priority"),
("directive_id" = Option<Uuid>, Query, description = "Filter by directive ID"),
- ("contract_id" = Option<Uuid>, Query, description = "Filter by contract ID"),
+ ("search" = Option<String>, Query, description = "Text search across title, description, and directive name"),
),
responses(
(status = 200, description = "List of orders", body = OrderListResponse),
@@ -62,7 +62,7 @@ pub async fn list_orders(
query.order_type.as_deref(),
query.priority.as_deref(),
query.directive_id,
- query.contract_id,
+ query.search.as_deref(),
)
.await
{
@@ -327,80 +327,13 @@ pub async fn link_to_directive(
}
}
-/// Link an order to a contract.
-#[utoipa::path(
- post,
- path = "/api/v1/orders/{id}/link-contract",
- params(("id" = Uuid, Path, description = "Order ID")),
- request_body = LinkContractRequest,
- responses(
- (status = 200, description = "Order linked to contract", body = Order),
- (status = 404, description = "Not found", body = ApiError),
- (status = 401, description = "Unauthorized", body = ApiError),
- (status = 503, description = "Database not configured", body = ApiError),
- ),
- security(("bearer_auth" = []), ("api_key" = [])),
- tag = "Orders"
-)]
-pub async fn link_to_contract(
- State(state): State<SharedState>,
- Authenticated(auth): Authenticated,
- Path(id): Path<Uuid>,
- Json(req): Json<LinkContractRequest>,
-) -> impl IntoResponse {
- let Some(ref pool) = state.db_pool else {
- return (
- StatusCode::SERVICE_UNAVAILABLE,
- Json(ApiError::new("DB_UNAVAILABLE", "Database not configured")),
- )
- .into_response();
- };
-
- // Verify the contract exists and belongs to this owner
- match repository::get_contract_for_owner(pool, auth.owner_id, req.contract_id).await {
- Ok(Some(_)) => {}
- Ok(None) => {
- return (
- StatusCode::NOT_FOUND,
- Json(ApiError::new("NOT_FOUND", "Contract not found")),
- )
- .into_response();
- }
- Err(e) => {
- return (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ApiError::new("GET_FAILED", &e.to_string())),
- )
- .into_response();
- }
- }
-
- match repository::link_order_to_contract(pool, auth.owner_id, id, req.contract_id).await {
- Ok(Some(order)) => Json(order).into_response(),
- Ok(None) => (
- StatusCode::NOT_FOUND,
- Json(ApiError::new("NOT_FOUND", "Order not found")),
- )
- .into_response(),
- Err(e) => {
- tracing::error!("Failed to link order to contract: {}", e);
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ApiError::new("LINK_FAILED", &e.to_string())),
- )
- .into_response()
- }
- }
-}
-
/// Convert an order to a directive step.
-/// Creates a new step in the specified directive using the order's title/description,
-/// and links the order to both the directive and the new step.
+/// Creates a new step in the order's linked directive using the order's title/description,
+/// and links the order to the new step. The order must have a directive_id set.
#[utoipa::path(
post,
path = "/api/v1/orders/{id}/convert-to-step",
params(("id" = Uuid, Path, description = "Order ID")),
- request_body = ConvertToStepRequest,
responses(
(status = 201, description = "Directive step created from order", body = DirectiveStep),
(status = 404, description = "Order or directive not found", body = ApiError),
@@ -414,7 +347,6 @@ pub async fn convert_to_step(
State(state): State<SharedState>,
Authenticated(auth): Authenticated,
Path(id): Path<Uuid>,
- Json(req): Json<ConvertToStepRequest>,
) -> impl IntoResponse {
let Some(ref pool) = state.db_pool else {
return (
@@ -424,11 +356,14 @@ pub async fn convert_to_step(
.into_response();
};
- match repository::convert_order_to_step(pool, auth.owner_id, id, req.directive_id).await {
+ match repository::convert_order_to_step(pool, auth.owner_id, id).await {
Ok(Some(step)) => (StatusCode::CREATED, Json(step)).into_response(),
Ok(None) => (
StatusCode::NOT_FOUND,
- Json(ApiError::new("NOT_FOUND", "Order or directive not found")),
+ Json(ApiError::new(
+ "NOT_FOUND",
+ "Order not found or has no linked directive",
+ )),
)
.into_response(),
Err(e) => {
diff --git a/makima/src/server/mod.rs b/makima/src/server/mod.rs
index c963618..6bd5ae0 100644
--- a/makima/src/server/mod.rs
+++ b/makima/src/server/mod.rs
@@ -252,7 +252,6 @@ pub fn make_router(state: SharedState) -> Router {
.delete(orders::delete_order),
)
.route("/orders/{id}/link-directive", post(orders::link_to_directive))
- .route("/orders/{id}/link-contract", post(orders::link_to_contract))
.route("/orders/{id}/convert-to-step", post(orders::convert_to_step))
// Timeline endpoint (unified history for user)
.route("/timeline", get(history::get_timeline))
diff --git a/makima/src/server/openapi.rs b/makima/src/server/openapi.rs
index 9c6463a..87ca9c5 100644
--- a/makima/src/server/openapi.rs
+++ b/makima/src/server/openapi.rs
@@ -8,14 +8,14 @@ use crate::db::models::{
ChangePhaseRequest,
Contract, ContractChatHistoryResponse, ContractChatMessageRecord, ContractEvent,
ContractListResponse, ContractRepository, ContractSummary, ContractWithRelations,
- CleanupTasksResponse, ConvertToStepRequest,
+ CleanupTasksResponse,
CreateContractRequest, CreateDirectiveRequest, CreateDirectiveStepRequest, CreateFileRequest,
CreateManagedRepositoryRequest, CreateOrderRequest, CreateTaskRequest,
Daemon, DaemonDirectoriesResponse,
DaemonDirectory, DaemonListResponse, Directive, DirectiveListResponse,
DirectiveStep, DirectiveSummary, DirectiveWithSteps,
File, FileListResponse, FileSummary,
- LinkContractRequest, LinkDirectiveRequest,
+ LinkDirectiveRequest,
MergeCommitRequest, MergeCompleteCheckResponse, MergeResolveRequest, MergeResultResponse,
MergeSkipRequest, MergeStartRequest, MergeStatusResponse, MeshChatConversation,
MeshChatHistoryResponse, MeshChatMessageRecord,
@@ -137,7 +137,6 @@ use crate::server::messages::{ApiError, AudioEncoding, StartMessage, StopMessage
orders::update_order,
orders::delete_order,
orders::link_to_directive,
- orders::link_to_contract,
orders::convert_to_step,
// Repository history/settings endpoints
repository_history::list_repository_history,
@@ -243,8 +242,6 @@ use crate::server::messages::{ApiError, AudioEncoding, StartMessage, StopMessage
CreateOrderRequest,
UpdateOrderRequest,
LinkDirectiveRequest,
- LinkContractRequest,
- ConvertToStepRequest,
// Repository history schemas
RepositoryHistoryEntry,
RepositoryHistoryListResponse,