# HG changeset patch # User Sascha L. Teichmann # Date 1542907007 -3600 # Node ID 1c0c9190fcf238ea709ca94edff2f34796660a41 # Parent 99c039e86624bd07cc302445bb0ae072a1b6c128 Import sounding result: If uploading a zip with a meta.json which has a dataset for bottleneck which already has a scan for a given date issue a message. diff -r 99c039e86624 -r 1c0c9190fcf2 pkg/controllers/srimports.go --- a/pkg/controllers/srimports.go Thu Nov 22 17:00:26 2018 +0100 +++ b/pkg/controllers/srimports.go Thu Nov 22 18:16:47 2018 +0100 @@ -276,7 +276,7 @@ result := struct { Message string `json:"message"` }{ - Message: fmt.Sprintf("Token %s deletes.", token), + Message: fmt.Sprintf("Token %s deleted.", token), } SendJSON(rw, http.StatusOK, &result) } diff -r 99c039e86624 -r 1c0c9190fcf2 pkg/models/sr.go --- a/pkg/models/sr.go Thu Nov 22 17:00:26 2018 +0100 +++ b/pkg/models/sr.go Thu Nov 22 18:16:47 2018 +0100 @@ -46,6 +46,11 @@ checkBottleneckSQL = ` SELECT true FROM waterway.bottlenecks WHERE objnam = $1` + + checkBottleneckDateUniqueSQL = ` +SELECT true FROM waterway.sounding_results sr JOIN + waterway.bottlenecks bn ON sr.bottleneck_id = bn.bottleneck_id +WHERE bn.objnam = $1 AND sr.date_info = $2` ) func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error { @@ -85,7 +90,7 @@ errs = append(errs, errors.New("Unexpected depth reference")) } - err = conn.QueryRowContext(context.Background(), + err = conn.QueryRowContext(ctx, checkBottleneckSQL, m.Bottleneck).Scan(&b) switch { @@ -97,5 +102,17 @@ errs = append(errs, errors.New("Unexpected bottleneck")) } + err = conn.QueryRowContext(ctx, + checkBottleneckDateUniqueSQL, + m.Bottleneck, m.Date.Time).Scan(&b) + switch { + case err == sql.ErrNoRows: // good! -> unique. + case err != nil: + errs = append(errs, err) + case b: + errs = append(errs, + errors.New("Sounding result for this date already exists.")) + } + return errs }