pooly/resources/connections/
mod.rs1use std::sync::Arc;
2
3use actix_web::{delete, get, HttpResponse, patch};
4use actix_web::post;
5use actix_web::Result;
6use actix_web::web::{Data, Json, Path};
7
8use crate::models::query::connections::{ConnectionConfig, ConnectionConfigUpdateCommand};
9use crate::services::connections::config::ConnectionConfigService;
10use crate::services::updatable::UpdatableService;
11
12pub mod access;
13
14
15#[post("/v1/connections")]
16pub async fn create(service: Data<Arc<ConnectionConfigService>>,
17 request: Json<ConnectionConfig>) -> Result<HttpResponse> {
18 match service.create(request.0) {
19 Ok(_) => Ok(HttpResponse::Ok().finish()),
20 Err(err) => Ok(HttpResponse::InternalServerError().json(err))
21 }
22}
23
24#[get("/v1/connections/{id}")]
25pub async fn get(service: Data<Arc<ConnectionConfigService>>,
26 client_id: Path<String>) -> Result<HttpResponse> {
27 match service.get(&client_id.into_inner()) {
28 Ok(config) => Ok(
29 match config {
30 None => HttpResponse::NotFound().finish(),
31 Some(config_value) => HttpResponse::Ok().json(config_value.value())
32 }),
33 Err(err) => Ok(HttpResponse::InternalServerError().json(err))
34 }
35}
36
37#[patch("/v1/connections/{id}")]
38pub async fn update(service: Data<Arc<ConnectionConfigService>>,
39 client_id: Path<String>,
40 request: Json<ConnectionConfigUpdateCommand>) -> Result<HttpResponse> {
41 match service.update(&client_id.into_inner(), request.0) {
42 Ok(updated) => Ok(HttpResponse::Ok().json(updated)),
43 Err(err) => Ok(HttpResponse::InternalServerError().json(err))
44 }
45}
46
47#[delete("/v1/connections/{id}")]
48pub async fn delete(service: Data<Arc<ConnectionConfigService>>,
49 client_id: Path<String>) -> Result<HttpResponse> {
50 match service.delete(&client_id.into_inner()) {
51 Ok(_) => Ok(HttpResponse::Ok().finish()),
52 Err(err) => Ok(HttpResponse::InternalServerError().json(err))
53 }
54}