diff options
author | Matthew Lemon <y@yulqen.org> | 2024-03-12 11:30:05 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-03-12 11:30:05 +0000 |
commit | 9b2f5ce230900f799f54d872ffaf43790be55f14 (patch) | |
tree | 3eab3f05079c0e679637ad44dd91f8f7319794f3 | |
parent | 6c40bee051883d1801143376147f5dac4bde6cad (diff) |
wip: full datamap struct is now converted to json
-rw-r--r-- | cmd/api/datamaps.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/cmd/api/datamaps.go b/cmd/api/datamaps.go index cc12a45..3cec38e 100644 --- a/cmd/api/datamaps.go +++ b/cmd/api/datamaps.go @@ -5,12 +5,20 @@ import ( "fmt" "net/http" "strconv" + "time" ) type datamapLine struct { - Key string - Sheet string - Cellref string + Key string `json:"key"` + Sheet string `json:"sheet"` + Cellref string `json:"cellref"` +} + +type datamap struct { + Name string `json:"name"` + Description string `json:"description"` + Created time.Time `json:"created"` + DMLs []datamapLine `json:"datamap_lines"` } func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Request) { @@ -31,7 +39,8 @@ func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Requ // parse the csv reader := csv.NewReader(file) - var datamapLines []datamapLine + var dmls []datamapLine + var dm datamap for { line, err := reader.Read() @@ -47,14 +56,15 @@ func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Requ return } - datamapLines = append(datamapLines, datamapLine{ + dmls = append(dmls, datamapLine{ Key: line[0], Sheet: line[1], Cellref: line[2], }) } + dm = datamap{Name: "test-datamap", Description: "test description", Created: time.Now(), DMLs: dmls} - err = app.writeJSON(w, http.StatusOK, datamapLines, nil) + err = app.writeJSON(w, http.StatusOK, dm, nil) if err != nil { app.logger.Debug("writing out csv", "err", err) http.Error(w, "Cannot write output from parsed CSV", http.StatusInternalServerError) |