save and remove quote
This commit is contained in:
parent
df5f3f8250
commit
1df31a6e35
@ -3,7 +3,6 @@ package application
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"sirlab.de/go/knyt/user"
|
"sirlab.de/go/knyt/user"
|
||||||
)
|
)
|
||||||
@ -24,23 +23,15 @@ func (app *Application) RemoveQuote(usr *user.User, w http.ResponseWriter, r *ht
|
|||||||
}
|
}
|
||||||
|
|
||||||
quoteId := r.URL.Query().Get("id")
|
quoteId := r.URL.Query().Get("id")
|
||||||
if quote, err := gm.RemoveQuote(usr.GetId(), quoteId); err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
w.WriteHeader(http.StatusForbidden)
|
|
||||||
fmt.Fprintf(w, "forbidden")
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
gameDirName := path.Join(app.config.DataDir, "games", gm.GetId())
|
gameDirName := path.Join(app.config.DataDir, "games", gm.GetId())
|
||||||
quoteFileNameShort := quote.GetId() + ".json"
|
quoteFileNameShort := quoteId + ".json"
|
||||||
quoteFileName := path.Join(gameDirName, "quotes", quoteFileNameShort)
|
quoteFileName := path.Join(gameDirName, "quotes", quoteFileNameShort)
|
||||||
|
|
||||||
if err := os.Remove(quoteFileName); err != nil {
|
if err := gm.RemoveQuote(quoteFileName, usr.GetId(), quoteId); err != nil {
|
||||||
fmt.Printf("%s\n", err)
|
fmt.Printf("%s\n", err)
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
fmt.Fprintf(w, "forbidden")
|
fmt.Fprintf(w, "forbidden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "ok")
|
fmt.Fprintf(w, "ok")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,22 @@ package game
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sirlab.de/go/knyt/quote"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gm *Game) RemoveQuote(usrId string, quoteId string) (*quote.Quote, error) {
|
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
|
||||||
quote, err := gm.getQuoteById(quoteId)
|
if quote, err := gm.getQuoteById(quoteId); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return nil, err
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if quote.GetSourceId() != usrId {
|
if quote.GetSourceId() != usrId {
|
||||||
return nil, fmt.Errorf("usrId does not match quote source id")
|
return fmt.Errorf("usrId does not match quote source id")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%v\n", quote)
|
err := os.Remove(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return quote, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user