@@ -11,7 +11,7 @@ use sea_orm::{
1111 ActiveValue , ColumnTrait , Condition , DatabaseConnection , DbErr , EntityTrait , IntoActiveModel ,
1212 QueryFilter , QuerySelect ,
1313} ;
14- use tracing:: { error, info, trace , warn} ;
14+ use tracing:: { error, info, warn} ;
1515
1616pub async fn get_history (
1717 db : & DatabaseConnection ,
@@ -64,9 +64,9 @@ pub async fn create_history(
6464
6565#[ derive( Debug , Clone ) ]
6666pub struct SubmitResult {
67- pub remaining_tries : usize ,
68- pub is_dirty : bool ,
6967 pub submit_history : SubmitHistory ,
68+ pub is_dirty : bool ,
69+ pub is_completed : bool ,
7070}
7171
7272pub async fn submit_to_history (
@@ -83,15 +83,24 @@ pub async fn submit_to_history(
8383 . columns ( [
8484 histories:: Column :: SubmitHistory ,
8585 histories:: Column :: IsDirty ,
86+ histories:: Column :: IsCompleted ,
8687 histories:: Column :: OriginalSolution ,
8788 ] )
88- . into_tuple :: < ( Option < SubmitHistory > , bool , PuzzleSolution ) > ( )
89+ . into_tuple :: < ( Option < SubmitHistory > , bool , bool , PuzzleSolution ) > ( )
8990 . one ( db)
9091 . await
9192 . ok ( )
9293 . flatten ( )
9394 {
94- Some ( ( submit_history, is_dirty, solution) ) => {
95+ Some ( ( submit_history, is_dirty, true , _) ) => {
96+ warn ! ( "history is completed for {date} with session {session}!" ) ;
97+ return Ok ( SubmitResult {
98+ submit_history : submit_history. unwrap_or_default ( ) ,
99+ is_dirty,
100+ is_completed : true ,
101+ } ) ;
102+ }
103+ Some ( ( submit_history, is_dirty, false , solution) ) => {
95104 ( submit_history. unwrap_or_default ( ) , is_dirty, solution)
96105 }
97106 None => {
@@ -100,8 +109,9 @@ pub async fn submit_to_history(
100109 }
101110 } ;
102111
112+ let word = SubmitWord :: tint ( answer, & solution) ;
103113 submit_history
104- . submit ( SubmitWord :: tint ( answer , & solution ) )
114+ . submit ( word )
105115 . map_err ( |e| DbErr :: Custom ( e. to_string ( ) ) ) ?;
106116
107117 let active_history = histories:: ActiveModel {
@@ -110,14 +120,17 @@ pub async fn submit_to_history(
110120 submit_history : ActiveValue :: Set ( Some ( submit_history. clone ( ) ) ) ,
111121 original_solution : ActiveValue :: Unchanged ( solution) ,
112122 is_dirty : ActiveValue :: Unchanged ( false ) ,
123+ is_completed : ActiveValue :: Set ( word. all_matches ( ) ) ,
113124 uploaded_at : ActiveValue :: Unchanged ( Utc :: now ( ) . naive_utc ( ) ) ,
114- ..Default :: default ( )
115125 } ;
116126
117127 match Histories :: insert ( active_history)
118128 . on_conflict (
119129 OnConflict :: columns ( [ histories:: Column :: Date , histories:: Column :: Session ] )
120- . update_column ( histories:: Column :: SubmitHistory )
130+ . update_columns ( [
131+ histories:: Column :: SubmitHistory ,
132+ histories:: Column :: IsCompleted ,
133+ ] )
121134 . to_owned ( ) ,
122135 )
123136 . exec ( db)
@@ -126,9 +139,9 @@ pub async fn submit_to_history(
126139 Ok ( _) => {
127140 info ! ( "submitted {answer} to history at {date} with session {session}" ) ;
128141 Ok ( SubmitResult {
129- remaining_tries : submit_history. remaining_tries ( ) ,
130- is_dirty,
131142 submit_history,
143+ is_dirty,
144+ is_completed : word. all_matches ( ) ,
132145 } )
133146 }
134147 Err ( err) => {
0 commit comments