/
team_feedback.go
54 lines (44 loc) · 1.33 KB
/
team_feedback.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
package v1
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
feedbackServices "github.com/iReflect/reflect-app/apps/feedback/services"
)
// TeamFeedbackController ...
type TeamFeedbackController struct {
FeedbackService feedbackServices.FeedbackService
}
// Routes for Feedback
func (ctrl TeamFeedbackController) Routes(r *gin.RouterGroup) {
r.GET("/", ctrl.List)
r.GET("/:id/", ctrl.Get)
}
// ToDo: handle errors like in retrospectives/sprints controllers
// Get feedback
func (ctrl TeamFeedbackController) Get(c *gin.Context) {
id := c.Param("id")
userID, _ := c.Get("userID")
feedbackResponse, err := ctrl.FeedbackService.TeamGet(id, userID.(uint))
if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"message": "Feedback not found", "error": err})
return
}
c.JSON(http.StatusOK, feedbackResponse)
}
// List Feedbacks
func (ctrl TeamFeedbackController) List(c *gin.Context) {
statuses := c.QueryArray("status")
userID, _ := c.Get("userID")
perPage, _ := c.GetQuery("perPage")
parsedPerPage, err := strconv.Atoi(perPage)
if err != nil {
parsedPerPage = -1
}
response, err := ctrl.FeedbackService.TeamList(userID.(uint), statuses, parsedPerPage)
if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"message": "Feedbacks not found", "error": err})
return
}
c.JSON(http.StatusOK, response)
}