aboutsummaryrefslogtreecommitdiff
path: root/controllers/domain/domain.go
blob: ef450ac89afce7f6b7900c1c455e4b90e78f00cf (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package domain

import (
	"strconv"

	domainService "dove/services/domain"
	"dove/utils/meta"
	"dove/utils/shortcuts"

	"github.com/gofiber/fiber/v2"
)

func CreateDomain(context *fiber.Ctx) error {
	body, parseError := meta.Body[domainService.CreateDomainRequest](context)
	if parseError != nil {
		return shortcuts.BadRequestError(context, parseError)
	}

	serviceError := domainService.CreateDomain(body)
	if serviceError != nil {
		return shortcuts.HandleError(context, serviceError)
	}

	return shortcuts.Redirect(context, "domains.manage")
}

func DeleteDomain(context *fiber.Ctx) error {
	domainID, parseError := strconv.ParseUint(meta.Request(context).Param("id"), 10, 64)
	if parseError != nil {
		return shortcuts.BadRequestError(context, parseError)
	}

	serviceError := domainService.DeleteDomain(uint(domainID))
	if serviceError != nil {
		return shortcuts.HandleError(context, serviceError)
	}

	return shortcuts.Redirect(context, "domains.manage")
}

func CreateTLD(context *fiber.Ctx) error {
	body, parseError := meta.Body[domainService.CreateTLDRequest](context)
	if parseError != nil {
		return shortcuts.BadRequestError(context, parseError)
	}

	serviceError := domainService.CreateTLD(body)
	if serviceError != nil {
		return shortcuts.HandleError(context, serviceError)
	}

	return shortcuts.Redirect(context, "domains.tlds")
}

func UpdateTLD(context *fiber.Ctx) error {
	tldID, parseError := strconv.ParseUint(meta.Request(context).Param("id"), 10, 64)
	if parseError != nil {
		return shortcuts.BadRequestError(context, parseError)
	}

	body, bodyError := meta.Body[domainService.UpdateTLDRequest](context)
	if bodyError != nil {
		return shortcuts.BadRequestError(context, bodyError)
	}

	serviceError := domainService.UpdateTLD(uint(tldID), body)
	if serviceError != nil {
		return shortcuts.HandleError(context, serviceError)
	}

	return shortcuts.Redirect(context, "domains.tlds")
}

func DeleteTLD(context *fiber.Ctx) error {
	serviceError := domainService.DeleteTLD(meta.Request(context).Param("name"))
	if serviceError != nil {
		return shortcuts.HandleError(context, serviceError)
	}

	return shortcuts.Redirect(context, "domains.tlds")
}