Add missing CRUD routes: Companies GET by ID, Support Tickets

This commit is contained in:
Tiago Yamamoto 2025-12-26 10:20:38 -03:00
parent d61b4db69a
commit ee5a680468
6 changed files with 141 additions and 4 deletions

View file

@ -364,6 +364,44 @@ const docTemplate = `{
}
}
},
"/api/v1/companies/{id}": {
"get": {
"description": "Retrieves a company by its ID.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Companies"
],
"summary": "Get Company",
"parameters": [
{
"type": "string",
"description": "Company ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "string"
}
}
}
}
},
"/api/v1/jobs": {
"get": {
"description": "Get a paginated list of job postings with optional filters",

View file

@ -357,6 +357,44 @@
}
}
},
"/api/v1/companies/{id}": {
"get": {
"description": "Retrieves a company by its ID.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Companies"
],
"summary": "Get Company",
"parameters": [
{
"type": "string",
"description": "Company ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "string"
}
}
}
}
},
"/api/v1/jobs": {
"get": {
"description": "Get a paginated list of job postings with optional filters",

View file

@ -620,6 +620,31 @@ paths:
summary: Create Company (Tenant)
tags:
- Companies
/api/v1/companies/{id}:
get:
consumes:
- application/json
description: Retrieves a company by its ID.
parameters:
- description: Company ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: object
"404":
description: Not Found
schema:
type: string
summary: Get Company
tags:
- Companies
/api/v1/jobs:
get:
consumes:

View file

@ -228,6 +228,33 @@ func (h *CoreHandlers) ListCompanies(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(resp)
}
// GetCompanyByID retrieves a single company by ID.
// @Summary Get Company
// @Description Retrieves a company by its ID.
// @Tags Companies
// @Accept json
// @Produce json
// @Param id path string true "Company ID"
// @Success 200 {object} object
// @Failure 404 {string} string "Not Found"
// @Router /api/v1/companies/{id} [get]
func (h *CoreHandlers) GetCompanyByID(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
http.Error(w, "Company ID is required", http.StatusBadRequest)
return
}
company, err := h.adminService.GetCompanyByID(r.Context(), id)
if err != nil {
http.Error(w, "Company not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(company)
}
// CreateUser creates a new user within the authenticated tenant.
// @Summary Create User
// @Description Creates a new user under the current tenant. Requires Admin role.

View file

@ -193,9 +193,18 @@ func NewRouter() http.Handler {
// /api/v1/admin/candidates -> /api/v1/candidates
mux.Handle("GET /api/v1/candidates", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.ListCandidates))))
// Get Company by ID (Public)
mux.HandleFunc("GET /api/v1/companies/{id}", coreHandlers.GetCompanyByID)
// Notifications Route
mux.Handle("GET /api/v1/notifications", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.ListNotifications)))
// Support Ticket Routes
mux.Handle("GET /api/v1/support/tickets", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.ListTickets)))
mux.Handle("POST /api/v1/support/tickets", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.CreateTicket)))
mux.Handle("GET /api/v1/support/tickets/{id}", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.GetTicket)))
mux.Handle("POST /api/v1/support/tickets/{id}/messages", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.AddMessage)))
// Application Routes
mux.HandleFunc("POST /api/v1/applications", applicationHandler.CreateApplication)
mux.HandleFunc("GET /api/v1/applications", applicationHandler.GetApplications)

View file

@ -139,7 +139,7 @@ func (s *AdminService) ListUsers(ctx context.Context, page, limit int, companyID
}
func (s *AdminService) UpdateCompanyStatus(ctx context.Context, id string, active *bool, verified *bool) (*models.Company, error) {
company, err := s.getCompanyByID(ctx, id)
company, err := s.GetCompanyByID(ctx, id)
if err != nil {
return nil, err
}
@ -536,7 +536,7 @@ func isActiveApplicationStatus(status string) bool {
}
}
func (s *AdminService) getCompanyByID(ctx context.Context, id string) (*models.Company, error) {
func (s *AdminService) GetCompanyByID(ctx context.Context, id string) (*models.Company, error) {
query := `
SELECT id, name, slug, type, document, address, region_id, city_id, phone, email, website, logo_url, description, active, verified, created_at, updated_at
FROM companies WHERE id = $1
@ -626,7 +626,7 @@ func (s *AdminService) GetCompanyByUserID(ctx context.Context, userID string) (*
}
func (s *AdminService) UpdateCompany(ctx context.Context, id string, req dto.UpdateCompanyRequest) (*models.Company, error) {
company, err := s.getCompanyByID(ctx, id)
company, err := s.GetCompanyByID(ctx, id)
if err != nil {
return nil, err
}
@ -700,7 +700,7 @@ func (s *AdminService) UpdateCompany(ctx context.Context, id string, req dto.Upd
func (s *AdminService) DeleteCompany(ctx context.Context, id string) error {
// First check if exists
_, err := s.getCompanyByID(ctx, id)
_, err := s.GetCompanyByID(ctx, id)
if err != nil {
return err
}