Add Company Profile Retrieval Endpoint and Update API Documentation
- Introduced a new public API endpoint to retrieve the profile of the authenticated user's company, enhancing the functionality of the tender management system. - Implemented the `MyCompany` method in the company handler to handle requests for the company profile, ensuring proper authentication and error handling. - Updated Swagger and YAML documentation to accurately reflect the new endpoint, including detailed descriptions, parameters, and response formats for the `CompanyProfileResponse`. - Modified the router to include the new company profile route, ensuring adherence to Clean Architecture principles and maintaining a clear separation of concerns in the handler layer. - Enhanced the public routes registration to include the company handler, improving the overall API structure and usability.
This commit is contained in:
@@ -202,3 +202,25 @@ func (c *Company) ToResponse() *CompanyResponse {
|
||||
UpdatedBy: c.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
type CompanyProfileResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RegistrationNumber string `json:"registration_number"`
|
||||
Industry string `json:"industry"`
|
||||
Country string `json:"country"`
|
||||
FoundedYear *int `json:"founded_year,omitempty"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
}
|
||||
|
||||
// ToResponse converts Company to CompanyResponse
|
||||
func (c *Company) ToProfileResponse() *CompanyProfileResponse {
|
||||
return &CompanyProfileResponse{
|
||||
ID: c.ID.Hex(),
|
||||
Name: c.Name,
|
||||
RegistrationNumber: c.RegistrationNumber,
|
||||
Industry: c.Industry,
|
||||
FoundedYear: c.FoundedYear,
|
||||
CreatedAt: c.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,35 @@ func NewHandler(service Service, userHandler *user.Handler, logger logger.Logger
|
||||
}
|
||||
}
|
||||
|
||||
// **************************** PUBLIC ENDPOINTS ****************************
|
||||
|
||||
// MyCompany returns the authenticated user's company profile (Mobile App)
|
||||
// @Summary Get my company profile
|
||||
// @Description Retrieve the profile of the company associated with the authenticated user
|
||||
// @Tags Company
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.APIResponse{data=CompanyProfileResponse} "Company retrieved successfully"
|
||||
// @Failure 401 {object} response.APIResponse "Unauthorized - User not authenticated"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/companies [get]
|
||||
func (h *Handler) MyCompany(c echo.Context) error {
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.Unauthorized(c, "User not authenticated")
|
||||
}
|
||||
|
||||
company, err := h.service.GetCompanyByID(c.Request().Context(), companyID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to get company")
|
||||
}
|
||||
|
||||
return response.Success(c, company.ToProfileResponse(), "Company retrieved successfully")
|
||||
}
|
||||
|
||||
// **************************** ADMIN ENDPOINTS ****************************
|
||||
|
||||
// CreateCompany creates a new company (Web Panel)
|
||||
// @Summary Create a new company
|
||||
// @Description Create a new company with comprehensive information including business details, address, tags, and customer assignment. This endpoint is used by the web panel for full company registration.
|
||||
|
||||
Reference in New Issue
Block a user