= setup OK

= surfer OK
This commit is contained in:
Miki 2024-01-02 10:05:24 +00:00
parent 6b86375ce9
commit 2bb01aa45a
6 changed files with 72 additions and 23 deletions

View file

@ -15,7 +15,7 @@ type Athlete struct {
}
func surferName(athlete Athlete) string {
str := fmt.Sprintf("%s.%s", athlete.Name, athlete.Category)
str := fmt.Sprintf("%s-%s", athlete.Name, athlete.Category)
str = strings.ReplaceAll(str, " ", "_")
return str
}
@ -50,3 +50,26 @@ func (app *App) SaveSurfer(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "saved"})
}
func (app *App) DeleteSurfer(c *gin.Context) {
var athlete Athlete
err := c.ShouldBind(&athlete)
if err != nil {
log.Printf("req error: %+v", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
log.Printf("surfer: %+v", athlete)
err = app.DB.Delete("Surfers", surferName(athlete))
if err != nil {
log.Printf("set error: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{"status": fmt.Sprintf("Error: %+v", err)})
return
}
c.JSON(http.StatusOK, gin.H{"status": "deleted"})
}