/
offering.go
113 lines (89 loc) · 3.4 KB
/
offering.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package private
import (
"net/http"
"github.com/Projeto-USPY/uspy-backend/db"
"github.com/Projeto-USPY/uspy-backend/entity/controllers"
"github.com/Projeto-USPY/uspy-backend/server/models/private"
"github.com/gin-gonic/gin"
)
// GetComment is a closure for the GET /private/subjects/offerings/comments endpoint
func GetComment(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
off.Subject = *sub
userID := ctx.MustGet("userID").(string)
private.GetComment(ctx, DB, userID, off)
}
}
// GetCommentRating is a closure for the GET /private/subjects/offerings/comments/rating endpoint
func GetCommentRating(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
rating := ctx.MustGet("CommentRating").(*controllers.CommentRating)
off.Subject = *sub
rating.Offering = *off
userID := ctx.MustGet("userID").(string)
private.GetCommentRating(ctx, DB, userID, rating)
}
}
// RateComment is a closure for the PUT /private/subjects/offerings/comments/rating endpoint
func RateComment(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
rating := ctx.MustGet("CommentRating").(*controllers.CommentRating)
off.Subject = *sub
rating.Offering = *off
userID := ctx.MustGet("userID").(string)
var body controllers.CommentRateBody
if err := ctx.ShouldBindJSON(&body); err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
return
}
private.RateComment(ctx, DB, userID, rating, &body)
}
}
// ReportComment is a closure for the PUT /private/subjects/offerings/comments/report endpoint
func ReportComment(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
report := ctx.MustGet("CommentRating").(*controllers.CommentRating)
off.Subject = *sub
report.Offering = *off
userID := ctx.MustGet("userID").(string)
var body controllers.CommentReportBody
if err := ctx.ShouldBindJSON(&body); err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
return
}
private.ReportComment(ctx, DB, userID, report, &body)
}
}
// PublishComment is a closure for the PUT /private/subjects/offerings/comments endpoint
func PublishComment(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
off.Subject = *sub
userID := ctx.MustGet("userID").(string)
var comment controllers.Comment
if err := ctx.ShouldBindJSON(&comment); err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
return
}
private.PublishComment(ctx, DB, userID, off, &comment)
}
}
// DeleteComment is a closure for the DELETE /private/subjects/offerings/comments endpoint
func DeleteComment(DB db.Database) func(*gin.Context) {
return func(ctx *gin.Context) {
sub := ctx.MustGet("Subject").(*controllers.Subject)
off := ctx.MustGet("Offering").(*controllers.Offering)
off.Subject = *sub
userID := ctx.MustGet("userID").(string)
private.DeleteComment(ctx, DB, userID, off)
}
}