-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1633 from scpwiki/WJ-1161-messages
[WJ-1161] [WJ-373] [WJ-770] [WJ-1128] Add message support
- Loading branch information
Showing
28 changed files
with
1,557 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* endpoints/message.rs | ||
* | ||
* DEEPWELL - Wikijump API provider and database manager | ||
* Copyright (C) 2019-2023 Wikijump Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use super::prelude::*; | ||
use crate::services::message::{ | ||
CreateMessageDraft, DeleteMessageDraft, SendMessageDraft, UpdateMessageDraft, | ||
}; | ||
|
||
pub async fn message_draft_create(mut req: ApiRequest) -> ApiResponse { | ||
let txn = req.database().begin().await?; | ||
let ctx = ServiceContext::new(&req, &txn); | ||
|
||
let input: CreateMessageDraft = req.body_json().await?; | ||
tide::log::info!("Creating new message draft for user ID {}", input.user_id); | ||
|
||
let output = MessageService::create_draft(&ctx, input).await?; | ||
txn.commit().await?; | ||
build_json_response(&output, StatusCode::Ok) | ||
} | ||
|
||
pub async fn message_draft_update(mut req: ApiRequest) -> ApiResponse { | ||
let txn = req.database().begin().await?; | ||
let ctx = ServiceContext::new(&req, &txn); | ||
|
||
let input: UpdateMessageDraft = req.body_json().await?; | ||
tide::log::info!( | ||
"Updating message draft for draft ID {}", | ||
input.message_draft_id | ||
); | ||
|
||
let output = MessageService::update_draft(&ctx, input).await?; | ||
txn.commit().await?; | ||
build_json_response(&output, StatusCode::Ok) | ||
} | ||
|
||
pub async fn message_draft_send(mut req: ApiRequest) -> ApiResponse { | ||
let txn = req.database().begin().await?; | ||
let ctx = ServiceContext::new(&req, &txn); | ||
|
||
let SendMessageDraft { message_draft_id } = req.body_json().await?; | ||
tide::log::info!("Sending message draft with ID {message_draft_id}"); | ||
|
||
let output = MessageService::send(&ctx, &message_draft_id).await?; | ||
txn.commit().await?; | ||
build_json_response(&output, StatusCode::Ok) | ||
} | ||
|
||
pub async fn message_draft_delete(mut req: ApiRequest) -> ApiResponse { | ||
let txn = req.database().begin().await?; | ||
let ctx = ServiceContext::new(&req, &txn); | ||
|
||
let DeleteMessageDraft { message_draft_id } = req.body_json().await?; | ||
tide::log::info!("Deleting message draft with ID {message_draft_id}"); | ||
|
||
MessageService::delete_draft(&ctx, message_draft_id).await?; | ||
txn.commit().await?; | ||
Ok(Response::new(StatusCode::Ok)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.