check duplicates before making claude request
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m31s

This commit is contained in:
2026-03-07 16:51:11 +00:00
parent 88ce32abeb
commit 0da6d3f0ed

View File

@@ -82,6 +82,13 @@ func (store *Store) CreateRowing(ctx *gin.Context) {
} }
encoded := base64.StdEncoding.EncodeToString(data) encoded := base64.StdEncoding.EncodeToString(data)
// Reject duplicates: same EXIF datetime already recorded
var existing models.Rowing
if err := store.DB.Where("date = ?", dateTaken).First(&existing).Error; err == nil {
ctx.JSON(http.StatusConflict, gin.H{"error": "duplicate entry for this date"})
return
}
// Build the message with an image + text prompt // Build the message with an image + text prompt
message, err := store.ClaudeClient.Messages.New(context.Background(), anthropic.MessageNewParams{ message, err := store.ClaudeClient.Messages.New(context.Background(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeHaiku4_5, Model: anthropic.ModelClaudeHaiku4_5,
@@ -176,13 +183,6 @@ No text, no markdown, no explanation. Just the JSON object.`),
return return
} }
// Reject duplicates: same EXIF datetime already recorded
var existing models.Rowing
if err := store.DB.Where("date = ?", dateTaken).First(&existing).Error; err == nil {
ctx.JSON(http.StatusConflict, gin.H{"error": "duplicate entry for this date"})
return
}
calories := float64(extractedData.Distance) / 7500.0 * 500.0 calories := float64(extractedData.Distance) / 7500.0 * 500.0
rowing := models.Rowing{ rowing := models.Rowing{