-
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.
- Loading branch information
Showing
11 changed files
with
87 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(Score::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(Score::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(Score::User).big_unsigned().not_null()) | ||
.col(ColumnDef::new(Score::Judge).big_unsigned().not_null()) | ||
.col(ColumnDef::new(Score::Survey).integer().not_null()) | ||
.col(ColumnDef::new(Score::Answer).integer().not_null()) | ||
.col(ColumnDef::new(Score::Scores).array(ColumnType::Json).not_null()) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(Score::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Score { | ||
Table, | ||
Id, | ||
User, | ||
Judge, | ||
Survey, | ||
Answer, | ||
Scores, | ||
} |
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,19 +1,24 @@ | ||
use crate::model::question::QuestionType; | ||
use crate::model::question::{Condition, QuestionType}; | ||
use crate::service::questions::save_question; | ||
use axum::Json; | ||
use sea_orm::JsonValue; | ||
use serde::Serialize; | ||
use crate::model::ValueWithTitle; | ||
|
||
pub async fn new_question(Json(question): Json<NewQuestionRequest>) -> String { | ||
let id = save_question(question.content, question.r#type, question.values, question.condition, question.required, None).await; | ||
let content = serde_json::to_value(question.content).unwrap(); | ||
let values = question.values.map(|values| | ||
values.iter().map(|v| serde_json::to_value(v).unwrap()).collect()); | ||
let condition = question.condition.map(|c| serde_json::to_string(&c).unwrap()); | ||
|
||
let id = save_question(content, question.r#type, values, condition, question.required, None).await; | ||
id.to_string() | ||
} | ||
|
||
#[derive(serde::Deserialize, Serialize)] | ||
pub struct NewQuestionRequest { | ||
pub content: JsonValue, | ||
pub content: ValueWithTitle, | ||
pub r#type: QuestionType, | ||
pub values: Option<Vec<JsonValue>>, | ||
pub condition: Option<String>, | ||
pub values: Option<Vec<ValueWithTitle>>, | ||
pub condition: Option<Vec<Condition>>, | ||
pub required: bool, | ||
} |
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ pub mod admin; | |
pub mod answer; | ||
pub mod page; | ||
pub mod question; | ||
pub mod score; | ||
pub mod survey; |
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,20 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "score")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub user: i64, | ||
pub judge: i64, | ||
pub survey: i32, | ||
pub answer: i32, | ||
pub scores: Vec<Json>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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