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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package dns
import (
"fmt"
"strconv"
dnsService "dove/services/dns"
"dove/utils/meta"
"dove/utils/shortcuts"
"github.com/gofiber/fiber/v2"
)
func CreateRecord(context *fiber.Ctx) error {
body, parseError := meta.Body[dnsService.CreateRecordRequest](context)
if parseError != nil {
return shortcuts.BadRequestError(context, parseError)
}
serviceError := dnsService.CreateRecord(body)
if serviceError != nil {
return shortcuts.HandleError(context, serviceError)
}
return shortcuts.RedirectToPath(context, fmt.Sprintf("/domains/manage/%d", body.DomainID))
}
func UpdateRecord(context *fiber.Ctx) error {
recordID, parseError := strconv.ParseUint(meta.Request(context).Param("id"), 10, 64)
if parseError != nil {
return shortcuts.BadRequestError(context, parseError)
}
recordType := meta.Request(context).Param("type")
body, bodyError := meta.Body[dnsService.UpdateRecordRequest](context)
if bodyError != nil {
return shortcuts.BadRequestError(context, bodyError)
}
serviceError := dnsService.UpdateRecord(recordType, uint(recordID), body)
if serviceError != nil {
return shortcuts.HandleError(context, serviceError)
}
domainID := meta.Request(context).Query("domain_id")
return shortcuts.RedirectToPath(context, fmt.Sprintf("/domains/manage/%s", domainID))
}
func DeleteRecord(context *fiber.Ctx) error {
recordID, parseError := strconv.ParseUint(meta.Request(context).Param("id"), 10, 64)
if parseError != nil {
return shortcuts.BadRequestError(context, parseError)
}
recordType := meta.Request(context).Param("type")
serviceError := dnsService.DeleteRecord(recordType, uint(recordID))
if serviceError != nil {
return shortcuts.HandleError(context, serviceError)
}
domainID := meta.Request(context).Query("domain_id")
return shortcuts.RedirectToPath(context, fmt.Sprintf("/domains/manage/%s", domainID))
}
|