mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
implemented delete reusable content block
This commit is contained in:
parent
2493a09ba9
commit
fc9127e165
12 changed files with 130 additions and 16 deletions
|
@ -219,6 +219,7 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/space/{folderID}", []string{"GET", "OPTIONS"}, nil, GetBlocksForSpace))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"GET", "OPTIONS"}, nil, GetBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"PUT", "OPTIONS"}, nil, UpdateBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"DELETE", "OPTIONS"}, nil, DeleteBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks", []string{"POST", "OPTIONS"}, nil, AddBlock))
|
||||
|
||||
// Links
|
||||
|
|
|
@ -226,7 +226,19 @@ func AddBlock(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
b, err = p.GetBlock(b.RefID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "block", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// GetBlock returns requested reusable content block.
|
||||
|
@ -337,3 +349,43 @@ func UpdateBlock(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
writeSuccessEmptyJSON(w)
|
||||
}
|
||||
|
||||
// DeleteBlock removes requested reusable content block.
|
||||
func DeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
method := "DeleteBlock"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
blockID := params["blockID"]
|
||||
|
||||
if len(blockID) == 0 {
|
||||
writeMissingDataError(w, method, "blockID")
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
_, err = p.DeleteBlock(blockID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = p.RemoveBlockReference(blockID)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue