(
State(state): State<AppState>,
Extension(current_guild): Extension<CurrentUserGuild>,
Json(payload): Json<CreateRequestData>,
)
| 86 | } |
| 87 | |
| 88 | pub async fn create_guild_script( |
| 89 | State(state): State<AppState>, |
| 90 | Extension(current_guild): Extension<CurrentUserGuild>, |
| 91 | Json(payload): Json<CreateRequestData>, |
| 92 | ) -> ApiResult<impl IntoResponse> { |
| 93 | let cs = CreateScript { |
| 94 | enabled: payload.enabled, |
| 95 | original_source: payload.original_source, |
| 96 | name: payload.name, |
| 97 | plugin_auto_update: None, |
| 98 | plugin_id: None, |
| 99 | plugin_version_number: None, |
| 100 | }; |
| 101 | |
| 102 | if let Err(verr) = validate(&cs, &()) { |
| 103 | return Err(ApiErrorResponse::ValidationFailed(verr)); |
| 104 | } |
| 105 | |
| 106 | if state |
| 107 | .db |
| 108 | .get_script(current_guild.id, cs.name.clone()) |
| 109 | .await |
| 110 | .is_ok() |
| 111 | { |
| 112 | return Err(ApiErrorResponse::ValidationFailed(vec![ValidationError { |
| 113 | field: "name".to_string(), |
| 114 | msg: "Name already taken".to_string(), |
| 115 | }])); |
| 116 | } |
| 117 | |
| 118 | let script = state |
| 119 | .db |
| 120 | .create_script(current_guild.id, cs) |
| 121 | .await |
| 122 | .map_err(|err| { |
| 123 | error!(%err, "failed creating guild script"); |
| 124 | ApiErrorResponse::InternalError |
| 125 | })?; |
| 126 | |
| 127 | Ok(Json(script)) |
| 128 | } |
| 129 | |
| 130 | #[derive(Debug, Clone, Deserialize)] |
| 131 | pub struct UpdateRequestData { |
nothing calls this directly
no test coverage detected