UPDATE: Historian module
All checks were successful
Build and Release / release (push) Successful in 1m20s
All checks were successful
Build and Release / release (push) Successful in 1m20s
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"history-api/internal/dtos/response"
|
||||
"history-api/internal/models"
|
||||
"history-api/internal/services"
|
||||
"history-api/pkg/config"
|
||||
"history-api/pkg/validator"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -137,7 +138,6 @@ func (h *AuthController) Signup(c fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func (h *AuthController) getRefreshToken(c fiber.Ctx) string {
|
||||
auth := c.Get("Authorization")
|
||||
if auth != "" {
|
||||
@@ -326,9 +326,10 @@ func (h *AuthController) GoogleLogin(c fiber.Ctx) error {
|
||||
|
||||
state := uuid.New().String()
|
||||
|
||||
feUrl := config.GetConfigWithDefault("FRONTEND_URL", "http://localhost:3000")
|
||||
redirect := c.Query("redirect")
|
||||
if redirect == "" {
|
||||
redirect = "http://localhost:3000"
|
||||
redirect = feUrl
|
||||
}
|
||||
|
||||
data := models.OAuthState{
|
||||
@@ -443,10 +444,10 @@ func (h *AuthController) GoogleCallback(c fiber.Ctx) error {
|
||||
"https://localhost:3001": true,
|
||||
"http://localhost:5500": true,
|
||||
}
|
||||
|
||||
feUrl := config.GetConfigWithDefault("FRONTEND_URL", "http://localhost:3000")
|
||||
redirectURL := data.RedirectURL
|
||||
if !allowed[redirectURL] {
|
||||
redirectURL = "http://localhost:3000"
|
||||
redirectURL = feUrl
|
||||
}
|
||||
|
||||
return c.Redirect().To(redirectURL)
|
||||
|
||||
@@ -25,6 +25,7 @@ func NewMediaController(svc services.MediaService) *MediaController {
|
||||
// @Tags Media
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path string true "Media ID"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
@@ -52,9 +53,8 @@ func (m *MediaController) GetMediaByID(c fiber.Ctx) error {
|
||||
// @Tags Media
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "Page number"
|
||||
// @Param limit query int false "Items per page"
|
||||
// @Param keyword query string false "Search keyword"
|
||||
// @Security BearerAuth
|
||||
// @Param query query request.SearchMediaDto false "Search Query"
|
||||
// @Success 200 {object} response.PaginatedResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
@@ -220,9 +220,7 @@ func (m *MediaController) UploadServerSide(c fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param fileName query string true "File name"
|
||||
// @Param content_type query string true "Content type"
|
||||
// @Param size query int true "File size"
|
||||
// @Param query query request.PreSignedDto false "PreSigned"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
@@ -255,7 +253,7 @@ func (m *MediaController) GeneratePresignedURL(c fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param data body PreSignedCompleteDto true "Request body"
|
||||
// @Param data body request.PreSignedCompleteDto true "Request body"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
|
||||
@@ -14,12 +14,18 @@ import (
|
||||
type UserController struct {
|
||||
service services.UserService
|
||||
mediaService services.MediaService
|
||||
verificationService services.VerificationService
|
||||
}
|
||||
|
||||
func NewUserController(svc services.UserService, mediaSvc services.MediaService) *UserController {
|
||||
func NewUserController(
|
||||
svc services.UserService,
|
||||
mediaSvc services.MediaService,
|
||||
verificationSvc services.VerificationService,
|
||||
) *UserController {
|
||||
return &UserController{
|
||||
service: svc,
|
||||
mediaService: mediaSvc,
|
||||
verificationService: verificationSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +112,33 @@ func (h *UserController) GetMediaByUserID(c fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// GetApplicationUserID godoc
|
||||
// @Summary Get user's media by user ID
|
||||
// @Description Retrieve media list by specific user ID
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "User ID"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Router /users/{id}/application [get]
|
||||
func (h *UserController) GetVerificationByUserID(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
userId := c.Params("id")
|
||||
res, err := h.verificationService.GetVerificationByUserID(ctx, userId)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||
Status: true,
|
||||
Data: res,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateProfile godoc
|
||||
// @Summary Update user profile
|
||||
// @Description Update the profile details of the currently authenticated user
|
||||
|
||||
186
internal/controllers/verificationController.go
Normal file
186
internal/controllers/verificationController.go
Normal file
@@ -0,0 +1,186 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"history-api/internal/dtos/response"
|
||||
"history-api/internal/dtos/request"
|
||||
"history-api/internal/services"
|
||||
"history-api/pkg/validator"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type VerificationController struct {
|
||||
service services.VerificationService
|
||||
}
|
||||
|
||||
func NewVerificationController(svc services.VerificationService) *VerificationController {
|
||||
return &VerificationController{service: svc}
|
||||
}
|
||||
|
||||
// @Summary Get application by ID
|
||||
// @Description Get historian application detail
|
||||
// @Tags Historian Application
|
||||
// @Produce json
|
||||
// @Param id path string true "Verification ID"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /historian/application/{id} [get]
|
||||
func (m *VerificationController) GetVerificationByID(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
verificationId := c.Params("id")
|
||||
res, err := m.service.GetVerificationByID(ctx, verificationId)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||
Status: true,
|
||||
Data: res,
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Search historian applications
|
||||
// @Description Get list of historian applications with filters
|
||||
// @Tags Historian Application
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param query query request.SearchUserVerificationDto false "Search Query"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Router /historian/application [get]
|
||||
func (m *VerificationController) SearchVerification(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
dto := &request.SearchUserVerificationDto{}
|
||||
if err := validator.ValidateQueryDto(c, dto); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
res, err := m.service.SearchVerification(ctx, dto)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(res)
|
||||
}
|
||||
|
||||
// @Summary Delete application
|
||||
// @Description Delete historian application
|
||||
// @Tags Historian Application
|
||||
// @Produce json
|
||||
// @Param id path string true "Verification ID"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /historian/application/{id} [delete]
|
||||
func (m *VerificationController) DeleteVerification(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
claimsVal := c.Locals("user_claims")
|
||||
if claimsVal == nil {
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: "Unauthorized",
|
||||
})
|
||||
}
|
||||
|
||||
claims, ok := claimsVal.(*response.JWTClaims)
|
||||
if !ok {
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: "Invalid user claims",
|
||||
})
|
||||
}
|
||||
|
||||
verificationId := c.Params("id")
|
||||
err := m.service.DeleteVerification(ctx, claims, verificationId)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||
Status: true,
|
||||
Message: "Verification deleted successfully",
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Create historian application
|
||||
// @Description Submit application to become historian
|
||||
// @Tags Historian Application
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body request.CreateUserVerificationDto true "Application data"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /historian/application [post]
|
||||
func (m *VerificationController) CreateVerification(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
dto := &request.CreateUserVerificationDto{}
|
||||
if err := validator.ValidateBodyDto(c, dto); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
res, err := m.service.CreateVerification(ctx, c.Locals("uid").(string), dto)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(res)
|
||||
}
|
||||
|
||||
// @Summary Update application status
|
||||
// @Description Approve or reject historian application
|
||||
// @Tags Historian Application
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Verification ID"
|
||||
// @Param body body request.UpdateVerificationStatusDto true "Status update"
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 400 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /historian/application/{id}/status [put]
|
||||
func (m *VerificationController) UpdateVerificationStatus(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
dto := &request.UpdateVerificationStatusDto{}
|
||||
if err := validator.ValidateBodyDto(c, dto); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
verificationId := c.Params("id")
|
||||
res, err := m.service.UpdateStatusVerification(ctx, c.Locals("uid").(string), verificationId, dto)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(res)
|
||||
}
|
||||
Reference in New Issue
Block a user