Skip to content

Commit

Permalink
chore: migrate to nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
chamanbravo committed Aug 2, 2024
1 parent ac6e359 commit 7afc8d2
Show file tree
Hide file tree
Showing 174 changed files with 7,037 additions and 8,479 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
send_interrupt = true
stop_on_error = true

[color]
Expand Down
37 changes: 19 additions & 18 deletions controllers/auth_controller.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package controllers

import (
"github.com/chamanbravo/upstat/dto"
"github.com/chamanbravo/upstat/queries"
"github.com/chamanbravo/upstat/serializers"
"github.com/chamanbravo/upstat/utils"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
)

var validate = validator.New()

// SignUp method to create a new user.
// @Description Create a new user.
// @Summary create a new user
// @Tags Auth
// @Accept json
// @Produce json
// @Param body body serializers.UserSignUp true "Body"
// @Success 200 {object} serializers.UserSignInOut
// @Success 400 {object} serializers.ErrorResponse
// @Param body body dto.UserSignUp true "Body"
// @Success 200 {object} dto.UserSignInOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/auth/signup [post]
func SignUp(c *fiber.Ctx) error {
user := new(serializers.UserSignUp)
user := new(dto.UserSignUp)
if err := c.BodyParser(user); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": err.Error(),
Expand Down Expand Up @@ -72,8 +69,10 @@ func SignUp(c *fiber.Ctx) error {
return c.Status(200).JSON(fiber.Map{
"message": "success",
"user": fiber.Map{
"username": user.Username,
"email": user.Email,
"username": user.Username,
"email": user.Email,
"refresh_token": tokens.RefreshToken,
"access_token": tokens.AccessToken,
},
})
}
Expand All @@ -84,12 +83,12 @@ func SignUp(c *fiber.Ctx) error {
// @Tags Auth
// @Accept json
// @Produce json
// @Param body body serializers.UserSignIn true "Body"
// @Success 200 {object} serializers.UserSignInOut
// @Success 400 {object} serializers.ErrorResponse
// @Param body body dto.UserSignIn true "Body"
// @Success 200 {object} dto.UserSignInOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/auth/signin [post]
func SignIn(c *fiber.Ctx) error {
user := new(serializers.UserSignIn)
user := new(dto.UserSignIn)
if err := c.BodyParser(user); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": "Invalid body",
Expand Down Expand Up @@ -132,8 +131,10 @@ func SignIn(c *fiber.Ctx) error {
c.Cookie(&refreshToken)

return c.JSON(fiber.Map{"message": "success", "user": fiber.Map{
"username": existingUser.Username,
"email": existingUser.Email,
"username": existingUser.Username,
"email": existingUser.Email,
"refresh_token": tokens.RefreshToken,
"access_token": tokens.AccessToken,
}})
}

Expand All @@ -144,8 +145,8 @@ func SignIn(c *fiber.Ctx) error {
// @Tags Auth
// @Accept json
// @Produce json
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/auth/signout [post]
func SignOut(c *fiber.Ctx) error {
c.ClearCookie("access_token")
Expand Down
76 changes: 38 additions & 38 deletions controllers/monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
"strconv"
"time"

"github.com/chamanbravo/upstat/dto"
"github.com/chamanbravo/upstat/queries"
"github.com/chamanbravo/upstat/serializers"
"github.com/chamanbravo/upstat/utils"
"github.com/gofiber/fiber/v2"
)

// @Tags Monitors
// @Accept json
// @Produce json
// @Param body body serializers.AddMonitorIn true "Body"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/create [post]
// @Param body body dto.AddMonitorIn true "Body"
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors [post]
func CreateMonitor(c *fiber.Ctx) error {
newMonitor := new(serializers.AddMonitorIn)
newMonitor := new(dto.AddMonitorIn)
if err := c.BodyParser(newMonitor); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": err.Error(),
Expand Down Expand Up @@ -63,9 +63,9 @@ func CreateMonitor(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.MonitorInfoOut
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/info/{id} [get]
// @Success 200 {object} dto.MonitorInfoOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id} [get]
func MonitorInfo(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand Down Expand Up @@ -98,10 +98,10 @@ func MonitorInfo(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Param body body serializers.AddMonitorIn true "Body"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/update/{id} [put]
// @Param body body dto.AddMonitorIn true "Body"
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id} [patch]
func UpdateMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand All @@ -110,7 +110,7 @@ func UpdateMonitor(c *fiber.Ctx) error {
})
}

monitor := new(serializers.AddMonitorIn)
monitor := new(dto.AddMonitorIn)
if err := c.BodyParser(monitor); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": err.Error(),
Expand Down Expand Up @@ -160,9 +160,9 @@ func UpdateMonitor(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/pause/{id} [put]
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id}/pause [patch]
func PauseMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand Down Expand Up @@ -195,9 +195,9 @@ func PauseMonitor(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/resume/{id} [put]
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id}/resume [patch]
func ResumeMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand Down Expand Up @@ -235,9 +235,9 @@ func ResumeMonitor(c *fiber.Ctx) error {

// @Accept json
// @Produce json
// @Success 200 {object} serializers.MonitorsListOut
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/monitors/list [get]
// @Success 200 {object} dto.MonitorsListOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors [get]
func MonitorsList(c *fiber.Ctx) error {
monitors, err := queries.RetrieveMonitors()
if err != nil {
Expand Down Expand Up @@ -266,8 +266,8 @@ func MonitorsList(c *fiber.Ctx) error {
}

return c.Status(200).JSON(fiber.Map{
"message": "success",
"monitors": monitorsList,
"message": "success",
"items": monitorsList,
})
}

Expand All @@ -276,8 +276,8 @@ func MonitorsList(c *fiber.Ctx) error {
// @Produce json
// @Param id path string true "Monitor ID"
// @Param startTime query time.Time true "Start Time" format(json)
// @Success 200 {object} serializers.HeartbeatsOut
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.HeartbeatsOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/heartbeat/{id} [get]
func RetrieveHeartbeat(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand All @@ -294,7 +294,7 @@ func RetrieveHeartbeat(c *fiber.Ctx) error {
})
}

query := new(serializers.RetrieveHeartbeatIn)
query := new(dto.RetrieveHeartbeatIn)
if err := c.QueryParser(query); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": err.Error(),
Expand All @@ -320,8 +320,8 @@ func RetrieveHeartbeat(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.MonitorSummaryOut
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.MonitorSummaryOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/summary/{id} [get]
func MonitorSummary(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand Down Expand Up @@ -373,8 +373,8 @@ func MonitorSummary(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/delete/{id} [delete]
func DeleteMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand Down Expand Up @@ -406,8 +406,8 @@ func DeleteMonitor(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.CertificateExpiryCountDown
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.CertificateExpiryCountDown
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/cert-exp-countdown/{id} [get]
func CertificateExpiryCountDown(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand Down Expand Up @@ -453,8 +453,8 @@ func CertificateExpiryCountDown(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.NotificationListOut
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.NotificationListOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id}/notifications [get]
func NotificationChannelListOfMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand Down Expand Up @@ -488,8 +488,8 @@ func NotificationChannelListOfMonitor(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Monitor ID"
// @Success 200 {object} serializers.ListStatusPagesOut
// @Success 400 {object} serializers.ErrorResponse
// @Success 200 {object} dto.ListStatusPagesOut
// @Success 400 {object} dto.ErrorResponse
// @Router /api/monitors/{id}/status-pages [get]
func StatusPagesListOfMonitor(c *fiber.Ctx) error {
idParam := c.Params("id")
Expand Down
40 changes: 20 additions & 20 deletions controllers/notifications_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"fmt"
"strconv"

"github.com/chamanbravo/upstat/dto"
"github.com/chamanbravo/upstat/queries"
"github.com/chamanbravo/upstat/serializers"
"github.com/chamanbravo/upstat/utils"
"github.com/gofiber/fiber/v2"
)

// @Tags Notifications
// @Accept json
// @Produce json
// @Param body body serializers.NotificationCreateIn true "Body"
// @Success 200 {object} serializers.SuccessResponse
// @Failure 400 {object} serializers.ErrorResponse
// @Router /api/notifications/create [post]
// @Param body body dto.NotificationCreateIn true "Body"
// @Success 200 {object} dto.SuccessResponse
// @Failure 400 {object} dto.ErrorResponse
// @Router /api/notifications [post]
func CreateNotification(c *fiber.Ctx) error {
notificationChannel := new(serializers.NotificationCreateIn)
notificationChannel := new(dto.NotificationCreateIn)
if err := c.BodyParser(notificationChannel); err != nil {
fmt.Print(notificationChannel)
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
Expand Down Expand Up @@ -46,9 +46,9 @@ func CreateNotification(c *fiber.Ctx) error {
// @Tags Notifications
// @Accept json
// @Produce json
// @Success 200 {object} serializers.NotificationListOut
// @Failure 400 {object} serializers.ErrorResponse
// @Router /api/notifications/list [get]
// @Success 200 {object} dto.NotificationListOut
// @Failure 400 {object} dto.ErrorResponse
// @Router /api/notifications [get]
func ListNotificationsChannel(c *fiber.Ctx) error {
notifications, err := queries.ListNotificationChannel()
if err != nil {
Expand All @@ -66,9 +66,9 @@ func ListNotificationsChannel(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Notification Channel ID"
// @Success 200 {object} serializers.SuccessResponse
// @Failure 400 {object} serializers.ErrorResponse
// @Router /api/notifications/delete/{id} [delete]
// @Success 200 {object} dto.SuccessResponse
// @Failure 400 {object} dto.ErrorResponse
// @Router /api/notifications/{id} [delete]
func DeleteNotificationChannel(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand Down Expand Up @@ -101,10 +101,10 @@ func DeleteNotificationChannel(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Notification Channel ID"
// @Param body body serializers.NotificationCreateIn true "Body"
// @Success 200 {object} serializers.SuccessResponse
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/notifications/update/{id} [put]
// @Param body body dto.NotificationCreateIn true "Body"
// @Success 200 {object} dto.SuccessResponse
// @Success 400 {object} dto.ErrorResponse
// @Router /api/notifications/{id} [patch]
func UpdateNotificationChannel(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand All @@ -113,7 +113,7 @@ func UpdateNotificationChannel(c *fiber.Ctx) error {
})
}

notificationChannel := new(serializers.NotificationCreateIn)
notificationChannel := new(dto.NotificationCreateIn)
if err := c.BodyParser(notificationChannel); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": err.Error(),
Expand Down Expand Up @@ -149,9 +149,9 @@ func UpdateNotificationChannel(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param id path string true "Notification Channel ID"
// @Success 200 {object} serializers.NotificationChannelInfo
// @Success 400 {object} serializers.ErrorResponse
// @Router /api/notifications/info/{id} [get]
// @Success 200 {object} dto.NotificationChannelInfo
// @Success 400 {object} dto.ErrorResponse
// @Router /api/notifications/{id} [get]
func NotificationChannelInfo(c *fiber.Ctx) error {
idParam := c.Params("id")
if idParam == "" {
Expand Down
Loading

0 comments on commit 7afc8d2

Please sign in to comment.