Skip to content

Commit f98edc6

Browse files
committed
feat: add test field to UserStageModel
1 parent 21acdb7 commit f98edc6

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Migration to add test column to user_stages table
2+
-- Stores test result status (passed/failed) for user stage progress
3+
4+
ALTER TABLE user_stages ADD COLUMN test TEXT NOT NULL DEFAULT 'failed';
5+
6+
-- Update existing records to maintain consistency
7+
UPDATE user_stages SET test = 'failed' WHERE test IS NULL;

openapi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@
11611161
"course_slug",
11621162
"stage_slug",
11631163
"status",
1164+
"test",
11641165
"started_at"
11651166
],
11661167
"properties": {
@@ -1188,6 +1189,10 @@
11881189
"status": {
11891190
"type": "string",
11901191
"description": "Current progress status (in_progress, completed)"
1192+
},
1193+
"test": {
1194+
"type": "string",
1195+
"description": "Test result status (passed, failed)"
11911196
}
11921197
}
11931198
},

src/model/stage.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ pub struct UserStageModel {
125125
/// Current progress status (in_progress, completed)
126126
pub status: String,
127127

128+
/// Test result status (passed, failed)
129+
pub test: String,
130+
128131
/// Timestamp when the stage was started
129132
pub started_at: DateTime<Utc>,
130133

@@ -142,11 +145,18 @@ impl UserStageModel {
142145
stage_id,
143146
stage_slug: String::new(),
144147
status: "in_progress".to_string(),
148+
test: "failed".to_string(),
145149
started_at: Utc::now(),
146150
completed_at: None,
147151
}
148152
}
149153

154+
/// Marks the stage as test passed
155+
pub fn passed(mut self) -> Self {
156+
self.test = "passed".to_string();
157+
self
158+
}
159+
150160
/// Marks the stage as completed with current timestamp
151161
pub fn complete(mut self) -> Self {
152162
self.status = "completed".to_string();

src/repository/stage.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ impl StageRepository {
343343
r#"
344344
WITH inserted AS (
345345
INSERT INTO user_stages (
346-
id, user_course_id, stage_id, status, started_at
347-
) VALUES ($1, $2, $3, $4, $5)
346+
id, user_course_id, stage_id, status, test, started_at
347+
) VALUES ($1, $2, $3, $4, $5, $6)
348348
RETURNING *
349349
)
350350
SELECT
@@ -361,6 +361,7 @@ impl StageRepository {
361361
.bind(user_stage.user_course_id)
362362
.bind(user_stage.stage_id)
363363
.bind(&user_stage.status)
364+
.bind(&user_stage.test)
364365
.bind(user_stage.started_at)
365366
.fetch_one(&mut **tx)
366367
.await?;
@@ -381,7 +382,8 @@ impl StageRepository {
381382
UPDATE user_stages
382383
SET
383384
status = $2,
384-
completed_at = $3
385+
test = $3,
386+
completed_at = $4
385387
WHERE id = $1
386388
RETURNING *
387389
)
@@ -397,6 +399,7 @@ impl StageRepository {
397399
)
398400
.bind(user_stage.id)
399401
.bind(&user_stage.status)
402+
.bind(&user_stage.test)
400403
.bind(user_stage.completed_at)
401404
.fetch_one(&mut **tx)
402405
.await?;

src/response/stage.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ pub struct UserStageResponse {
116116
/// Current progress status (in_progress, completed)
117117
pub status: String,
118118

119+
/// Test result status (passed, failed)
120+
pub test: String,
121+
119122
/// Timestamp when the stage was started
120123
pub started_at: DateTime<Utc>,
121124

@@ -129,6 +132,7 @@ impl From<UserStageModel> for UserStageResponse {
129132
course_slug: model.course_slug,
130133
stage_slug: model.stage_slug,
131134
status: model.status,
135+
test: model.test,
132136
started_at: model.started_at,
133137
completed_at: model.completed_at,
134138
}

src/service/stage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl StageService {
107107
let mut tx = ctx.database.pool().begin().await?;
108108

109109
// Mark the stage as completed.
110-
user_stage = user_stage.complete();
110+
user_stage = user_stage.passed().complete();
111111
let completed_stage = StageRepository::update_user_stage(&mut tx, &user_stage).await?;
112112

113113
// Update user course and create next stage if needed.
@@ -166,6 +166,6 @@ impl StageService {
166166
StageRepository::get_user_stage(&ctx.database, user_id, course_slug, stage_slug)
167167
.await?;
168168

169-
Ok(UserStageStatusResponse { status: user_stage.status, test: "failed".into() })
169+
Ok(UserStageStatusResponse { status: user_stage.status, test: user_stage.test })
170170
}
171171
}

0 commit comments

Comments
 (0)