This commit is contained in:
Liang Ding 2022-12-21 22:29:05 +08:00
parent b3b67832b0
commit 2abc5561b5
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
5 changed files with 32 additions and 17 deletions

View File

@ -67,7 +67,7 @@ func getRiffDueCards(c *gin.Context) {
ret.Data = cards ret.Data = cards
} }
func removeRiffCard(c *gin.Context) { func removeRiffCards(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)
@ -77,8 +77,12 @@ func removeRiffCard(c *gin.Context) {
} }
deckID := arg["deckID"].(string) deckID := arg["deckID"].(string)
blockID := arg["blockID"].(string) blockIDsArg := arg["blockIDs"].([]interface{})
err := model.RemoveFlashcard(blockID, deckID) var blockIDs []string
for _, blockID := range blockIDsArg {
blockIDs = append(blockIDs, blockID.(string))
}
err := model.RemoveFlashcards(deckID, blockIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -86,7 +90,7 @@ func removeRiffCard(c *gin.Context) {
} }
} }
func addRiffCard(c *gin.Context) { func addRiffCards(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)
@ -96,8 +100,12 @@ func addRiffCard(c *gin.Context) {
} }
deckID := arg["deckID"].(string) deckID := arg["deckID"].(string)
blockID := arg["blockID"].(string) blockIDsArg := arg["blockIDs"].([]interface{})
err := model.AddFlashcard(blockID, deckID) var blockIDs []string
for _, blockID := range blockIDsArg {
blockIDs = append(blockIDs, blockID.(string))
}
err := model.AddFlashcards(deckID, blockIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -115,12 +123,13 @@ func createRiffDeck(c *gin.Context) {
} }
name := arg["name"].(string) name := arg["name"].(string)
err := model.CreateDeck(name) deck, err := model.CreateDeck(name)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
return return
} }
ret.Data = deck
} }
func getRiffDecks(c *gin.Context) { func getRiffDecks(c *gin.Context) {

View File

@ -301,8 +301,8 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck) ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck)
ginServer.Handle("POST", "/api/riff/getRiffDecks", model.CheckAuth, getRiffDecks) ginServer.Handle("POST", "/api/riff/getRiffDecks", model.CheckAuth, getRiffDecks)
ginServer.Handle("POST", "/api/riff/addRiffCard", model.CheckAuth, addRiffCard) ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
ginServer.Handle("POST", "/api/riff/removeRiffCard", model.CheckAuth, removeRiffCard) ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards) ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards)
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard) ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)

View File

@ -45,7 +45,7 @@ require (
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8 github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b
github.com/steambap/captcha v1.4.1 github.com/steambap/captcha v1.4.1
github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012 github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012
github.com/vmihailenco/msgpack/v5 v5.3.5 github.com/vmihailenco/msgpack/v5 v5.3.5

View File

@ -387,6 +387,8 @@ github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccY
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM= github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c h1:DaPdLs6t6JHbedko5+w+gfNuqXgThHWkLHrKiiHrbpQ= github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c h1:DaPdLs6t6JHbedko5+w+gfNuqXgThHWkLHrKiiHrbpQ=
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc= github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b h1:cDjWs67Y+glYE45+HWuB2oIXWipjJaZh3mYJRpV/FNQ=
github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY= github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=

View File

@ -71,12 +71,14 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
return return
} }
func RemoveFlashcard(blockID string, deckID string) (err error) { func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
deckLock.Lock() deckLock.Lock()
deck := Decks[deckID] deck := Decks[deckID]
deckLock.Unlock() deckLock.Unlock()
deck.RemoveCard(blockID) for _, blockID := range blockIDs {
deck.RemoveCard(blockID)
}
err = deck.Save() err = deck.Save()
if nil != err { if nil != err {
logging.LogErrorf("save deck [%s] failed: %s", deckID, err) logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
@ -85,13 +87,15 @@ func RemoveFlashcard(blockID string, deckID string) (err error) {
return return
} }
func AddFlashcard(blockID string, deckID string) (err error) { func AddFlashcards(deckID string, blockIDs []string) (err error) {
deckLock.Lock() deckLock.Lock()
deck := Decks[deckID] deck := Decks[deckID]
deckLock.Unlock() deckLock.Unlock()
cardID := ast.NewNodeID() for _, blockID := range blockIDs {
deck.AddCard(cardID, blockID) cardID := ast.NewNodeID()
deck.AddCard(cardID, blockID)
}
err = deck.Save() err = deck.Save()
if nil != err { if nil != err {
logging.LogErrorf("save deck [%s] failed: %s", deckID, err) logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
@ -128,10 +132,10 @@ func InitFlashcards() {
} }
} }
func CreateDeck(name string) (err error) { func CreateDeck(name string) (deck *riff.Deck, err error) {
riffSavePath := getRiffDir() riffSavePath := getRiffDir()
deckID := ast.NewNodeID() deckID := ast.NewNodeID()
deck, err := riff.LoadDeck(riffSavePath, deckID) deck, err = riff.LoadDeck(riffSavePath, deckID)
if nil != err { if nil != err {
logging.LogErrorf("load deck [%s] failed: %s", deckID, err) logging.LogErrorf("load deck [%s] failed: %s", deckID, err)
return return