update list of quotes after create/delete

This commit is contained in:
Settel 2021-10-16 21:35:31 +02:00
parent a6b6d1dfd6
commit d70f98bf48
3 changed files with 23 additions and 11 deletions

View File

@ -14,18 +14,19 @@
export default {
props: ['quote'],
methods: {
edit() {
console.log('edit')
this.save()
async edit() {
await this.save()
},
save() {
console.log('save')
// this.$engine.createQuote(this.quote.quote)
async save() {
this.$engine.createQuote(this.quote.quote)
// this.$engine.saveQuote(this.quote.id, this.quote.quote)
// this.$engine.removeQuote(this.quote.id)
await this.$engine.getMyQuotes()
},
remove() {
console.log('remove')
async remove() {
if (confirm('Eintrag wirklich löschen?')) {
this.$engine.removeQuote(this.quote.id)
await this.$engine.getMyQuotes()
}
},
},
}

View File

@ -3,15 +3,18 @@ package game
import (
"fmt"
"os"
"sirlab.de/go/knyt/quote"
)
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
if quote, err := gm.getQuoteById(quoteId); err != nil {
if qu, err := gm.getQuoteById(quoteId); err != nil {
return err
} else {
if quote.GetSourceId() != usrId {
if qu.GetSourceId() != usrId {
return fmt.Errorf("usrId does not match quote source id")
}
gm.removeQuoteFromList(qu)
}
err := os.Remove(fileName)
@ -21,3 +24,10 @@ func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
return nil
}
func (gm *Game) removeQuoteFromList(qu *quote.Quote) {
gm.mu.Lock()
defer gm.mu.Unlock()
delete(gm.quotes, qu.GetId())
}

View File

@ -7,6 +7,7 @@ import (
func (gm *Game) CreateQuote(fileName, usrId, quoteId, quoteText string) error {
qu := quote.NewQuote(quoteId, usrId, quoteText)
gm.AddQuote(qu)
return qu.Save(fileName)
}