Add function to parse tag input whatever fuck

This commit is contained in:
~erin 2022-01-23 22:05:52 -05:00
parent fe695541e4
commit af95ebeb66
No known key found for this signature in database
GPG Key ID: DA70E064A8C70F44
3 changed files with 29 additions and 5 deletions

View File

@ -1,12 +1,24 @@
use rocket::form::Form; use rocket::form::Form;
use crate::structures::RecipeForm; use crate::structures::{RecipeForm, Tag};
#[get("/test")] #[get("/test")]
pub fn test() -> String { pub fn test() -> String {
return "Hello! :3".to_string(); return "Hello! :3".to_string();
} }
pub fn parse_tags(tags: String) -> Vec<Tag> {
let split: Vec<&str> = tags.split(",").collect();
let mut tags_vec: Vec<Tag> = Vec::new();
for i in split {
tags_vec.push(Tag::new(i
.replace(" ", "")
.replace("#", "")));
}
return tags_vec;
}
#[post("/new-recipe", data = "<recipe>")] #[post("/new-recipe", data = "<recipe>")]
pub fn new_recipe(recipe: Form<RecipeForm>) -> String { pub fn new_recipe(recipe: Form<RecipeForm>) -> String {
return recipe.name.clone();
return recipe.recipe_name.to_owned();
} }

View File

@ -82,7 +82,9 @@ pub struct Tag(pub char, pub String);
impl Tag { impl Tag {
pub fn new(s: String) -> Tag { pub fn new(s: String) -> Tag {
Tag('#', s) let mut fuck = s;
fuck.make_ascii_lowercase();
Tag('#', fuck)
} }
pub fn to_string(&self) -> String { pub fn to_string(&self) -> String {
@ -107,8 +109,8 @@ impl Tag {
#[derive(FromForm)] #[derive(FromForm)]
pub struct RecipeForm { pub struct RecipeForm {
pub name: String, pub recipe_name: String,
pub author: String, pub author_name: String,
pub tags: String, pub tags: String,
pub prep_time: String, pub prep_time: String,
pub cooking_time: String, pub cooking_time: String,

View File

@ -2,6 +2,7 @@
mod tests { mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope. // Note this useful idiom: importing names from outer (for mod tests) scope.
use crate::structures::*; use crate::structures::*;
use crate::networking::{parse_tags};
#[test] #[test]
fn test_tag_new() { fn test_tag_new() {
@ -22,4 +23,13 @@ mod tests {
fn test_shortcode_conversion() { fn test_shortcode_conversion() {
assert_eq!(construct_shortcode("Test SHORtcode".to_string()), "test-shortcode".to_string()); assert_eq!(construct_shortcode("Test SHORtcode".to_string()), "test-shortcode".to_string());
} }
#[test]
fn test_parse_tags() {
assert_eq!(parse_tags("one,TWO ,tHRee, #four".to_string()), vec![
Tag('#',"one".to_string()),
Tag('#',"two".to_string()),
Tag('#',"three".to_string()),
Tag('#',"four".to_string())]);
}
} }