282 lines
8.6 KiB
YAML
282 lines
8.6 KiB
YAML
- rest:
|
|
id: user-api
|
|
description: 用户服务
|
|
path: /api/users
|
|
consumes: application/json
|
|
produces: application/json
|
|
delete:
|
|
- id: delete-984c
|
|
description: 删除用户
|
|
path: /deleteUser/{id}
|
|
to: direct:deleteUser
|
|
outType: java.lang.String
|
|
get:
|
|
- id: get-8b80
|
|
description: 获取所有用户列表
|
|
path: /getAllUsers
|
|
to: direct:getAllUsers
|
|
outType: java.util.List
|
|
- id: get-95c8
|
|
description: 根据ID获取用户信息
|
|
path: /getUserById/{id}
|
|
to: direct:getUserById
|
|
post:
|
|
- id: post-c96c
|
|
description: 创建新用户
|
|
path: /createUser
|
|
to: direct:createUser
|
|
type: com.example.model.User
|
|
outType: com.example.model.User
|
|
bindingMode: json
|
|
put:
|
|
- id: put-fa43
|
|
description: 更新用户信息
|
|
path: /updateUser/{id}
|
|
to: direct:updateUser
|
|
type: com.example.model.User
|
|
outType: com.example.model.User
|
|
- route:
|
|
id: get-all-users-route
|
|
from:
|
|
id: from-0b1c
|
|
uri: direct
|
|
parameters:
|
|
name: getAllUsers
|
|
steps:
|
|
- setBody:
|
|
id: setBody-fd7e
|
|
expression:
|
|
constant:
|
|
id: constant-5729
|
|
expression: >-
|
|
SELECT id, username, email, full_name, phone, create_time,
|
|
update_time FROM users ORDER BY id
|
|
- to:
|
|
id: to-a097
|
|
uri: jdbc
|
|
parameters:
|
|
dataSourceName: PostgresDatabase
|
|
- marshal:
|
|
id: marshal-f876
|
|
json:
|
|
id: json-4aff
|
|
- route:
|
|
id: get-user-by-id-route
|
|
from:
|
|
id: from-c50a
|
|
uri: direct
|
|
parameters:
|
|
name: getUserById
|
|
steps:
|
|
- setBody:
|
|
id: setBody-ff17
|
|
expression:
|
|
simple:
|
|
id: simple-137e
|
|
expression: >-
|
|
SELECT id, username, email, full_name as fullName, phone,
|
|
create_time as createTime, update_time as updateTime FROM
|
|
users WHERE id = ${header.id}
|
|
- to:
|
|
id: to-5ad5
|
|
uri: jdbc
|
|
parameters:
|
|
dataSourceName: dataSource
|
|
- choice:
|
|
id: choice-4f8d
|
|
when:
|
|
- id: when-c8e8
|
|
expression:
|
|
simple:
|
|
id: simple-73fc
|
|
expression: ${body.size} > 0
|
|
steps:
|
|
- transform:
|
|
id: transform-5efd
|
|
expression:
|
|
simple:
|
|
id: simple-84b8
|
|
expression: ${body[0]}
|
|
- marshal:
|
|
id: marshal-6650
|
|
json:
|
|
id: json-7743
|
|
otherwise:
|
|
id: otherwise-b227
|
|
steps:
|
|
- setHeader:
|
|
id: setHeader-15a3
|
|
name: CamelHttpResponseCode
|
|
expression:
|
|
constant:
|
|
id: constant-37e1
|
|
expression: "404"
|
|
- setBody:
|
|
id: setBody-634d
|
|
expression:
|
|
constant:
|
|
id: constant-50fa
|
|
expression: "{\"error\": \"用户不存在\"}"
|
|
- marshal:
|
|
id: marshal-f5a3
|
|
json:
|
|
id: json-cf61
|
|
- route:
|
|
id: create-user-route
|
|
from:
|
|
id: from-b805
|
|
uri: direct
|
|
parameters:
|
|
name: createUser
|
|
steps:
|
|
- setBody:
|
|
id: setBody-2d9f
|
|
expression:
|
|
simple:
|
|
id: simple-9223
|
|
expression: >-
|
|
INSERT INTO users (username, email, full_name, phone) VALUES
|
|
('${body.username}', '${body.email}', '${body.fullName}',
|
|
'${body.phone}') RETURNING id, username, email, full_name as
|
|
fullName, phone, create_time as createTime, update_time as
|
|
updateTime
|
|
- to:
|
|
id: to-c2d7
|
|
uri: jdbc
|
|
parameters:
|
|
dataSourceName: dataSource
|
|
- transform:
|
|
id: transform-47bb
|
|
expression:
|
|
simple:
|
|
id: simple-f601
|
|
expression: ${body[0]}
|
|
- route:
|
|
id: update-user-route
|
|
from:
|
|
id: from-72c4
|
|
uri: direct
|
|
parameters:
|
|
name: updateUser
|
|
steps:
|
|
- setBody:
|
|
id: setBody-67d8
|
|
expression:
|
|
simple:
|
|
id: simple-a84e
|
|
expression: >-
|
|
UPDATE users SET username = '${body.username}',
|
|
email = '${body.email}',
|
|
full_name = '${body.fullName}',
|
|
phone = '${body.phone}',
|
|
update_time = CURRENT_TIMESTAMP
|
|
WHERE id = ${header.id} RETURNING id, username, email,
|
|
full_name as fullName, phone, create_time as createTime,
|
|
update_time as updateTime
|
|
- to:
|
|
id: to-183c
|
|
uri: jdbc
|
|
parameters:
|
|
dataSourceName: dataSource
|
|
- choice:
|
|
id: choice-56d3
|
|
when:
|
|
- id: when-ccfc
|
|
expression:
|
|
simple:
|
|
id: simple-5121
|
|
expression: ${body.size} > 0
|
|
steps:
|
|
- transform:
|
|
id: transform-9765
|
|
expression:
|
|
simple:
|
|
id: simple-f8e2
|
|
expression: ${body[0]}
|
|
otherwise:
|
|
id: otherwise-181a
|
|
steps:
|
|
- setHeader:
|
|
id: setHeader-5730
|
|
name: CamelHttpResponseCode
|
|
expression:
|
|
constant:
|
|
id: constant-82c6
|
|
expression: "404"
|
|
- setBody:
|
|
id: setBody-a681
|
|
expression:
|
|
constant:
|
|
id: constant-ced6
|
|
expression: "{\"error\": \"用户不存在\"}"
|
|
- marshal:
|
|
id: marshal-18ea
|
|
json:
|
|
id: json-c22b
|
|
- route:
|
|
id: delete-user-route
|
|
from:
|
|
id: from-59ba
|
|
uri: direct
|
|
parameters:
|
|
name: deleteUser
|
|
steps:
|
|
- setBody:
|
|
id: setBody-ccdd
|
|
expression:
|
|
simple:
|
|
id: simple-e35c
|
|
expression: DELETE FROM users WHERE id = ${header.id} RETURNING id
|
|
- to:
|
|
id: to-737a
|
|
uri: jdbc
|
|
parameters:
|
|
dataSourceName: dataSource
|
|
- choice:
|
|
id: choice-723e
|
|
when:
|
|
- id: when-ae6b
|
|
expression:
|
|
simple:
|
|
id: simple-5896
|
|
expression: ${body.size} > 0
|
|
steps:
|
|
- setBody:
|
|
id: setBody-1279
|
|
expression:
|
|
constant:
|
|
id: constant-67fc
|
|
expression: "{\"message\": \"用户已成功删除\"}"
|
|
- marshal:
|
|
id: marshal-5a7a
|
|
json:
|
|
id: json-6243
|
|
otherwise:
|
|
id: otherwise-2317
|
|
steps:
|
|
- setHeader:
|
|
id: setHeader-ff9f
|
|
name: CamelHttpResponseCode
|
|
expression:
|
|
constant:
|
|
id: constant-57b7
|
|
expression: "404"
|
|
- setBody:
|
|
id: setBody-1ee6
|
|
expression:
|
|
constant:
|
|
id: constant-de9d
|
|
expression: "{\"error\": \"用户不存在\"}"
|
|
- marshal:
|
|
id: marshal-7fca
|
|
json:
|
|
id: json-ff43
|
|
- beans:
|
|
- name: PostgresDatabase
|
|
type: "#class:org.apache.commons.dbcp2.BasicDataSource"
|
|
properties:
|
|
username: postgres
|
|
password: 1qaz123$
|
|
url: jdbc:postgresql://192.168.56.12:5432/user_db
|
|
driverClassName: org.postgresql.Driver
|