|
|
@ -1,9 +1,8 @@
|
|
|
|
package handlers
|
|
|
|
package note
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ajikamaludin/go-fiber-rest/app/models"
|
|
|
|
"github.com/ajikamaludin/go-fiber-rest/app/models"
|
|
|
|
|
|
|
|
noteRepository "github.com/ajikamaludin/go-fiber-rest/app/repository/note"
|
|
|
|
gormdb "github.com/ajikamaludin/go-fiber-rest/pkg/gorm.db"
|
|
|
|
gormdb "github.com/ajikamaludin/go-fiber-rest/pkg/gorm.db"
|
|
|
|
redisclient "github.com/ajikamaludin/go-fiber-rest/pkg/redis.client"
|
|
|
|
redisclient "github.com/ajikamaludin/go-fiber-rest/pkg/redis.client"
|
|
|
|
"github.com/ajikamaludin/go-fiber-rest/pkg/utils/constants"
|
|
|
|
"github.com/ajikamaludin/go-fiber-rest/pkg/utils/constants"
|
|
|
@ -14,9 +13,7 @@ import (
|
|
|
|
func GetAllNotes(c *fiber.Ctx) error {
|
|
|
|
func GetAllNotes(c *fiber.Ctx) error {
|
|
|
|
var notes []models.Note
|
|
|
|
var notes []models.Note
|
|
|
|
|
|
|
|
|
|
|
|
err := redisclient.Get("allnotes", ¬es)
|
|
|
|
err := noteRepository.GetAllNotes(¬es)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
db, err := gormdb.GetInstance()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": constants.STATUS_FAIL,
|
|
|
|
"status": constants.STATUS_FAIL,
|
|
|
@ -24,10 +21,6 @@ func GetAllNotes(c *fiber.Ctx) error {
|
|
|
|
"error": err.Error(),
|
|
|
|
"error": err.Error(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db.Find(¬es)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisclient.Set("allnotes", ¬es, 30*time.Second)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
|
|
"status": constants.STATUS_SUCCESS,
|
|
|
|
"status": constants.STATUS_SUCCESS,
|
|
|
@ -40,27 +33,15 @@ func GetNoteById(c *fiber.Ctx) error {
|
|
|
|
id := c.Params("id")
|
|
|
|
id := c.Params("id")
|
|
|
|
note := models.Note{}
|
|
|
|
note := models.Note{}
|
|
|
|
|
|
|
|
|
|
|
|
key := "note+" + id
|
|
|
|
err := noteRepository.GetNoteById(id, ¬e)
|
|
|
|
err := redisclient.Get(key, ¬e)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
db, err := gormdb.GetInstance()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.First(¬e, id).Error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": constants.STATUS_FAIL,
|
|
|
|
"status": constants.STATUS_FAIL,
|
|
|
|
"message": "note not found",
|
|
|
|
"message": "note not found",
|
|
|
|
|
|
|
|
"error": err.Error(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
redisclient.Set(key, ¬e, 30*time.Second)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
|
|
"status": constants.STATUS_OK,
|
|
|
|
"status": constants.STATUS_OK,
|
|
|
|
"message": "note found",
|
|
|
|
"message": "note found",
|