Enha: remove marks

This commit is contained in:
Grail Finder
2025-07-05 10:16:17 +03:00
parent 413edae4b6
commit eef4b7941b
8 changed files with 51 additions and 20 deletions

View File

@ -221,17 +221,30 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) {
found := false
var newMarks []models.CardMark
for _, mark := range card.Marks {
if mark.Username == fi.State.Username && mark.Active {
if mark.Username == fi.State.Username {
found = true
} else {
newMarks = append(newMarks, mark)
}
}
if !found {
newMarks = append(newMarks, models.CardMark{
cm := models.CardMark{
Username: fi.State.Username,
Active: true,
})
CardID: card.ID,
}
newMarks = append(newMarks, cm)
if err := repo.CardMarksAdd(r.Context(), &cm); err != nil {
log.Error("failed to add mark", "error", err, "card", card)
abortWithError(w, "failed to add mark")
return
}
} else {
// TODO: if mark was found, it needs to be removed
if err := repo.CardMarksRemove(r.Context(), card.ID, fi.State.Username); err != nil {
log.Error("failed to remove mark", "error", err, "card", card)
abortWithError(w, "failed to remove mark")
return
}
}
fi.Room.Cards[i].Marks = newMarks
cardword = fi.Room.Cards[i]