Cambridge-Community-Kitchen / cck-volunteer-web-app

https://volunteer.cckitchen.uk
3 stars 2 forks source link

Ingest Google sheets #1

Open jamdelion opened 2 years ago

ZephSibley commented 1 year ago

The way I usually handle this kind of problem is by applying the Strategy pattern; https://refactoring.guru/design-patterns/strategy

Essentially there would be a class looking something like:

class GoogleSheetIngester {
    constructor(strategy) {
         this._strategy = strategy;
    }
    ingest(sheet_link_or_something) {
        // Logic here around getting the sheet data and serialising it into a standard format like JSON
        return this._strategy.ingest(sheet_data)
    }
}

class DeliverySheet:
    ingest(sheet_data) {
        // Handle the specific logic for the delivery sheet, keeping the knowledge of what to expect from that sheet inside this class.
    }
}

result = GoogleSheetIngester(DeliverySheet).ingest(sheet_link_or_something)