Skip to content

Commit 786dc43

Browse files
committed
refactor: clean up run169 form name
1 parent 49a3650 commit 786dc43

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

src/application/town_service.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
Town, User,
55
distance::{DistanceUnit, Kilometers, Miles},
66
race::NewRace,
7-
town::{SubmitTown, SubmitTownForGoogle, SubmitTownGoogleForm},
7+
town::{Run169TownsSocietyGoogleForm, SubmitTown, SubmitTownForGoogle},
88
},
99
infrastructure::db::{RaceRepository, TownRepository},
1010
};
@@ -28,6 +28,7 @@ impl TownService {
2828

2929
pub async fn submit_completed_town(&self, user: User, form: SubmitTown) -> Result<(), String> {
3030
let user_id = user.id;
31+
let town_id = form.town_id;
3132
let town_name = self.town_repository.find_by_id(form.town_id).await?.name;
3233
let distance_val = match form.distance_unit {
3334
DistanceUnit::Miles => Miles::new(form.distance_val),
@@ -42,17 +43,14 @@ impl TownService {
4243
notes: form.notes.clone(),
4344
};
4445

45-
SubmitTownGoogleForm::new()
46+
// Submit the town to Run169Towns Society
47+
Run169TownsSocietyGoogleForm::new()
4648
.add_answers(user, google_form)
4749
.submit()
4850
.await?;
4951

5052
// Mark the town as completed.
51-
let _ = self
52-
.town_repository
53-
.mark_completed(user_id, form.town_id)
54-
.await;
55-
53+
let _ = self.town_repository.mark_completed(user_id, town_id).await;
5654
// Always try to create a race, it will reject if there's one that exists.
5755
let _ = self.race_repository.create_race(NewRace::from(form)).await;
5856

src/domain/town.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct SubmitTownForGoogle {
4848
pub notes: String,
4949
}
5050

51-
pub struct SubmitTownGoogleForm {
51+
pub struct Run169TownsSocietyGoogleForm {
5252
form_id: String,
5353
member_id: String,
5454
action: String,
@@ -66,7 +66,7 @@ pub struct SubmitTownGoogleForm {
6666
answers: HashMap<String, String>,
6767
}
6868

69-
impl SubmitTownGoogleForm {
69+
impl Run169TownsSocietyGoogleForm {
7070
pub fn new() -> Self {
7171
Self {
7272
form_id: "1FAIpQLScHViJvQL0G_ZPuCZOIFNsBPthZwDSzbkgiFFeL93wp831diA".to_string(),
@@ -91,7 +91,7 @@ impl SubmitTownGoogleForm {
9191
mut self,
9292
user: User,
9393
form: SubmitTownForGoogle,
94-
) -> CompletedSubmitTownGoogleForm {
94+
) -> CompletedRun169TownsSocietyGoogleForm {
9595
self.answers.insert(
9696
format!("entry.{}", self.member_id),
9797
user.runner_id.unwrap().to_string(),
@@ -129,13 +129,13 @@ impl SubmitTownGoogleForm {
129129
self.answers
130130
.insert(format!("entry.{}", self.comment), form.notes);
131131

132-
CompletedSubmitTownGoogleForm(self)
132+
CompletedRun169TownsSocietyGoogleForm(self)
133133
}
134134
}
135135

136-
pub struct CompletedSubmitTownGoogleForm(SubmitTownGoogleForm);
136+
pub struct CompletedRun169TownsSocietyGoogleForm(Run169TownsSocietyGoogleForm);
137137

138-
impl CompletedSubmitTownGoogleForm {
138+
impl CompletedRun169TownsSocietyGoogleForm {
139139
pub async fn submit(&self) -> Result<(), String> {
140140
let base_url = "https://docs.google.com/forms/d/e";
141141
let url = format!("{}/{}/formResponse", base_url, self.0.form_id);

src/routes/submit_town.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::domain::distance::DistanceUnit;
22
use crate::domain::race::{RaceView, SubmitTownSearchParams};
33
use crate::filters;
4+
use crate::util::htmx::HTMX;
45
use crate::util::pagination::PaginatedResponse;
56
use crate::{
67
SharedState,
@@ -71,12 +72,7 @@ async fn submit_town(
7172
// TODO: We'll need to handle the error scenario and success scenario.
7273
// We should celebrate the user's achievement!
7374
match state.town_service.submit_completed_town(*user, form).await {
74-
Ok(_) => SubmitTownPage {
75-
towns: state.town_service.find_all().await,
76-
max_race_date: Utc::now().with_timezone(&New_York).date_naive(),
77-
..Default::default()
78-
}
79-
.into_response(),
75+
Ok(_) => HTMX::refresh().into_response(),
8076
Err(_) => SubmitTownPage {
8177
towns: state.town_service.find_all().await,
8278
max_race_date: Utc::now().with_timezone(&New_York).date_naive(),

0 commit comments

Comments
 (0)