CodeYourFuture / CodeYourFuture/trainee-tracker

Migrate sheets reading to use serde

Open
#39 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
0
Forks
0
Avg merge
20m
Merged PRs (30d)
2

Description

We have a bunch of structs which we fill from Google Sheets, one per row, e.g.

https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/prs.rs#L217-L224

We currently do this in an annoyingly manual and inflexible way.

For this particular struct, we populate it here:

https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/reviewer_staff_info.rs#L48-L79

We ignore the headings completely, so if someone changed the sheet, we would start reading incorrect values. Then we hard-code the field order and types of each cell.

In other places, we manually check headings, and just error if they're wrong: https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/register.rs#L105-L160

We also handle partial rows poorly.

I would love instead for us to just use `serde`. We could derive `Deserialize` for each struct we populate, and use a `serde` adaptor to read the sheet into a `Vec`.

There is an existing [`serde_sheets` crate](https://crates.io/crates/serde_sheets) for doing this, but it has some issues. If it runs into issues with a row, it just prints an error to stdout and continues (https://docs.rs/serde_sheets/latest/src/serde_sheets/lib.rs.html#200).

Ideally we would either improve this crate, or write our own one. I'm imagining supporting a function along the lines of:

```rust
pub async fn read_all(
sheets: &mut Sheets,
document_id: &str,
tab_name: &str,
) -> SheetReadResult;

enum SheetReadResult {
AllOk(Vec),
SomeOk {
ok: Vec,
partial_records: Vec,
deserialization_error_records: Vec<(Record, serde::Error)>,
},
Err(SheetsError),
}

struct Record {
row_number: usize,
cells: Vec,
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.