Skip to content

Commit aaa52a3

Browse files
author
erangi-ar
committed
Implement CRUD operations for services with soft delete functionality
1 parent ed26c07 commit aaa52a3

File tree

7 files changed

+441
-0
lines changed

7 files changed

+441
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
UPDATE services
2+
SET deleted = true,
3+
updated_at = :updated_at::timestamp with time zone
4+
WHERE id = :id AND deleted = false;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT
2+
id,
3+
name,
4+
description,
5+
service_id,
6+
ruuter_type,
7+
current_state,
8+
is_common,
9+
slot,
10+
entities,
11+
examples,
12+
structure,
13+
endpoints,
14+
created_at,
15+
updated_at
16+
FROM services
17+
WHERE id = :id AND deleted = false;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
INSERT INTO services (
2+
name,
3+
description,
4+
service_id,
5+
ruuter_type,
6+
current_state,
7+
is_common,
8+
slot,
9+
entities,
10+
examples,
11+
structure,
12+
endpoints,
13+
created_at,
14+
updated_at
15+
) VALUES (
16+
:name,
17+
:description,
18+
:service_id,
19+
:ruuter_type::ruuter_request_type,
20+
:current_state::service_state,
21+
:is_common,
22+
:slot,
23+
:entities::text[],
24+
:examples::text[],
25+
:structure::json,
26+
:endpoints::json,
27+
:created_at::timestamp with time zone,
28+
:updated_at::timestamp with time zone
29+
) RETURNING
30+
id,
31+
name,
32+
description,
33+
service_id,
34+
ruuter_type,
35+
current_state,
36+
is_common,
37+
slot,
38+
entities,
39+
examples,
40+
structure,
41+
endpoints,
42+
created_at,
43+
updated_at;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
UPDATE services
2+
SET
3+
name = :name,
4+
description = :description,
5+
service_id = :service_id,
6+
ruuter_type = :ruuter_type::ruuter_request_type,
7+
current_state = :current_state::service_state,
8+
is_common = :is_common,
9+
slot = :slot,
10+
entities = :entities::text[],
11+
examples = :examples::text[],
12+
structure = :structure::json,
13+
endpoints = :endpoints::json,
14+
updated_at = :updated_at::timestamp with time zone
15+
WHERE id = :id AND deleted = false
16+
RETURNING
17+
id,
18+
name,
19+
description,
20+
service_id,
21+
ruuter_type,
22+
current_state,
23+
is_common,
24+
slot,
25+
entities,
26+
examples,
27+
structure,
28+
endpoints,
29+
created_at,
30+
updated_at;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
declaration:
2+
call: declare
3+
version: 0.1
4+
description: "Add a new service"
5+
method: post
6+
accepts: json
7+
returns: json
8+
namespace: rag-search
9+
allowlist:
10+
body:
11+
- field: name
12+
type: string
13+
description: "Service name"
14+
- field: description
15+
type: string
16+
description: "Service description"
17+
- field: service_id
18+
type: string
19+
description: "Unique service identifier"
20+
- field: ruuter_type
21+
type: string
22+
description: "Ruuter request type (GET or POST)"
23+
- field: current_state
24+
type: string
25+
description: "Service state (active, inactive, draft)"
26+
- field: is_common
27+
type: boolean
28+
description: "Whether the service is common"
29+
- field: slot
30+
type: string
31+
description: "Intent classification slot"
32+
- field: entities
33+
type: array
34+
description: "Array of entities for intent classification"
35+
- field: examples
36+
type: array
37+
description: "Array of example phrases for intent classification"
38+
- field: structure
39+
type: object
40+
description: "Service configuration structure"
41+
- field: endpoints
42+
type: array
43+
description: "Array of service endpoints"
44+
45+
extract_request_data:
46+
assign:
47+
name: ${incoming.body.name}
48+
description: ${incoming.body.description}
49+
service_id: ${incoming.body.service_id}
50+
ruuter_type: ${incoming.body.ruuter_type || "GET"}
51+
current_state: ${incoming.body.current_state || "draft"}
52+
is_common: ${incoming.body.is_common || false}
53+
slot: ${incoming.body.slot || ""}
54+
entities: ${incoming.body.entities || []}
55+
examples: ${incoming.body.examples || []}
56+
structure: ${incoming.body.structure || {}}
57+
endpoints: ${incoming.body.endpoints || []}
58+
created_at: ${new Date().toISOString()}
59+
updated_at: ${new Date().toISOString()}
60+
next: validate_required_fields
61+
62+
validate_required_fields:
63+
switch:
64+
- condition: "${!name || !description || !service_id}"
65+
next: return_validation_error
66+
next: insert_service
67+
68+
insert_service:
69+
call: http.post
70+
args:
71+
url: "[#RAG_SEARCH_RESQL]/insert-service"
72+
body:
73+
name: ${name}
74+
description: ${description}
75+
service_id: ${service_id}
76+
ruuter_type: ${ruuter_type}
77+
current_state: ${current_state}
78+
is_common: ${is_common}
79+
slot: ${slot}
80+
entities: ${entities}
81+
examples: ${examples}
82+
structure: ${structure}
83+
endpoints: ${endpoints}
84+
created_at: ${created_at}
85+
updated_at: ${updated_at}
86+
result: insert_result
87+
next: handle_insert_response
88+
89+
handle_insert_response:
90+
switch:
91+
- condition: "${insert_result.response.statusCodeValue >= 400}"
92+
next: return_error
93+
next: return_success
94+
95+
return_success:
96+
return:
97+
success: true
98+
message: "Service created successfully"
99+
service: ${insert_result.response.body[0]}
100+
next: end
101+
102+
return_validation_error:
103+
status: 400
104+
return:
105+
success: false
106+
error: "Missing required fields: name, description, and service_id are required"
107+
next: end
108+
109+
return_error:
110+
status: ${insert_result.response.statusCodeValue || 500}
111+
return:
112+
success: false
113+
error: "Failed to create service"
114+
details: ${insert_result.response.body}
115+
next: end
116+
117+
end:
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
declaration:
2+
call: declare
3+
version: 0.1
4+
description: "Delete a service (soft delete)"
5+
method: post
6+
accepts: json
7+
returns: json
8+
namespace: rag-search
9+
allowlist:
10+
body:
11+
- field: id
12+
type: number
13+
description: "Service ID"
14+
15+
extract_request_data:
16+
assign:
17+
id: ${Number(incoming.body.id)}
18+
updated_at: ${new Date().toISOString()}
19+
next: validate_id
20+
21+
validate_id:
22+
switch:
23+
- condition: "${!id}"
24+
next: return_validation_error
25+
next: check_service_exists
26+
27+
check_service_exists:
28+
call: http.post
29+
args:
30+
url: "[#RAG_SEARCH_RESQL]/get-service"
31+
body:
32+
id: ${id}
33+
result: existing_service
34+
next: validate_service_exists
35+
36+
validate_service_exists:
37+
switch:
38+
- condition: "${existing_service.response.body.length > 0}"
39+
next: delete_service
40+
next: return_not_found
41+
42+
delete_service:
43+
call: http.post
44+
args:
45+
url: "[#RAG_SEARCH_RESQL]/delete-service"
46+
body:
47+
id: ${id}
48+
updated_at: ${updated_at}
49+
result: delete_result
50+
next: handle_delete_response
51+
52+
handle_delete_response:
53+
switch:
54+
- condition: "${delete_result.response.statusCodeValue >= 400}"
55+
next: return_error
56+
next: return_success
57+
58+
return_success:
59+
return:
60+
success: true
61+
message: "Service deleted successfully"
62+
next: end
63+
64+
return_validation_error:
65+
status: 400
66+
return:
67+
success: false
68+
error: "Missing required field: id is required"
69+
next: end
70+
71+
return_not_found:
72+
status: 404
73+
return:
74+
success: false
75+
error: "Service not found"
76+
next: end
77+
78+
return_error:
79+
status: ${delete_result.response.statusCodeValue || 500}
80+
return:
81+
success: false
82+
error: "Failed to delete service"
83+
details: ${delete_result.response.body}
84+
next: end
85+
86+
end:

0 commit comments

Comments
 (0)