-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathme_notes.go
More file actions
65 lines (51 loc) · 1.24 KB
/
me_notes.go
File metadata and controls
65 lines (51 loc) · 1.24 KB
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
package main
import "github.com/gin-gonic/gin"
func noteUser(c *gin.Context) {
username := Username(c.Param("username"))
if username == "" {
c.JSON(400, gin.H{"error": "Username is required"})
return
}
authKey := c.Query("auth")
if authKey == "" {
c.JSON(400, gin.H{"error": "Authentication key is required"})
return
}
noteContent := c.Query("note")
if noteContent == "" {
c.JSON(400, gin.H{"error": "Note content is required"})
return
}
user := authenticateWithKey(authKey)
if user == nil {
c.JSON(403, gin.H{"error": "Invalid authentication key"})
return
}
err := user.SetNote(username, noteContent)
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
go saveUsers()
c.JSON(200, gin.H{"success": true})
}
func deleteNote(c *gin.Context) {
username := Username(c.Param("username"))
if username == "" {
c.JSON(400, gin.H{"error": "Username is required"})
return
}
authKey := c.Query("auth")
if authKey == "" {
c.JSON(400, gin.H{"error": "Authentication key is required"})
return
}
user := authenticateWithKey(authKey)
if user == nil {
c.JSON(403, gin.H{"error": "Invalid authentication key"})
return
}
user.RemoveNote(username)
go saveUsers()
c.JSON(200, gin.H{"success": true})
}