-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add work-in-progress translation suggestions
- Loading branch information
1 parent
8e5c0b4
commit 810808f
Showing
4 changed files
with
91 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
use actix_web::{web, Scope}; | ||
|
||
use self::{english_word::english_dictionary_router, slovene_word::slovene_dictionary_router}; | ||
use self::{ | ||
english_word::english_dictionary_router, | ||
slovene_word::slovene_dictionary_router, | ||
suggestions::suggested_translations_router, | ||
}; | ||
|
||
pub mod english_word; | ||
pub mod slovene_word; | ||
pub mod suggestions; | ||
|
||
|
||
#[rustfmt::skip] | ||
pub fn dictionary_router() -> Scope { | ||
web::scope("/dictionary") | ||
.service(slovene_dictionary_router()) | ||
.service(english_dictionary_router()) | ||
.service(suggested_translations_router()) | ||
} |
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,45 @@ | ||
use actix_web::{post, web, Scope}; | ||
use kolomoni_auth::Permission; | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
use crate::{ | ||
api::errors::EndpointResult, | ||
authentication::UserAuthenticationExtractor, | ||
require_authentication, | ||
require_permission, | ||
state::ApplicationState, | ||
}; | ||
|
||
|
||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, ToSchema)] | ||
pub struct TranslationSuggestionRequest { | ||
english_word_id: String, | ||
slovene_word_id: String, | ||
} | ||
|
||
#[post("")] | ||
pub async fn suggest_a_translation( | ||
state: ApplicationState, | ||
authentication: UserAuthenticationExtractor, | ||
request_body: web::Json<TranslationSuggestionRequest>, | ||
) -> EndpointResult { | ||
let authenticated_user = require_authentication!(authentication); | ||
require_permission!( | ||
state, | ||
authenticated_user, | ||
Permission::SuggestionCreate | ||
); | ||
|
||
// TODO Continue from here. | ||
|
||
|
||
todo!(); | ||
} | ||
|
||
|
||
#[rustfmt::skip] | ||
pub fn suggested_translations_router() -> Scope { | ||
web::scope("/suggestion") | ||
.service(suggest_a_translation) | ||
} |
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
37 changes: 37 additions & 0 deletions
37
kolomoni_database/src/mutation/word_translation_suggestion.rs
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,37 @@ | ||
use chrono::Utc; | ||
use miette::{Context, IntoDiagnostic, Result}; | ||
use sea_orm::{ActiveModelTrait, ActiveValue, ConnectionTrait, TransactionTrait}; | ||
use uuid::Uuid; | ||
|
||
use crate::entities::word_translation_suggestion; | ||
|
||
|
||
|
||
pub struct NewTranslationSuggestion { | ||
pub english_word_id: Uuid, | ||
pub slovene_word_id: Uuid, | ||
} | ||
|
||
|
||
pub struct TranslationSuggestionMutation; | ||
|
||
impl TranslationSuggestionMutation { | ||
pub async fn create<C: ConnectionTrait + TransactionTrait>( | ||
database: &C, | ||
new_translation_suggestion: NewTranslationSuggestion, | ||
) -> Result<word_translation_suggestion::Model> { | ||
let active_suggestion = word_translation_suggestion::ActiveModel { | ||
english_word_id: ActiveValue::Set(new_translation_suggestion.english_word_id), | ||
slovene_word_id: ActiveValue::Set(new_translation_suggestion.slovene_word_id), | ||
suggested_at: ActiveValue::Set(Utc::now().fixed_offset()), | ||
}; | ||
|
||
let new_suggestion_model = active_suggestion | ||
.insert(database) | ||
.await | ||
.into_diagnostic() | ||
.wrap_err("Failed while inserting new translation suggestion into the database.")?; | ||
|
||
Ok(new_suggestion_model) | ||
} | ||
} |