saveQuote, removeQuote (WIP)
This commit is contained in:
parent
8815cddebf
commit
680ec9c6ce
@ -16,9 +16,15 @@ export default {
|
||||
methods: {
|
||||
edit() {
|
||||
console.log('edit')
|
||||
this.save()
|
||||
},
|
||||
save() {
|
||||
console.log('save')
|
||||
this.$engine.saveQuote(this.quote.id, this.quote.quote)
|
||||
},
|
||||
remove() {
|
||||
console.log('remove')
|
||||
this.$engine.removeQuote(this.quote.id)
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -46,6 +52,7 @@ export default {
|
||||
line-height: 48px;
|
||||
font-size: 32px;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background-color: #6040c0;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<CollectQuotesExplain />
|
||||
<!-- <CollectQuotesExplain /> -->
|
||||
<CollectQuote v-for="quote in quotes" :key="quote.id" :quote="quote" />
|
||||
</div>
|
||||
</template>
|
||||
|
@ -12,6 +12,7 @@ import parseSyncData from './parseSyncData'
|
||||
import saveSelection from './saveSelection'
|
||||
import getMyQuotes from './getMyQuotes'
|
||||
import saveQuote from './saveQuote'
|
||||
import removeQuote from './removeQuote'
|
||||
|
||||
export default (context, inject) => {
|
||||
const engine = {
|
||||
@ -28,6 +29,7 @@ export default (context, inject) => {
|
||||
collectQuotes,
|
||||
getMyQuotes,
|
||||
saveQuote,
|
||||
removeQuote,
|
||||
startGame,
|
||||
resetGame,
|
||||
continueGame,
|
||||
|
8
client/src/plugins/engine/removeQuote.js
Normal file
8
client/src/plugins/engine/removeQuote.js
Normal file
@ -0,0 +1,8 @@
|
||||
export default async function(id, quote) {
|
||||
const { store } = this.context
|
||||
|
||||
await this.callApi('/api/removeQuote', {
|
||||
g: store.state.engine.user?.game,
|
||||
id,
|
||||
})
|
||||
}
|
31
server/src/application/removeQuote.go
Normal file
31
server/src/application/removeQuote.go
Normal file
@ -0,0 +1,31 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sirlab.de/go/knyt/user"
|
||||
)
|
||||
|
||||
func (app *Application) RemoveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
||||
gameRef := r.URL.Query().Get("g")
|
||||
gm, err := app.GetGameById(gameRef)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
fmt.Fprintf(w, "game not found")
|
||||
return
|
||||
}
|
||||
|
||||
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
|
||||
quoteId := r.URL.Query().Get("id")
|
||||
if err := gm.RemoveQuote(usr.GetId(), quoteId); err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
}
|
32
server/src/application/saveQuote.go
Normal file
32
server/src/application/saveQuote.go
Normal file
@ -0,0 +1,32 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sirlab.de/go/knyt/user"
|
||||
)
|
||||
|
||||
func (app *Application) SaveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
||||
gameRef := r.URL.Query().Get("g")
|
||||
gm, err := app.GetGameById(gameRef)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
fmt.Fprintf(w, "game not found")
|
||||
return
|
||||
}
|
||||
|
||||
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
|
||||
quoteId := r.URL.Query().Get("id")
|
||||
quoteText := r.URL.Query().Get("quote")
|
||||
if err := gm.SaveQuote(usr.GetId(), quoteId, quoteText); err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {
|
||||
|
||||
quote := gm.quotes[id]
|
||||
if quote == nil {
|
||||
return nil, fmt.Errorf("player id \"%s\" not found in game\n", id)
|
||||
return nil, fmt.Errorf("quote id \"%s\" not found in game\n", id)
|
||||
}
|
||||
|
||||
return quote, nil
|
||||
|
20
server/src/game/removeQuote.go
Normal file
20
server/src/game/removeQuote.go
Normal file
@ -0,0 +1,20 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (gm *Game) RemoveQuote(usrId string, quoteId string) error {
|
||||
quote, err := gm.getQuoteById(quoteId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if quote.GetSourceId() != usrId {
|
||||
return fmt.Errorf("usrId does not match quote source id")
|
||||
}
|
||||
|
||||
fmt.Printf("%v\n", quote)
|
||||
|
||||
return fmt.Errorf("Game::RemoveQuote() not yet implemented")
|
||||
}
|
20
server/src/game/saveQuote.go
Normal file
20
server/src/game/saveQuote.go
Normal file
@ -0,0 +1,20 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (gm *Game) SaveQuote(usrId string, quoteId string, quoteText string) error {
|
||||
quote, err := gm.getQuoteById(quoteId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if quote.GetSourceId() != usrId {
|
||||
return fmt.Errorf("usrId does not match quote source id")
|
||||
}
|
||||
|
||||
fmt.Printf("%v\n", quote)
|
||||
|
||||
return fmt.Errorf("Game::SaveQuote() not yet implemented")
|
||||
}
|
@ -30,6 +30,8 @@ func main() {
|
||||
mux.PrivateHandleFunc("/api/finishGame", app.FinishGame)
|
||||
mux.PrivateHandleFunc("/api/saveSelection", app.SaveSelection)
|
||||
mux.PrivateHandleFunc("/api/getQuotes", app.GetQuotes)
|
||||
mux.PrivateHandleFunc("/api/saveQuote", app.SaveQuote)
|
||||
mux.PrivateHandleFunc("/api/removeQuote", app.RemoveQuote)
|
||||
|
||||
// default handler
|
||||
fsHandler := http.FileServer(http.Dir("../../client/dist/"))
|
||||
|
Loading…
Reference in New Issue
Block a user