remove quote
This commit is contained in:
parent
680ec9c6ce
commit
6f974195b2
@ -3,6 +3,8 @@ package application
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"sirlab.de/go/knyt/user"
|
"sirlab.de/go/knyt/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,10 +24,23 @@ 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 err := gm.RemoveQuote(usr.GetId(), quoteId); err != nil {
|
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())
|
||||||
|
quotesFileNameShort := quote.GetId() + ".json"
|
||||||
|
quotesFileName := path.Join(gameDirName, "quotes", quotesFileNameShort)
|
||||||
|
|
||||||
|
if err := os.Remove(quotesFileName); 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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,20 @@ package game
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sirlab.de/go/knyt/quote"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gm *Game) RemoveQuote(usrId string, quoteId string) error {
|
func (gm *Game) RemoveQuote(usrId string, quoteId string) (*quote.Quote, error) {
|
||||||
quote, err := gm.getQuoteById(quoteId)
|
quote, err := gm.getQuoteById(quoteId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if quote.GetSourceId() != usrId {
|
if quote.GetSourceId() != usrId {
|
||||||
return fmt.Errorf("usrId does not match quote source id")
|
return nil, fmt.Errorf("usrId does not match quote source id")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%v\n", quote)
|
fmt.Printf("%v\n", quote)
|
||||||
|
|
||||||
return fmt.Errorf("Game::RemoveQuote() not yet implemented")
|
return quote, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user