Skip to content

Commit

Permalink
feat: add word categories to database, add empty category-related end…
Browse files Browse the repository at this point in the history
…poins
  • Loading branch information
simongoricar committed Feb 22, 2024
1 parent 7759a58 commit 6e93eeb
Show file tree
Hide file tree
Showing 21 changed files with 886 additions and 46 deletions.
22 changes: 22 additions & 0 deletions kolomoni/src/api/v1/dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
use std::str::FromStr;

use actix_web::{web, Scope};
use kolomoni_database::entities;
use miette::IntoDiagnostic;
use sea_orm::prelude::Uuid;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use self::{
categories::categories_router,
english_word::english_dictionary_router,
slovene_word::slovene_dictionary_router,
suggestions::suggested_translations_router,
translations::translations_router,
};
use crate::api::errors::APIError;

pub mod categories;
pub mod english_word;
pub mod slovene_word;
pub mod suggestions;
pub mod translations;


#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, ToSchema)]
pub struct Category {
pub id: i32,
pub name: String,
}

impl Category {
pub fn from_database_model(model: entities::category::Model) -> Self {
Self {
id: model.id,
name: model.name,
}
}
}


pub fn parse_string_into_uuid(potential_uuid: &str) -> Result<Uuid, APIError> {
let target_word_uuid = Uuid::from_str(potential_uuid)
.into_diagnostic()
Expand All @@ -34,4 +55,5 @@ pub fn dictionary_router() -> Scope {
.service(english_dictionary_router())
.service(suggested_translations_router())
.service(translations_router())
.service(categories_router())
}
74 changes: 74 additions & 0 deletions kolomoni/src/api/v1/dictionary/categories.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use actix_web::{delete, get, patch, post, web, Scope};

use crate::api::errors::EndpointResult;




#[post("")]
pub async fn create_category() -> EndpointResult {
todo!();
}




#[get("")]
pub async fn get_all_categories() -> EndpointResult {
todo!();
}




#[get("/{category_id}")]
pub async fn get_specific_category() -> EndpointResult {
todo!();
}




#[patch("/{category_id}")]
pub async fn update_specific_category() -> EndpointResult {
todo!();
}




#[delete("/{category_id}")]
pub async fn delete_specific_category() -> EndpointResult {
todo!();
}




#[post("/{category_id}/word-link/{word_uuid}")]
pub async fn link_word_to_category() -> EndpointResult {
todo!();
}




#[delete("/{category_id}/word-link/{word_uuid}")]
pub async fn unlink_word_from_category() -> EndpointResult {
todo!();
}




#[rustfmt::skip]
pub fn categories_router() -> Scope {
web::scope("/category")
.service(create_category)
.service(get_all_categories)
.service(get_specific_category)
.service(update_specific_category)
.service(delete_specific_category)
.service(link_word_to_category)
.service(unlink_word_from_category)
}
Loading

0 comments on commit 6e93eeb

Please sign in to comment.