-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.go
40 lines (31 loc) · 824 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package document
import (
"fmt"
"log"
"path/filepath"
"github.com/gofiber/fiber/v2"
)
func (d *Controller) Delete(c *fiber.Ctx) error {
if c.FormValue("id") == "" {
return fiber.ErrBadRequest
}
document, err := d.idx.Document(c.FormValue("id"))
if err != nil {
fmt.Println(err)
return fiber.ErrBadRequest
}
fullPath := filepath.Join(d.config.LibraryPath, document.ID)
if _, err := d.appFs.Stat(fullPath); err != nil {
return fiber.ErrBadRequest
}
if err := d.idx.RemoveFile(fullPath); err != nil {
return fiber.ErrInternalServerError
}
if err := d.appFs.Remove(fullPath); err != nil {
log.Printf("error removing file %s", fullPath)
}
if err := d.hlRepository.RemoveDocument(document.ID); err != nil {
log.Printf("error removing file %s from highlights", document.ID)
}
return nil
}