feat: update fixing clientId on some module
This commit is contained in:
parent
58bb26f7b9
commit
63f229da27
|
|
@ -3,10 +3,9 @@ package clients
|
|||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/fx"
|
||||
"web-medols-be/app/module/c
|
||||
"web-medols-be/app/module/clients/controller"
|
||||
"web-medols-be/app/module/clients/repository"
|
||||
"go.uber.org/fx"
|
||||
"web-medols-be/app/module/clients/service"
|
||||
)
|
||||
|
||||
// struct of ClientsRouter
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"strconv"
|
||||
"web-medols-be/app/middleware"
|
||||
"web-medols-be/app/module/custom_static_pages/request"
|
||||
"web-medols-be/app/module/custom_static_pages/service"
|
||||
"web-medols-be/utils/paginator"
|
||||
|
|
@ -60,7 +61,10 @@ func (_i *customStaticPagesController) All(c *fiber.Ctx) error {
|
|||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
customStaticPagesData, paging, err := _i.customStaticPagesService.All(req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
customStaticPagesData, paging, err := _i.customStaticPagesService.All(clientId, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -90,7 +94,10 @@ func (_i *customStaticPagesController) Show(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
customStaticPagesData, err := _i.customStaticPagesService.Show(uint(id))
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
customStaticPagesData, err := _i.customStaticPagesService.Show(clientId, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -116,7 +123,10 @@ func (_i *customStaticPagesController) Show(c *fiber.Ctx) error {
|
|||
func (_i *customStaticPagesController) ShowBySlug(c *fiber.Ctx) error {
|
||||
slug := c.Params("slug")
|
||||
|
||||
customStaticPagesData, err := _i.customStaticPagesService.ShowBySlug(slug)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
customStaticPagesData, err := _i.customStaticPagesService.ShowBySlug(clientId, slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -146,8 +156,11 @@ func (_i *customStaticPagesController) Save(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.customStaticPagesService.Save(*req, authToken)
|
||||
dataResult, err := _i.customStaticPagesService.Save(clientId, *req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -183,7 +196,10 @@ func (_i *customStaticPagesController) Update(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = _i.customStaticPagesService.Update(uint(id), *req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.customStaticPagesService.Update(clientId, uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -212,7 +228,10 @@ func (_i *customStaticPagesController) Delete(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = _i.customStaticPagesService.Delete(uint(id))
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.customStaticPagesService.Delete(clientId, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package repository
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"strings"
|
||||
"web-medols-be/app/database"
|
||||
|
|
@ -18,12 +19,12 @@ type customStaticPagesRepository struct {
|
|||
|
||||
// CustomStaticPagesRepository define interface of ICustomStaticPagesRepository
|
||||
type CustomStaticPagesRepository interface {
|
||||
GetAll(req request.CustomStaticPagesQueryRequest) (customStaticPagess []*entity.CustomStaticPages, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
FindOneBySlug(slug string) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
Create(customStaticPages *entity.CustomStaticPages) (customStaticPagesReturn *entity.CustomStaticPages, err error)
|
||||
Update(id uint, customStaticPages *entity.CustomStaticPages) (err error)
|
||||
Delete(id uint) (err error)
|
||||
GetAll(clientId *uuid.UUID, req request.CustomStaticPagesQueryRequest) (customStaticPagess []*entity.CustomStaticPages, paging paginator.Pagination, err error)
|
||||
FindOne(clientId *uuid.UUID, id uint) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
FindOneBySlug(clientId *uuid.UUID, slug string) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
Create(clientId *uuid.UUID, customStaticPages *entity.CustomStaticPages) (customStaticPagesReturn *entity.CustomStaticPages, err error)
|
||||
Update(clientId *uuid.UUID, id uint, customStaticPages *entity.CustomStaticPages) (err error)
|
||||
Delete(clientId *uuid.UUID, id uint) (err error)
|
||||
}
|
||||
|
||||
func NewCustomStaticPagesRepository(db *database.Database, logger zerolog.Logger) CustomStaticPagesRepository {
|
||||
|
|
@ -34,11 +35,12 @@ func NewCustomStaticPagesRepository(db *database.Database, logger zerolog.Logger
|
|||
}
|
||||
|
||||
// implement interface of ICustomStaticPagesRepository
|
||||
func (_i *customStaticPagesRepository) GetAll(req request.CustomStaticPagesQueryRequest) (customStaticPagess []*entity.CustomStaticPages, paging paginator.Pagination, err error) {
|
||||
func (_i *customStaticPagesRepository) GetAll(clientId *uuid.UUID, req request.CustomStaticPagesQueryRequest) (customStaticPagess []*entity.CustomStaticPages, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.CustomStaticPages{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
|
|
@ -75,37 +77,38 @@ func (_i *customStaticPagesRepository) GetAll(req request.CustomStaticPagesQuery
|
|||
return
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) FindOne(id uint) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
if err := _i.DB.DB.First(&customStaticPages, id).Error; err != nil {
|
||||
func (_i *customStaticPagesRepository) FindOne(clientId *uuid.UUID, id uint) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
if err := _i.DB.DB.Where("client_id = ?", clientId).First(&customStaticPages, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return customStaticPages, nil
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) FindOneBySlug(slug string) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
if err := _i.DB.DB.Where("slug = ?", slug).First(&customStaticPages).Error; err != nil {
|
||||
func (_i *customStaticPagesRepository) FindOneBySlug(clientId *uuid.UUID, slug string) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
if err := _i.DB.DB.Where("client_id = ? AND slug = ?", clientId, slug).First(&customStaticPages).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return customStaticPages, nil
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) Create(customStaticPages *entity.CustomStaticPages) (customStaticPagesReturn *entity.CustomStaticPages, err error) {
|
||||
func (_i *customStaticPagesRepository) Create(clientId *uuid.UUID, customStaticPages *entity.CustomStaticPages) (customStaticPagesReturn *entity.CustomStaticPages, err error) {
|
||||
customStaticPages.ClientId = clientId
|
||||
result := _i.DB.DB.Create(customStaticPages)
|
||||
return customStaticPages, result.Error
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) Update(id uint, customStaticPages *entity.CustomStaticPages) (err error) {
|
||||
func (_i *customStaticPagesRepository) Update(clientId *uuid.UUID, id uint, customStaticPages *entity.CustomStaticPages) (err error) {
|
||||
customStaticPagesMap, err := utilSvc.StructToMap(customStaticPages)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.CustomStaticPages{}).
|
||||
Where(&entity.CustomStaticPages{ID: id}).
|
||||
Where(&entity.CustomStaticPages{ID: id, ClientId: clientId}).
|
||||
Updates(customStaticPagesMap).Error
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.CustomStaticPages{}, id).Error
|
||||
func (_i *customStaticPagesRepository) Delete(clientId *uuid.UUID, id uint) error {
|
||||
return _i.DB.DB.Where("client_id = ?", clientId).Delete(&entity.CustomStaticPages{}, id).Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"web-medols-be/app/database/entity"
|
||||
"web-medols-be/app/module/custom_static_pages/mapper"
|
||||
|
|
@ -20,12 +21,12 @@ type customStaticPagesService struct {
|
|||
|
||||
// CustomStaticPagesService define interface of ICustomStaticPagesService
|
||||
type CustomStaticPagesService interface {
|
||||
All(req request.CustomStaticPagesQueryRequest) (customStaticPages []*response.CustomStaticPagesResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (customStaticPages *response.CustomStaticPagesResponse, err error)
|
||||
ShowBySlug(slug string) (customStaticPages *response.CustomStaticPagesResponse, err error)
|
||||
Save(req request.CustomStaticPagesCreateRequest, authToken string) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
Update(id uint, req request.CustomStaticPagesUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
All(clientId *uuid.UUID, req request.CustomStaticPagesQueryRequest) (customStaticPages []*response.CustomStaticPagesResponse, paging paginator.Pagination, err error)
|
||||
Show(clientId *uuid.UUID, id uint) (customStaticPages *response.CustomStaticPagesResponse, err error)
|
||||
ShowBySlug(clientId *uuid.UUID, slug string) (customStaticPages *response.CustomStaticPagesResponse, err error)
|
||||
Save(clientId *uuid.UUID, req request.CustomStaticPagesCreateRequest, authToken string) (customStaticPages *entity.CustomStaticPages, err error)
|
||||
Update(clientId *uuid.UUID, id uint, req request.CustomStaticPagesUpdateRequest) (err error)
|
||||
Delete(clientId *uuid.UUID, id uint) error
|
||||
}
|
||||
|
||||
// NewCustomStaticPagesService init CustomStaticPagesService
|
||||
|
|
@ -39,8 +40,8 @@ func NewCustomStaticPagesService(repo repository.CustomStaticPagesRepository, lo
|
|||
}
|
||||
|
||||
// All implement interface of CustomStaticPagesService
|
||||
func (_i *customStaticPagesService) All(req request.CustomStaticPagesQueryRequest) (customStaticPagess []*response.CustomStaticPagesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
func (_i *customStaticPagesService) All(clientId *uuid.UUID, req request.CustomStaticPagesQueryRequest) (customStaticPagess []*response.CustomStaticPagesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(clientId, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -52,8 +53,8 @@ func (_i *customStaticPagesService) All(req request.CustomStaticPagesQueryReques
|
|||
return
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesService) Show(id uint) (customStaticPages *response.CustomStaticPagesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *customStaticPagesService) Show(clientId *uuid.UUID, id uint) (customStaticPages *response.CustomStaticPagesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(clientId, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -61,8 +62,8 @@ func (_i *customStaticPagesService) Show(id uint) (customStaticPages *response.C
|
|||
return mapper.CustomStaticPagesResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesService) ShowBySlug(slug string) (customStaticPages *response.CustomStaticPagesResponse, err error) {
|
||||
result, err := _i.Repo.FindOneBySlug(slug)
|
||||
func (_i *customStaticPagesService) ShowBySlug(clientId *uuid.UUID, slug string) (customStaticPages *response.CustomStaticPagesResponse, err error) {
|
||||
result, err := _i.Repo.FindOneBySlug(clientId, slug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -70,7 +71,7 @@ func (_i *customStaticPagesService) ShowBySlug(slug string) (customStaticPages *
|
|||
return mapper.CustomStaticPagesResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesService) Save(req request.CustomStaticPagesCreateRequest, authToken string) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
func (_i *customStaticPagesService) Save(clientId *uuid.UUID, req request.CustomStaticPagesCreateRequest, authToken string) (customStaticPages *entity.CustomStaticPages, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
|
@ -78,20 +79,20 @@ func (_i *customStaticPagesService) Save(req request.CustomStaticPagesCreateRequ
|
|||
//createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
//newReq.CreatedById = &createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
return _i.Repo.Create(clientId, newReq)
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesService) Update(id uint, req request.CustomStaticPagesUpdateRequest) (err error) {
|
||||
func (_i *customStaticPagesService) Update(clientId *uuid.UUID, id uint, req request.CustomStaticPagesUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
return _i.Repo.Update(clientId, id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *customStaticPagesService) Delete(clientId *uuid.UUID, id uint) error {
|
||||
result, err := _i.Repo.FindOne(clientId, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.IsActive = false
|
||||
return _i.Repo.Update(id, result)
|
||||
return _i.Repo.Update(clientId, id, result)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"strconv"
|
||||
"web-medols-be/app/middleware"
|
||||
"web-medols-be/app/module/feedbacks/request"
|
||||
"web-medols-be/app/module/feedbacks/service"
|
||||
"web-medols-be/utils/paginator"
|
||||
|
|
@ -59,8 +60,8 @@ func (_i *feedbacksController) All(c *fiber.Ctx) error {
|
|||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
feedbacksData, paging, err := _i.feedbacksService.All(clientId, req)
|
||||
if err != nil {
|
||||
|
|
@ -92,8 +93,8 @@ func (_i *feedbacksController) Show(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
feedbacksData, err := _i.feedbacksService.Show(clientId, uint(id))
|
||||
if err != nil {
|
||||
|
|
@ -128,8 +129,8 @@ func (_i *feedbacksController) Save(c *fiber.Ctx) error {
|
|||
|
||||
authToken := c.Get("Authorization")
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
dataResult, err := _i.feedbacksService.Save(clientId, *req, authToken)
|
||||
if err != nil {
|
||||
|
|
@ -167,8 +168,8 @@ func (_i *feedbacksController) Update(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.feedbacksService.Update(clientId, uint(id), *req)
|
||||
if err != nil {
|
||||
|
|
@ -199,8 +200,8 @@ func (_i *feedbacksController) Delete(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.feedbacksService.Delete(clientId, uint(id))
|
||||
if err != nil {
|
||||
|
|
@ -233,8 +234,8 @@ func (_i *feedbacksController) FeedbackMonthlyStats(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
response, err := _i.feedbacksService.FeedbackMonthlyStats(clientId, authToken, &yearInt)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package controller
|
|||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"strconv"
|
||||
"web-medols-be/app/middleware"
|
||||
"web-medols-be/app/module/magazines/request"
|
||||
"web-medols-be/app/module/magazines/service"
|
||||
"web-medols-be/utils/paginator"
|
||||
|
|
@ -59,8 +60,8 @@ func (_i *magazinesController) All(c *fiber.Ctx) error {
|
|||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
magazinesData, paging, err := _i.magazinesService.All(clientId, req)
|
||||
if err != nil {
|
||||
|
|
@ -91,8 +92,8 @@ func (_i *magazinesController) Show(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
magazinesData, err := _i.magazinesService.Show(clientId, uint(id))
|
||||
if err != nil {
|
||||
|
|
@ -126,8 +127,8 @@ func (_i *magazinesController) Save(c *fiber.Ctx) error {
|
|||
|
||||
authToken := c.Get("Authorization")
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
dataResult, err := _i.magazinesService.Save(clientId, *req, authToken)
|
||||
if err != nil {
|
||||
|
|
@ -165,8 +166,8 @@ func (_i *magazinesController) Update(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.magazinesService.Update(clientId, uint(id), *req)
|
||||
if err != nil {
|
||||
|
|
@ -193,8 +194,8 @@ func (_i *magazinesController) Update(c *fiber.Ctx) error {
|
|||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /magazines/thumbnail/{id} [post]
|
||||
func (_i *magazinesController) SaveThumbnail(c *fiber.Ctx) error {
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err := _i.magazinesService.SaveThumbnail(clientId, c)
|
||||
if err != nil {
|
||||
|
|
@ -219,8 +220,8 @@ func (_i *magazinesController) SaveThumbnail(c *fiber.Ctx) error {
|
|||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /magazines/thumbnail/viewer/{thumbnailName} [get]
|
||||
func (_i *magazinesController) Viewer(c *fiber.Ctx) error {
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
return _i.magazinesService.Viewer(clientId, c)
|
||||
}
|
||||
|
|
@ -243,8 +244,8 @@ func (_i *magazinesController) Delete(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Extract ClientId from context
|
||||
clientId := c.Locals("clientId")
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.magazinesService.Delete(clientId, uint(id))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"strconv"
|
||||
"web-medols-be/app/middleware"
|
||||
"web-medols-be/app/module/subscription/request"
|
||||
"web-medols-be/app/module/subscription/service"
|
||||
"web-medols-be/utils/paginator"
|
||||
|
|
@ -55,7 +56,10 @@ func (_i *subscriptionController) All(c *fiber.Ctx) error {
|
|||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
subscriptionData, paging, err := _i.subscriptionService.All(req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
subscriptionData, paging, err := _i.subscriptionService.All(clientId, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -85,7 +89,10 @@ func (_i *subscriptionController) Show(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
subscriptionData, err := _i.subscriptionService.Show(uint(id))
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
subscriptionData, err := _i.subscriptionService.Show(clientId, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -115,7 +122,10 @@ func (_i *subscriptionController) Save(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
dataResult, err := _i.subscriptionService.Save(*req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
dataResult, err := _i.subscriptionService.Save(clientId, *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -151,7 +161,10 @@ func (_i *subscriptionController) Update(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = _i.subscriptionService.Update(uint(id), *req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.subscriptionService.Update(clientId, uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -180,7 +193,10 @@ func (_i *subscriptionController) Delete(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = _i.subscriptionService.Delete(uint(id))
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
err = _i.subscriptionService.Delete(clientId, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package repository
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"strings"
|
||||
"web-medols-be/app/database"
|
||||
|
|
@ -17,11 +18,11 @@ type subscriptionRepository struct {
|
|||
|
||||
// SubscriptionRepository define interface of ISubscriptionRepository
|
||||
type SubscriptionRepository interface {
|
||||
GetAll(req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (subscription *entity.Subscription, err error)
|
||||
GetAll(clientId *uuid.UUID, req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error)
|
||||
FindOne(clientId *uuid.UUID, id uint) (subscription *entity.Subscription, err error)
|
||||
Create(subscription *entity.Subscription) (subscriptionReturn *entity.Subscription, err error)
|
||||
Update(id uint, subscription *entity.Subscription) (err error)
|
||||
Delete(id uint) (err error)
|
||||
Update(clientId *uuid.UUID, id uint, subscription *entity.Subscription) (err error)
|
||||
Delete(clientId *uuid.UUID, id uint) (err error)
|
||||
}
|
||||
|
||||
func NewSubscriptionRepository(db *database.Database, logger zerolog.Logger) SubscriptionRepository {
|
||||
|
|
@ -32,10 +33,16 @@ func NewSubscriptionRepository(db *database.Database, logger zerolog.Logger) Sub
|
|||
}
|
||||
|
||||
// implement interface of ISubscriptionRepository
|
||||
func (_i *subscriptionRepository) GetAll(req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error) {
|
||||
func (_i *subscriptionRepository) GetAll(clientId *uuid.UUID, req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.Subscription{})
|
||||
|
||||
// Add ClientId filter
|
||||
if clientId != nil {
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
}
|
||||
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Email != nil && *req.Email != "" {
|
||||
|
|
@ -65,8 +72,15 @@ func (_i *subscriptionRepository) GetAll(req request.SubscriptionQueryRequest) (
|
|||
return
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) FindOne(id uint) (subscription *entity.Subscription, err error) {
|
||||
if err := _i.DB.DB.First(&subscription, id).Error; err != nil {
|
||||
func (_i *subscriptionRepository) FindOne(clientId *uuid.UUID, id uint) (subscription *entity.Subscription, err error) {
|
||||
query := _i.DB.DB.Where("id = ?", id)
|
||||
|
||||
// Add ClientId filter
|
||||
if clientId != nil {
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
}
|
||||
|
||||
if err := query.First(&subscription).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -78,12 +92,18 @@ func (_i *subscriptionRepository) Create(subscription *entity.Subscription) (sub
|
|||
return subscription, result.Error
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) Update(id uint, subscription *entity.Subscription) (err error) {
|
||||
return _i.DB.DB.Model(&entity.Subscription{}).
|
||||
Where(&entity.Subscription{ID: id}).
|
||||
Updates(subscription).Error
|
||||
func (_i *subscriptionRepository) Update(clientId *uuid.UUID, id uint, subscription *entity.Subscription) (err error) {
|
||||
query := _i.DB.DB.Model(&entity.Subscription{}).Where(&entity.Subscription{ID: id})
|
||||
if clientId != nil {
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
}
|
||||
return query.Updates(subscription).Error
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.Subscription{}, id).Error
|
||||
func (_i *subscriptionRepository) Delete(clientId *uuid.UUID, id uint) error {
|
||||
query := _i.DB.DB.Model(&entity.Subscription{}).Where("id = ?", id)
|
||||
if clientId != nil {
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
}
|
||||
return query.Delete(&entity.Subscription{}).Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"web-medols-be/app/database/entity"
|
||||
"web-medols-be/app/module/subscription/mapper"
|
||||
|
|
@ -20,11 +21,11 @@ type subscriptionService struct {
|
|||
|
||||
// SubscriptionService define interface of ISubscriptionService
|
||||
type SubscriptionService interface {
|
||||
All(req request.SubscriptionQueryRequest) (subscription []*response.SubscriptionResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (subscription *response.SubscriptionResponse, err error)
|
||||
Save(req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error)
|
||||
Update(id uint, req request.SubscriptionUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
All(clientId *uuid.UUID, req request.SubscriptionQueryRequest) (subscription []*response.SubscriptionResponse, paging paginator.Pagination, err error)
|
||||
Show(clientId *uuid.UUID, id uint) (subscription *response.SubscriptionResponse, err error)
|
||||
Save(clientId *uuid.UUID, req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error)
|
||||
Update(clientId *uuid.UUID, id uint, req request.SubscriptionUpdateRequest) (err error)
|
||||
Delete(clientId *uuid.UUID, id uint) error
|
||||
}
|
||||
|
||||
// NewSubscriptionService init SubscriptionService
|
||||
|
|
@ -38,8 +39,8 @@ func NewSubscriptionService(repo repository.SubscriptionRepository, log zerolog.
|
|||
}
|
||||
|
||||
// All implement interface of SubscriptionService
|
||||
func (_i *subscriptionService) All(req request.SubscriptionQueryRequest) (subscriptions []*response.SubscriptionResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
func (_i *subscriptionService) All(clientId *uuid.UUID, req request.SubscriptionQueryRequest) (subscriptions []*response.SubscriptionResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(clientId, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -51,8 +52,8 @@ func (_i *subscriptionService) All(req request.SubscriptionQueryRequest) (subscr
|
|||
return
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Show(id uint) (subscription *response.SubscriptionResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *subscriptionService) Show(clientId *uuid.UUID, id uint) (subscription *response.SubscriptionResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(clientId, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -60,23 +61,32 @@ func (_i *subscriptionService) Show(id uint) (subscription *response.Subscriptio
|
|||
return mapper.SubscriptionResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Save(req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error) {
|
||||
func (_i *subscriptionService) Save(clientId *uuid.UUID, req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
||||
// Set ClientId on entity
|
||||
newReq.ClientId = clientId
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Update(id uint, req request.SubscriptionUpdateRequest) (err error) {
|
||||
func (_i *subscriptionService) Update(clientId *uuid.UUID, id uint, req request.SubscriptionUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
|
||||
// Set ClientId on entity
|
||||
entity := req.ToEntity()
|
||||
entity.ClientId = clientId
|
||||
|
||||
return _i.Repo.Update(clientId, id, entity)
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *subscriptionService) Delete(clientId *uuid.UUID, id uint) error {
|
||||
result, err := _i.Repo.FindOne(clientId, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.IsActive = true
|
||||
return _i.Repo.Update(id, result)
|
||||
result.IsActive = false
|
||||
return _i.Repo.Update(clientId, id, result)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -561,7 +561,10 @@ func (_i *usersController) SetupEmail(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
messageResponse, err := _i.usersService.SetupEmail(*req)
|
||||
// Get ClientId from context
|
||||
clientId := middleware.GetClientID(c)
|
||||
|
||||
messageResponse, err := _i.usersService.SetupEmail(clientId, *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ type UsersService interface {
|
|||
ResetPassword(req request.UserResetPassword) (err error)
|
||||
ForgotPassword(clientId *uuid.UUID, req request.UserForgotPassword) (err error)
|
||||
EmailValidationPreLogin(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error)
|
||||
SetupEmail(req request.UserEmailValidationRequest) (msgResponse *string, err error)
|
||||
SetupEmail(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error)
|
||||
OtpRequest(req request.UserOtpRequest) (err error)
|
||||
OtpValidation(req request.UserOtpValidation) (err error)
|
||||
SendLoginOtp(name string, email string, otp string) error
|
||||
|
|
@ -456,7 +456,7 @@ func (_i *usersService) EmailValidationPreLogin(clientId *uuid.UUID, req request
|
|||
return msgResponse, nil
|
||||
}
|
||||
|
||||
func (_i *usersService) SetupEmail(req request.UserEmailValidationRequest) (msgResponse *string, err error) {
|
||||
func (_i *usersService) SetupEmail(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
var loginResponse *gocloak.JWT
|
||||
|
|
@ -467,7 +467,7 @@ func (_i *usersService) SetupEmail(req request.UserEmailValidationRequest) (msgR
|
|||
}
|
||||
|
||||
_i.Log.Info().Interface("findUser", "").Msg("")
|
||||
findUser, err := _i.Repo.FindByUsername(*req.Username)
|
||||
findUser, err := _i.Repo.FindByUsername(clientId, *req.Username)
|
||||
|
||||
_i.Log.Info().Interface("findUser", findUser).Msg("")
|
||||
if findUser == nil || err != nil {
|
||||
|
|
@ -479,7 +479,7 @@ func (_i *usersService) SetupEmail(req request.UserEmailValidationRequest) (msgR
|
|||
findUser.Email = *req.NewEmail
|
||||
findUser.IsEmailUpdated = &isTrue
|
||||
_i.Log.Info().Interface("Update", "").Msg("")
|
||||
err = _i.Repo.Update(findUser.ID, findUser)
|
||||
err = _i.Repo.Update(clientId, findUser.ID, findUser)
|
||||
_i.Log.Info().Interface("Update", err).Msg("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue