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
|
package controllers
import (
"lain/services"
"lain/session"
"strconv"
"github.com/gofiber/fiber/v2"
)
func GetEmailAPI(context *fiber.Ctx) error {
emailID, err := strconv.ParseUint(context.Params("id"), 10, 32)
if err != nil {
return context.Status(400).JSON(fiber.Map{"error": "Invalid email ID"})
}
userEmail, err := session.GetSessionEmail(context)
if err != nil {
return context.Status(401).JSON(fiber.Map{"error": "Unauthorized"})
}
email, err := services.GetEmailDetails(userEmail, uint(emailID))
if err != nil {
return context.Status(404).JSON(fiber.Map{"error": "Email not found"})
}
return context.JSON(email)
}
func ToggleFlagAPI(context *fiber.Ctx) error {
emailID, err := strconv.ParseUint(context.Params("id"), 10, 32)
if err != nil {
return context.Status(400).JSON(fiber.Map{"error": "Invalid email ID"})
}
userEmail, err := session.GetSessionEmail(context)
if err != nil {
return context.Status(401).JSON(fiber.Map{"error": "Unauthorized"})
}
isFlagged, err := services.ToggleEmailFlag(userEmail, uint(emailID))
if err != nil {
return context.Status(500).JSON(fiber.Map{"error": "Failed to toggle flag"})
}
return context.JSON(fiber.Map{"flagged": isFlagged})
}
func MarkEmailAsReadAPI(context *fiber.Ctx) error {
emailID, err := strconv.ParseUint(context.Params("id"), 10, 32)
if err != nil {
return context.Status(400).JSON(fiber.Map{"error": "Invalid email ID"})
}
userEmail, err := session.GetSessionEmail(context)
if err != nil {
return context.Status(401).JSON(fiber.Map{"error": "Unauthorized"})
}
err = services.MarkEmailAsRead(userEmail, uint(emailID))
if err != nil {
return context.Status(500).JSON(fiber.Map{"error": "Failed to mark as read"})
}
return context.JSON(fiber.Map{"success": true})
}
|