This commit is contained in:
Ian Gulliver
2024-06-23 16:32:39 -07:00
parent 222a912e9f
commit f921b050de

27
sync.go
View File

@@ -68,25 +68,12 @@ func main() {
fatal(l, "failed to get Parents table", "error", err) fatal(l, "failed to get Parents table", "error", err)
} }
remoteParentsRecords, err := parentsTable.ListRecords(context.Background(), nil) parents, err := parentsTable.ReplaceRecords(context.Background(), dir.GetParentRecords(), []string{"Email"})
if err != nil { if err != nil {
fatal(l, "failed to fetch Parents", "error", err) fatal(l, "failed to upsert Parents", "error", err)
} }
l.Info("tmp", "parents", remoteParentsRecords, "len", len(remoteParentsRecords)) l.Info("upserted parents", "parents", parents)
/*
localParentRecords := dir.GetParentRecords()
for _, record := range localParentRecords {
_, err = parentsTable.AddRecords(&AirtableRecords{
Records: []*AirtableRecord{record},
})
if err != nil {
fatal(l, "failed to add Parents", "error", err)
}
}
*/
} }
func loadDirectory(l *slog.Logger, path string) (*Directory, error) { func loadDirectory(l *slog.Logger, path string) (*Directory, error) {
@@ -246,12 +233,11 @@ func (d *Directory) AddStudent(email, name, class, grade string, parents []*Pare
return s return s
} }
/* func (d *Directory) GetParentRecords() []*airtable.Record {
func (d *Directory) GetParentRecords() []*AirtableRecord { records := []*airtable.Record{}
records := []*AirtableRecord{}
for _, parent := range d.Parents { for _, parent := range d.Parents {
records = append(records, &AirtableRecord{ records = append(records, &airtable.Record{
Fields: map[string]any{ Fields: map[string]any{
"Email": parent.Email, "Email": parent.Email,
"Name": parent.Name, "Name": parent.Name,
@@ -261,7 +247,6 @@ func (d *Directory) GetParentRecords() []*AirtableRecord {
return records return records
} }
*/
func (p Person) String() string { func (p Person) String() string {
return fmt.Sprintf( return fmt.Sprintf(