Add functionality to manage external links for companies
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced the ability to append external links to company profiles through a new API endpoint. - Enhanced the `Company` entity to include a `Links` field for storing external resource links. - Created `AddLinksForm` for validating incoming link data and implemented corresponding logic in the service layer. - Added error handling for link validation, ensuring only valid URLs are accepted and limiting the number of links to 20. - Implemented unit tests for link management functions, including sanitization and merging of links. - Updated relevant API documentation to reflect the new functionality. This update significantly enhances the company management capabilities by allowing the addition of external links, improving the overall user experience and data richness in company profiles.
This commit is contained in:
@@ -168,6 +168,9 @@ func (h *Handler) Create(c echo.Context) error {
|
||||
err.Error() == "failed to validate categories" {
|
||||
return response.BadRequest(c, err.Error(), "Invalid category data")
|
||||
}
|
||||
if err.Error() == "invalid link URL" || err.Error() == "too many links provided" {
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to create company")
|
||||
}
|
||||
|
||||
@@ -238,6 +241,9 @@ func (h *Handler) Update(c echo.Context) error {
|
||||
err.Error() == "failed to validate categories" {
|
||||
return response.BadRequest(c, err.Error(), "Invalid category data")
|
||||
}
|
||||
if err.Error() == "invalid link URL" || err.Error() == "too many links provided" {
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to update company")
|
||||
}
|
||||
|
||||
@@ -455,6 +461,54 @@ func (h *Handler) UploadDocuments(c echo.Context) error {
|
||||
return response.Success(c, result, message)
|
||||
}
|
||||
|
||||
// AddLinks appends external links to a company (Web Panel)
|
||||
// @Summary Add company links
|
||||
// @Description Append one or more external URLs to the company (max 20 links per request)
|
||||
// @Tags Admin-Companies
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Company ID"
|
||||
// @Param links body AddLinksForm true "Links to append"
|
||||
// @Success 200 {object} response.APIResponse{data=AddLinksResponse} "Links added successfully"
|
||||
// @Failure 400 {object} response.APIResponse "Bad request - No links or invalid URLs"
|
||||
// @Failure 404 {object} response.APIResponse "Not found - Company not found"
|
||||
// @Failure 422 {object} response.APIResponse "Validation error - Invalid request data"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /admin/v1/companies/{id}/links [post]
|
||||
func (h *Handler) AddLinks(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
form, err := response.Parse[AddLinksForm](c)
|
||||
if err != nil {
|
||||
return response.ValidationError(c, "Invalid request data", err.Error())
|
||||
}
|
||||
if len(form.Links) > maxCompanyLinks {
|
||||
return response.ValidationError(c, "Too many links", "Maximum 20 links per request")
|
||||
}
|
||||
|
||||
result, err := h.service.AddLinks(c.Request().Context(), id, form)
|
||||
if err != nil {
|
||||
switch err.Error() {
|
||||
case "company not found":
|
||||
return response.NotFound(c, "Company not found")
|
||||
case "no links provided", "no valid links provided", "invalid link URL":
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
case "too many links in request", "company link limit exceeded":
|
||||
return response.ValidationError(c, err.Error(), "")
|
||||
default:
|
||||
return response.InternalServerError(c, "Failed to add company links")
|
||||
}
|
||||
}
|
||||
|
||||
message := "Company links added successfully"
|
||||
if len(result.Added) == 0 {
|
||||
message = "No new company links were added"
|
||||
}
|
||||
|
||||
return response.Success(c, result, message)
|
||||
}
|
||||
|
||||
func collectCompanyUploadFiles(form *multipart.Form) []*multipart.FileHeader {
|
||||
if form == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user