Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spotにnoteを追加 #126

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion migrations/20230813182916_spot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ CREATE TABLE spot (
area text NOT NULL,
building text,
floor int,
room text
room text,
note text
);
10 changes: 7 additions & 3 deletions src/database/insert_spot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ where
building,
floor,
room,
note,
} = info;

sqlx::query!(
Expand All @@ -20,13 +21,15 @@ where
area,
building,
floor,
room
) VALUES ( $1, $2, $3, $4, $5 )"#,
room,
note
) VALUES ( $1, $2, $3, $4, $5, $6 )"#,
name,
area.to_string(),
building,
floor.map(|u8| u8 as i32),
room
room,
note
)
.execute(conn)
.await
Expand All @@ -49,6 +52,7 @@ mod tests {
building: Some("3C".to_string()),
floor: Some(2),
room: Some("coinsラウンジ".to_string()),
note: None,
};
let res = insert_spot(&pool, info).await;
assert!(res.is_ok());
Expand Down
8 changes: 6 additions & 2 deletions src/database/update_spot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ where
building,
floor,
room,
note,
} = new_info;
sqlx::query!(
r#"UPDATE spot SET area=$2, building=$3, floor=$4, room=$5 WHERE name=$1"#,
r#"UPDATE spot SET area=$2, building=$3, floor=$4, room=$5, note=$6 WHERE name=$1"#,
name,
area.to_string(),
building,
floor.map(|i| i as i32),
room
room,
note
)
.execute(conn)
.await
Expand All @@ -43,6 +45,7 @@ mod tests {
building: Some("3C".to_string()),
floor: Some(2),
room: Some("coinsラウンジ".to_string()),
note: None,
};
let res = insert_spot(&pool, info).await;
assert!(res.is_ok());
Expand All @@ -53,6 +56,7 @@ mod tests {
building: Some("3C".to_string()),
floor: Some(1),
room: Some("coins計算機室".to_string()),
note: None,
};
let res = update_spot(&pool, new_info).await;
assert!(res.is_ok());
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub struct Spot {
/// 部屋の番号や名前など。
/// 建物ではないところで使う可能性もあるのでOption型。
pub room: Option<String>,
/// 備考
pub note: Option<String>,
}

/// 大まかな範囲を与える区分。
Expand Down
Loading