chore: refactored server/handlers/admin.rs
c2601016
2 file(s) · +23 −32
| 136 | 136 | } |
|
| 137 | 137 | }; |
|
| 138 | 138 | ||
| 139 | - | let input = db::WineInput { |
|
| 140 | - | name: &data.base.name, |
|
| 141 | - | origin: &data.base.origin, |
|
| 142 | - | grape: &data.base.grape, |
|
| 143 | - | notes: &data.base.notes, |
|
| 144 | - | sweetness: data.scores.sweetness, |
|
| 145 | - | acidity: data.scores.acidity, |
|
| 146 | - | tannin: data.scores.tannin, |
|
| 147 | - | alcohol: data.scores.alcohol, |
|
| 148 | - | body: data.scores.body, |
|
| 149 | - | clarity: data.scores.clarity, |
|
| 150 | - | color_intensity: data.scores.color_intensity, |
|
| 151 | - | aroma_intensity: data.scores.aroma_intensity, |
|
| 152 | - | nose_complexity: data.scores.nose_complexity, |
|
| 153 | - | background: &data.base.background, |
|
| 154 | - | }; |
|
| 139 | + | let input = db::WineInput::from(&data); |
|
| 155 | 140 | match db::create_wine(&state.db, &input, false) { |
|
| 156 | 141 | Ok(wine) => { |
|
| 157 | 142 | if let (Some(image), Some(mime)) = (&data.base.image, &data.base.image_mime) { |
|
| 186 | 171 | } |
|
| 187 | 172 | }; |
|
| 188 | 173 | ||
| 189 | - | let input = db::WineInput { |
|
| 190 | - | name: &data.base.name, |
|
| 191 | - | origin: &data.base.origin, |
|
| 192 | - | grape: &data.base.grape, |
|
| 193 | - | notes: &data.base.notes, |
|
| 194 | - | sweetness: data.scores.sweetness, |
|
| 195 | - | acidity: data.scores.acidity, |
|
| 196 | - | tannin: data.scores.tannin, |
|
| 197 | - | alcohol: data.scores.alcohol, |
|
| 198 | - | body: data.scores.body, |
|
| 199 | - | clarity: data.scores.clarity, |
|
| 200 | - | color_intensity: data.scores.color_intensity, |
|
| 201 | - | aroma_intensity: data.scores.aroma_intensity, |
|
| 202 | - | nose_complexity: data.scores.nose_complexity, |
|
| 203 | - | background: &data.base.background, |
|
| 204 | - | }; |
|
| 174 | + | let input = db::WineInput::from(&data); |
|
| 205 | 175 | match db::update_wine(&state.db, &short_id, &input) { |
|
| 206 | 176 | Ok(Some(_)) => { |
|
| 207 | 177 | if let Some(image) = &data.base.image { |
|
| 439 | 439 | scores: WineScores, |
|
| 440 | 440 | } |
|
| 441 | 441 | ||
| 442 | + | impl<'a> From<&'a WineFormData> for crate::db::WineInput<'a> { |
|
| 443 | + | fn from(data: &'a WineFormData) -> Self { |
|
| 444 | + | Self { |
|
| 445 | + | name: &data.base.name, |
|
| 446 | + | origin: &data.base.origin, |
|
| 447 | + | grape: &data.base.grape, |
|
| 448 | + | notes: &data.base.notes, |
|
| 449 | + | sweetness: data.scores.sweetness, |
|
| 450 | + | acidity: data.scores.acidity, |
|
| 451 | + | tannin: data.scores.tannin, |
|
| 452 | + | alcohol: data.scores.alcohol, |
|
| 453 | + | body: data.scores.body, |
|
| 454 | + | clarity: data.scores.clarity, |
|
| 455 | + | color_intensity: data.scores.color_intensity, |
|
| 456 | + | aroma_intensity: data.scores.aroma_intensity, |
|
| 457 | + | nose_complexity: data.scores.nose_complexity, |
|
| 458 | + | background: &data.base.background, |
|
| 459 | + | } |
|
| 460 | + | } |
|
| 461 | + | } |
|
| 462 | + | ||
| 442 | 463 | async fn parse_wine_multipart(mut multipart: Multipart) -> Result<WineFormData, String> { |
|
| 443 | 464 | let mut base = WineBase::default(); |
|
| 444 | 465 | let mut scores = WineScores::default(); |