|
|
|
@ -12,6 +12,14 @@ type ItemDTO struct {
|
|
|
|
|
id int
|
|
|
|
|
message string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (item ItemDTO) GetId() int {
|
|
|
|
|
return item.id
|
|
|
|
|
}
|
|
|
|
|
func (item ItemDTO) GetMessage() string {
|
|
|
|
|
return item.message
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UserDTO struct {
|
|
|
|
|
id int
|
|
|
|
|
}
|
|
|
|
@ -70,8 +78,67 @@ func RegisterRoutes(router *gin.RouterGroup, prov types.IPersitenceProvider) {
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, ItemsToDTOs(items))
|
|
|
|
|
})
|
|
|
|
|
router.POST("/item", func(c *gin.Context) {})
|
|
|
|
|
router.PUT("/item", func(c *gin.Context) {})
|
|
|
|
|
router.DELETE("/item/:id", func(c *gin.Context) {})
|
|
|
|
|
router.GET("/link/:itemId/:userId", func(c *gin.Context) {})
|
|
|
|
|
router.POST("/item", func(c *gin.Context) {
|
|
|
|
|
var item struct {
|
|
|
|
|
message string
|
|
|
|
|
}
|
|
|
|
|
if err := c.BindJSON(&item); err != nil {
|
|
|
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
prov.CreateItem(ItemDTO{message: item.message})
|
|
|
|
|
c.Status(200)
|
|
|
|
|
})
|
|
|
|
|
router.PUT("/item", func(c *gin.Context) {
|
|
|
|
|
var item ItemDTO
|
|
|
|
|
if err := c.BindJSON(&item); err != nil {
|
|
|
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := prov.UpdateItem(item); err != nil {
|
|
|
|
|
c.String(http.StatusInternalServerError, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.Status(200)
|
|
|
|
|
})
|
|
|
|
|
router.DELETE("/item/:id", func(c *gin.Context) {
|
|
|
|
|
id, err := strconv.Atoi(c.Param("id"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(404, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := prov.DeleteItem(ItemDTO{id: id}); err != nil {
|
|
|
|
|
c.String(404, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.Status(200)
|
|
|
|
|
})
|
|
|
|
|
router.GET("/link/:itemId/:userId", func(c *gin.Context) {
|
|
|
|
|
itemId, err := strconv.Atoi(c.Param("itemId"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(404, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
userId, err := strconv.Atoi(c.Param("userId"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(404, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := prov.Link(UserDTO{id: userId}, ItemDTO{id: itemId}); err != nil {
|
|
|
|
|
c.String(404, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.Status(200)
|
|
|
|
|
})
|
|
|
|
|
router.POST("/user", func(c *gin.Context) {
|
|
|
|
|
var user struct {
|
|
|
|
|
id int
|
|
|
|
|
}
|
|
|
|
|
if err := c.BindJSON(&user); err != nil {
|
|
|
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
prov.CreateUser(UserDTO{user.id})
|
|
|
|
|
c.Status(200)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|