feat: add api public client
This commit is contained in:
parent
becc86c042
commit
cc81599c76
|
|
@ -49,7 +49,6 @@ func (_i *ClientsRouter) RegisterClientsRoutes() {
|
||||||
// define routes
|
// define routes
|
||||||
_i.App.Route("/clients", func(router fiber.Router) {
|
_i.App.Route("/clients", func(router fiber.Router) {
|
||||||
router.Get("/", clientsController.All)
|
router.Get("/", clientsController.All)
|
||||||
router.Get("/public", clientsController.PublicAll)
|
|
||||||
router.Get("/profile", clientsController.ShowWithAuth)
|
router.Get("/profile", clientsController.ShowWithAuth)
|
||||||
router.Get("/check-name/:name", clientsController.CheckClientNameExists)
|
router.Get("/check-name/:name", clientsController.CheckClientNameExists)
|
||||||
router.Get("/:id", clientsController.Show)
|
router.Get("/:id", clientsController.Show)
|
||||||
|
|
@ -65,4 +64,10 @@ func (_i *ClientsRouter) RegisterClientsRoutes() {
|
||||||
router.Get("/:id/logo/url", clientsController.GetLogoURL)
|
router.Get("/:id/logo/url", clientsController.GetLogoURL)
|
||||||
router.Get("/logo/:filename", clientsController.ViewLogo)
|
router.Get("/logo/:filename", clientsController.ViewLogo)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Public routes (no authentication required)
|
||||||
|
_i.App.Route("/clients/public", func(router fiber.Router) {
|
||||||
|
router.Get("/", clientsController.PublicAll)
|
||||||
|
router.Get("/slug/:slug", clientsController.ShowBySlugPublic)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ type ClientsController interface {
|
||||||
PublicAll(c *fiber.Ctx) error
|
PublicAll(c *fiber.Ctx) error
|
||||||
Show(c *fiber.Ctx) error
|
Show(c *fiber.Ctx) error
|
||||||
ShowWithAuth(c *fiber.Ctx) error
|
ShowWithAuth(c *fiber.Ctx) error
|
||||||
|
ShowBySlugPublic(c *fiber.Ctx) error
|
||||||
CheckClientNameExists(c *fiber.Ctx) error
|
CheckClientNameExists(c *fiber.Ctx) error
|
||||||
Save(c *fiber.Ctx) error
|
Save(c *fiber.Ctx) error
|
||||||
Update(c *fiber.Ctx) error
|
Update(c *fiber.Ctx) error
|
||||||
|
|
@ -219,6 +220,34 @@ func (_i *clientsController) ShowWithAuth(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShowBySlugPublic get Clients by slug (Public)
|
||||||
|
// @Summary Get Clients by slug (Public)
|
||||||
|
// @Description API for getting Clients by slug for public consumption
|
||||||
|
// @Tags Clients
|
||||||
|
// @Param slug path string true "Client slug"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
// @Failure 500 {object} response.InternalServerError
|
||||||
|
// @Router /clients/public/slug/{slug} [get]
|
||||||
|
func (_i *clientsController) ShowBySlugPublic(c *fiber.Ctx) error {
|
||||||
|
slug := c.Params("slug")
|
||||||
|
|
||||||
|
clientsData, err := _i.clientsService.ShowBySlugPublic(slug)
|
||||||
|
if err != nil {
|
||||||
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: false,
|
||||||
|
Messages: utilRes.Messages{err.Error()},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
|
Messages: utilRes.Messages{"Client successfully retrieved"},
|
||||||
|
Data: clientsData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// CheckClientNameExists check if client name exists
|
// CheckClientNameExists check if client name exists
|
||||||
// @Summary Check if client name exists
|
// @Summary Check if client name exists
|
||||||
// @Description API for checking if client name exists (returns only exist status)
|
// @Description API for checking if client name exists (returns only exist status)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ type ClientsRepository interface {
|
||||||
FindOneByClientId(clientId *uuid.UUID) (clients *entity.Clients, err error)
|
FindOneByClientId(clientId *uuid.UUID) (clients *entity.Clients, err error)
|
||||||
FindByName(name string) (clients *entity.Clients, err error)
|
FindByName(name string) (clients *entity.Clients, err error)
|
||||||
FindBySlug(slug string) (clients *entity.Clients, err error)
|
FindBySlug(slug string) (clients *entity.Clients, err error)
|
||||||
|
FindBySlugPublic(slug string) (clients *entity.Clients, err error)
|
||||||
FindByImagePathName(name string) (clients *entity.Clients, err error)
|
FindByImagePathName(name string) (clients *entity.Clients, err error)
|
||||||
Create(clients *entity.Clients) (clientsReturn *entity.Clients, err error)
|
Create(clients *entity.Clients) (clientsReturn *entity.Clients, err error)
|
||||||
Update(id uuid.UUID, clients *entity.Clients) (err error)
|
Update(id uuid.UUID, clients *entity.Clients) (err error)
|
||||||
|
|
@ -169,6 +170,17 @@ func (_i *clientsRepository) FindBySlug(slug string) (clients *entity.Clients, e
|
||||||
return clients, nil
|
return clients, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *clientsRepository) FindBySlugPublic(slug string) (clients *entity.Clients, err error) {
|
||||||
|
_i.Log.Info().Str("slug", slug).Msg("Finding client by slug for public consumption")
|
||||||
|
|
||||||
|
// For public access, only return active clients
|
||||||
|
if err := _i.DB.DB.Where("slug = ? AND is_active = ?", slug, true).First(&clients).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return clients, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *clientsRepository) FindByImagePathName(name string) (clients *entity.Clients, err error) {
|
func (_i *clientsRepository) FindByImagePathName(name string) (clients *entity.Clients, err error) {
|
||||||
if err := _i.DB.DB.Where("logo_image_path like ?", "%"+name+"%").First(&clients).Error; err != nil {
|
if err := _i.DB.DB.Where("logo_image_path like ?", "%"+name+"%").First(&clients).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ type ClientsService interface {
|
||||||
Show(id uuid.UUID) (clients *response.ClientsResponse, err error)
|
Show(id uuid.UUID) (clients *response.ClientsResponse, err error)
|
||||||
CheckClientNameExists(name string) (exists bool, err error)
|
CheckClientNameExists(name string) (exists bool, err error)
|
||||||
ShowWithAuth(authToken string) (clients *response.ClientsResponse, err error)
|
ShowWithAuth(authToken string) (clients *response.ClientsResponse, err error)
|
||||||
|
ShowBySlugPublic(slug string) (clients *response.PublicClientsResponse, err error)
|
||||||
Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error)
|
Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error)
|
||||||
Update(id uuid.UUID, req request.ClientsUpdateRequest) (err error)
|
Update(id uuid.UUID, req request.ClientsUpdateRequest) (err error)
|
||||||
UpdateWithAuth(authToken string, req request.ClientsUpdateRequest) (err error)
|
UpdateWithAuth(authToken string, req request.ClientsUpdateRequest) (err error)
|
||||||
|
|
@ -175,6 +176,19 @@ func (_i *clientsService) ShowWithAuth(authToken string) (clients *response.Clie
|
||||||
return mapper.ClientsResponseMapper(result), nil
|
return mapper.ClientsResponseMapper(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *clientsService) ShowBySlugPublic(slug string) (clients *response.PublicClientsResponse, err error) {
|
||||||
|
_i.Log.Info().Str("slug", slug).Msg("Getting client by slug for public consumption")
|
||||||
|
|
||||||
|
// For public access, only return active clients
|
||||||
|
result, err := _i.Repo.FindBySlugPublic(slug)
|
||||||
|
if err != nil {
|
||||||
|
_i.Log.Error().Err(err).Str("slug", slug).Msg("Failed to find client by slug")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapper.PublicClientsResponseMapper(result), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *clientsService) Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error) {
|
func (_i *clientsService) Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10046,6 +10046,50 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/clients/public/slug/{slug}": {
|
||||||
|
"get": {
|
||||||
|
"description": "API for getting Clients by slug for public consumption",
|
||||||
|
"tags": [
|
||||||
|
"Clients"
|
||||||
|
],
|
||||||
|
"summary": "Get Clients by slug (Public)",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Client slug",
|
||||||
|
"name": "slug",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/clients/update": {
|
"/clients/update": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -10035,6 +10035,50 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/clients/public/slug/{slug}": {
|
||||||
|
"get": {
|
||||||
|
"description": "API for getting Clients by slug for public consumption",
|
||||||
|
"tags": [
|
||||||
|
"Clients"
|
||||||
|
],
|
||||||
|
"summary": "Get Clients by slug (Public)",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Client slug",
|
||||||
|
"name": "slug",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/clients/update": {
|
"/clients/update": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -8436,6 +8436,35 @@ paths:
|
||||||
summary: Get all Clients (Public)
|
summary: Get all Clients (Public)
|
||||||
tags:
|
tags:
|
||||||
- Clients
|
- Clients
|
||||||
|
/clients/public/slug/{slug}:
|
||||||
|
get:
|
||||||
|
description: API for getting Clients by slug for public consumption
|
||||||
|
parameters:
|
||||||
|
- description: Client slug
|
||||||
|
in: path
|
||||||
|
name: slug
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.BadRequestError'
|
||||||
|
"401":
|
||||||
|
description: Unauthorized
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.UnauthorizedError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.InternalServerError'
|
||||||
|
summary: Get Clients by slug (Public)
|
||||||
|
tags:
|
||||||
|
- Clients
|
||||||
/clients/update:
|
/clients/update:
|
||||||
put:
|
put:
|
||||||
description: API for update Clients using client ID from auth token
|
description: API for update Clients using client ID from auth token
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue