fix: resolve remaining merge conflicts
This commit is contained in:
parent
eb1276eac4
commit
948858eca0
8 changed files with 3292 additions and 3528 deletions
|
|
@ -35,7 +35,6 @@ type CoreHandlers struct {
|
||||||
credentialsService *services.CredentialsService
|
credentialsService *services.CredentialsService
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
func NewCoreHandlers(
|
func NewCoreHandlers(
|
||||||
l *auth.LoginUseCase,
|
l *auth.LoginUseCase,
|
||||||
reg *auth.RegisterCandidateUseCase,
|
reg *auth.RegisterCandidateUseCase,
|
||||||
|
|
@ -44,6 +43,7 @@ func NewCoreHandlers(
|
||||||
list *user.ListUsersUseCase,
|
list *user.ListUsersUseCase,
|
||||||
del *user.DeleteUserUseCase,
|
del *user.DeleteUserUseCase,
|
||||||
upd *user.UpdateUserUseCase,
|
upd *user.UpdateUserUseCase,
|
||||||
|
updatePasswordUC *user.UpdatePasswordUseCase,
|
||||||
lc *tenant.ListCompaniesUseCase,
|
lc *tenant.ListCompaniesUseCase,
|
||||||
fp *auth.ForgotPasswordUseCase,
|
fp *auth.ForgotPasswordUseCase,
|
||||||
rp *auth.ResetPasswordUseCase,
|
rp *auth.ResetPasswordUseCase,
|
||||||
|
|
@ -53,9 +53,6 @@ func NewCoreHandlers(
|
||||||
adminService *services.AdminService,
|
adminService *services.AdminService,
|
||||||
credentialsService *services.CredentialsService,
|
credentialsService *services.CredentialsService,
|
||||||
) *CoreHandlers {
|
) *CoreHandlers {
|
||||||
=======
|
|
||||||
func NewCoreHandlers(l *auth.LoginUseCase, reg *auth.RegisterCandidateUseCase, c *tenant.CreateCompanyUseCase, u *user.CreateUserUseCase, list *user.ListUsersUseCase, del *user.DeleteUserUseCase, upd *user.UpdateUserUseCase, updatePasswordUC *user.UpdatePasswordUseCase, lc *tenant.ListCompaniesUseCase, auditService *services.AuditService, notificationService *services.NotificationService, ticketService *services.TicketService, adminService *services.AdminService, credentialsService *services.CredentialsService) *CoreHandlers {
|
|
||||||
>>>>>>> dev
|
|
||||||
return &CoreHandlers{
|
return &CoreHandlers{
|
||||||
loginUC: l,
|
loginUC: l,
|
||||||
registerCandidateUC: reg,
|
registerCandidateUC: reg,
|
||||||
|
|
@ -119,10 +116,9 @@ func (h *CoreHandlers) Login(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Set HttpOnly Cookie
|
// Set HttpOnly Cookie
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "jwt",
|
Name: "jwt",
|
||||||
Value: resp.Token,
|
Value: resp.Token,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
// Domain: "localhost", // Or separate based on env
|
|
||||||
Expires: time.Now().Add(24 * time.Hour),
|
Expires: time.Now().Add(24 * time.Hour),
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: false, // Set to true in production with HTTPS
|
Secure: false, // Set to true in production with HTTPS
|
||||||
|
|
@ -181,7 +177,6 @@ func (h *CoreHandlers) RegisterCandidate(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
resp, err := h.registerCandidateUC.Execute(r.Context(), req)
|
resp, err := h.registerCandidateUC.Execute(r.Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log removed to fix compilation error (LogAction missing)
|
|
||||||
http.Error(w, err.Error(), http.StatusConflict)
|
http.Error(w, err.Error(), http.StatusConflict)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -750,7 +745,7 @@ func (h *CoreHandlers) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
_ = h.forgotPasswordUC.Execute(r.Context(), req)
|
_ = h.forgotPasswordUC.Execute(r.Context(), req)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]string{"message": "Se o email estiver cadastrado, você receberá um link de recuperação."})
|
json.NewEncoder(w).Encode(map[string]string{"message": "Se o email estiver cadastrado, voce recebera um link de recuperacao."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetPassword resets the user's password.
|
// ResetPassword resets the user's password.
|
||||||
|
|
@ -1130,11 +1125,8 @@ func (h *CoreHandlers) UpdateMyProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// userID (string) passed directly as first arg
|
|
||||||
// log.Printf("[UpdateMyProfile] UserID: %s, TenantID: %s", userID, tenantID)
|
|
||||||
resp, err := h.updateUserUC.Execute(ctx, userID, tenantID, req)
|
resp, err := h.updateUserUC.Execute(ctx, userID, tenantID, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.Printf("[UpdateMyProfile] Error: %v", err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1216,20 +1208,6 @@ func (h *CoreHandlers) UploadMyAvatar(w http.ResponseWriter, r *http.Request) {
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Failure 500 {string} string "Internal Server Error"
|
// @Failure 500 {string} string "Internal Server Error"
|
||||||
// @Router /api/v1/users/me [get]
|
// @Router /api/v1/users/me [get]
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
// Me returns the current user profile including company info.
|
|
||||||
// @Summary Get My Profile
|
|
||||||
// @Description Returns the profile of the authenticated user.
|
|
||||||
// @Tags Users
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security BearerAuth
|
|
||||||
// @Success 200 {object} object
|
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
|
||||||
// @Failure 500 {string} string "Internal Server Error"
|
|
||||||
// @Router /api/v1/users/me [get]
|
|
||||||
>>>>>>> dev
|
|
||||||
func (h *CoreHandlers) Me(w http.ResponseWriter, r *http.Request) {
|
func (h *CoreHandlers) Me(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
userIDVal := ctx.Value(middleware.ContextUserID)
|
userIDVal := ctx.Value(middleware.ContextUserID)
|
||||||
|
|
@ -1310,7 +1288,6 @@ func (h *CoreHandlers) SaveFCMToken(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]string{"message": "Token saved successfully"})
|
json.NewEncoder(w).Encode(map[string]string{"message": "Token saved successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
// SaveCredentials saves encrypted credentials for external services.
|
// SaveCredentials saves encrypted credentials for external services.
|
||||||
// @Summary Save Credentials
|
// @Summary Save Credentials
|
||||||
// @Description Saves encrypted credentials payload (e.g. Stripe key encrypted by Backoffice)
|
// @Description Saves encrypted credentials payload (e.g. Stripe key encrypted by Backoffice)
|
||||||
|
|
@ -1356,8 +1333,6 @@ func (h *CoreHandlers) SaveCredentials(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]string{"message": "Credentials saved successfully"})
|
json.NewEncoder(w).Encode(map[string]string{"message": "Credentials saved successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> dev
|
|
||||||
// hasAdminRole checks if roles array contains admin or superadmin
|
// hasAdminRole checks if roles array contains admin or superadmin
|
||||||
func hasAdminRole(roles []string) bool {
|
func hasAdminRole(roles []string) bool {
|
||||||
for _, r := range roles {
|
for _, r := range roles {
|
||||||
|
|
|
||||||
|
|
@ -161,8 +161,6 @@ func TestLoginHandler_Success(t *testing.T) {
|
||||||
// Return entity.User
|
// Return entity.User
|
||||||
u := entity.NewUser("u1", "t1", "John", "john@example.com")
|
u := entity.NewUser("u1", "t1", "John", "john@example.com")
|
||||||
u.PasswordHash = "hashed_123456"
|
u.PasswordHash = "hashed_123456"
|
||||||
// Add Role if needed (mocked)
|
|
||||||
// u.Roles = ...
|
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
return nil, nil // Not found
|
return nil, nil // Not found
|
||||||
|
|
@ -239,21 +237,13 @@ func createTestCoreHandlers(t *testing.T, db *sql.DB, loginUC *auth.LoginUseCase
|
||||||
(*user.UpdateUserUseCase)(nil),
|
(*user.UpdateUserUseCase)(nil),
|
||||||
(*user.UpdatePasswordUseCase)(nil),
|
(*user.UpdatePasswordUseCase)(nil),
|
||||||
(*tenant.ListCompaniesUseCase)(nil),
|
(*tenant.ListCompaniesUseCase)(nil),
|
||||||
<<<<<<< HEAD
|
nil, // forgotPasswordUC
|
||||||
nil,
|
nil, // resetPasswordUC
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
=======
|
|
||||||
auditSvc,
|
auditSvc,
|
||||||
notifSvc,
|
notifSvc,
|
||||||
ticketSvc,
|
ticketSvc,
|
||||||
adminSvc,
|
adminSvc,
|
||||||
credSvc,
|
credSvc,
|
||||||
>>>>>>> dev
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,28 +23,6 @@ const (
|
||||||
|
|
||||||
// User represents a user within a specific Tenant (Company).
|
// User represents a user within a specific Tenant (Company).
|
||||||
type User struct {
|
type User struct {
|
||||||
<<<<<<< HEAD
|
|
||||||
ID string `json:"id"`
|
|
||||||
TenantID string `json:"tenant_id"` // Link to Company
|
|
||||||
Name string `json:"name"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
PasswordHash string `json:"-"`
|
|
||||||
Roles []Role `json:"roles"`
|
|
||||||
Status string `json:"status"` // "ACTIVE", "INACTIVE"
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
|
|
||||||
// HML Fields
|
|
||||||
AvatarUrl string `json:"avatar_url"`
|
|
||||||
Metadata map[string]interface{} `json:"metadata"`
|
|
||||||
|
|
||||||
// HEAD Fields (Profile Profile)
|
|
||||||
Bio string `json:"bio"`
|
|
||||||
ProfilePictureURL string `json:"profile_picture_url"`
|
|
||||||
Skills []string `json:"skills"` // Stored as JSONB, mapped to slice
|
|
||||||
Experience []any `json:"experience,omitempty"` // Flexible JSON structure
|
|
||||||
Education []any `json:"education,omitempty"` // Flexible JSON structure
|
|
||||||
=======
|
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
TenantID string `json:"tenant_id"` // Link to Company
|
TenantID string `json:"tenant_id"` // Link to Company
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
@ -68,7 +46,9 @@ type User struct {
|
||||||
Metadata map[string]interface{} `json:"metadata"`
|
Metadata map[string]interface{} `json:"metadata"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
>>>>>>> dev
|
|
||||||
|
// HEAD Fields (Profile)
|
||||||
|
ProfilePictureURL string `json:"profile_picture_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUser creates a new User instance.
|
// NewUser creates a new User instance.
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,12 @@ type UpdateUserRequest struct {
|
||||||
Name *string `json:"name,omitempty"`
|
Name *string `json:"name,omitempty"`
|
||||||
Email *string `json:"email,omitempty"`
|
Email *string `json:"email,omitempty"`
|
||||||
Phone *string `json:"phone,omitempty"`
|
Phone *string `json:"phone,omitempty"`
|
||||||
Bio *string `json:"bio,omitempty"`
|
|
||||||
Active *bool `json:"active,omitempty"`
|
Active *bool `json:"active,omitempty"`
|
||||||
Status *string `json:"status,omitempty"`
|
Status *string `json:"status,omitempty"`
|
||||||
Roles *[]string `json:"roles,omitempty"`
|
Roles *[]string `json:"roles,omitempty"`
|
||||||
AvatarUrl *string `json:"avatarUrl,omitempty"`
|
AvatarUrl *string `json:"avatarUrl,omitempty"`
|
||||||
|
|
||||||
// HEAD Fields
|
// Profile Fields
|
||||||
Bio *string `json:"bio,omitempty"`
|
Bio *string `json:"bio,omitempty"`
|
||||||
ProfilePictureURL *string `json:"profilePictureUrl,omitempty"`
|
ProfilePictureURL *string `json:"profilePictureUrl,omitempty"`
|
||||||
Skills []string `json:"skills,omitempty"`
|
Skills []string `json:"skills,omitempty"`
|
||||||
|
|
@ -46,21 +45,16 @@ type UserResponse struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
<<<<<<< HEAD
|
AvatarUrl string `json:"avatar_url,omitempty"`
|
||||||
=======
|
|
||||||
AvatarUrl string `json:"avatar_url"`
|
|
||||||
Phone *string `json:"phone,omitempty"`
|
Phone *string `json:"phone,omitempty"`
|
||||||
Bio *string `json:"bio,omitempty"`
|
Bio *string `json:"bio,omitempty"`
|
||||||
>>>>>>> dev
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
|
||||||
// Merged Fields
|
// Profile Fields
|
||||||
AvatarUrl string `json:"avatar_url,omitempty"` // hml
|
ProfilePictureURL string `json:"profile_picture_url,omitempty"`
|
||||||
Bio string `json:"bio,omitempty"` // HEAD
|
Skills []string `json:"skills,omitempty"`
|
||||||
ProfilePictureURL string `json:"profile_picture_url,omitempty"` // HEAD
|
Experience []any `json:"experience,omitempty"`
|
||||||
Skills []string `json:"skills,omitempty"` // HEAD
|
Education []any `json:"education,omitempty"`
|
||||||
Experience []any `json:"experience,omitempty"` // HEAD
|
|
||||||
Education []any `json:"education,omitempty"` // HEAD
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdatePasswordRequest struct {
|
type UpdatePasswordRequest struct {
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,9 @@ func NewJobHandler(service JobServiceInterface) *JobHandler {
|
||||||
// @Tags Jobs
|
// @Tags Jobs
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
<<<<<<< HEAD
|
|
||||||
// @Param page query int false "Page number (default: 1)"
|
// @Param page query int false "Page number (default: 1)"
|
||||||
// @Param limit query int false "Items per page (default: 10, max: 100)"
|
// @Param limit query int false "Items per page (default: 10, max: 100)"
|
||||||
// @Param companyId query int false "Filter by company ID"
|
// @Param companyId query string false "Filter by company ID"
|
||||||
// @Param featured query bool false "Filter by featured status"
|
// @Param featured query bool false "Filter by featured status"
|
||||||
// @Param search query string false "Full-text search query"
|
// @Param search query string false "Full-text search query"
|
||||||
// @Param employmentType query string false "Filter by employment type"
|
// @Param employmentType query string false "Filter by employment type"
|
||||||
|
|
@ -47,12 +46,6 @@ func NewJobHandler(service JobServiceInterface) *JobHandler {
|
||||||
// @Param salaryMax query number false "Maximum salary filter"
|
// @Param salaryMax query number false "Maximum salary filter"
|
||||||
// @Param sortBy query string false "Sort by: date, salary, relevance"
|
// @Param sortBy query string false "Sort by: date, salary, relevance"
|
||||||
// @Param sortOrder query string false "Sort order: asc, desc"
|
// @Param sortOrder query string false "Sort order: asc, desc"
|
||||||
=======
|
|
||||||
// @Param page query int false "Page number (default: 1)"
|
|
||||||
// @Param limit query int false "Items per page (default: 10, max: 100)"
|
|
||||||
// @Param companyId query string false "Filter by company ID"
|
|
||||||
// @Param featured query bool false "Filter by featured status"
|
|
||||||
>>>>>>> dev
|
|
||||||
// @Success 200 {object} dto.PaginatedResponse
|
// @Success 200 {object} dto.PaginatedResponse
|
||||||
// @Failure 500 {string} string "Internal Server Error"
|
// @Failure 500 {string} string "Internal Server Error"
|
||||||
// @Router /api/v1/jobs [get]
|
// @Router /api/v1/jobs [get]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package postgres
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
|
|
@ -58,9 +57,6 @@ func (r *UserRepository) Save(ctx context.Context, user *entity.User) (*entity.U
|
||||||
role = user.Roles[0].Name
|
role = user.Roles[0].Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare pq Array for skills
|
|
||||||
// IMPORTANT: import "github.com/lib/pq" needed at top
|
|
||||||
|
|
||||||
err = tx.QueryRowContext(ctx, query,
|
err = tx.QueryRowContext(ctx, query,
|
||||||
user.Email, // identifier = email
|
user.Email, // identifier = email
|
||||||
user.PasswordHash,
|
user.PasswordHash,
|
||||||
|
|
@ -111,31 +107,14 @@ func (r *UserRepository) Save(ctx context.Context, user *entity.User) (*entity.U
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*entity.User, error) {
|
func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*entity.User, error) {
|
||||||
<<<<<<< HEAD
|
|
||||||
query := `
|
|
||||||
SELECT
|
|
||||||
id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
|
||||||
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
|
||||||
bio, profile_picture_url, skills, experience, education
|
|
||||||
FROM users WHERE email = $1 OR identifier = $1
|
|
||||||
`
|
|
||||||
=======
|
|
||||||
query := `SELECT id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
query := `SELECT id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
||||||
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
||||||
phone, bio, address, city, state, zip_code, birth_date, education, experience, skills, objective, title
|
phone, bio, address, city, state, zip_code, birth_date, education, experience, skills, objective, title
|
||||||
FROM users WHERE email = $1 OR identifier = $1`
|
FROM users WHERE email = $1 OR identifier = $1`
|
||||||
>>>>>>> dev
|
|
||||||
row := r.db.QueryRowContext(ctx, query, email)
|
row := r.db.QueryRowContext(ctx, query, email)
|
||||||
|
|
||||||
u := &entity.User{}
|
u := &entity.User{}
|
||||||
var dbID string
|
var dbID string
|
||||||
<<<<<<< HEAD
|
|
||||||
var skills, experience, education []byte // temp for Scanning
|
|
||||||
|
|
||||||
err := row.Scan(
|
|
||||||
&dbID, &u.TenantID, &u.Name, &u.Email, &u.PasswordHash, &u.Status, &u.CreatedAt, &u.UpdatedAt, &u.AvatarUrl,
|
|
||||||
&u.Bio, &u.ProfilePictureURL, &skills, &experience, &education,
|
|
||||||
=======
|
|
||||||
var phone sql.NullString
|
var phone sql.NullString
|
||||||
var bio sql.NullString
|
var bio sql.NullString
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
|
|
@ -160,7 +139,6 @@ func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*entity
|
||||||
pq.Array(&u.Skills),
|
pq.Array(&u.Skills),
|
||||||
&u.Objective,
|
&u.Objective,
|
||||||
&u.Title,
|
&u.Title,
|
||||||
>>>>>>> dev
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
|
@ -169,53 +147,21 @@ func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*entity
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
u.ID = dbID
|
u.ID = dbID
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
// Unmarshal JSONB fields
|
|
||||||
if len(skills) > 0 {
|
|
||||||
_ = json.Unmarshal(skills, &u.Skills)
|
|
||||||
}
|
|
||||||
if len(experience) > 0 {
|
|
||||||
_ = json.Unmarshal(experience, &u.Experience)
|
|
||||||
}
|
|
||||||
if len(education) > 0 {
|
|
||||||
_ = json.Unmarshal(education, &u.Education)
|
|
||||||
}
|
|
||||||
|
|
||||||
=======
|
|
||||||
u.Phone = nullStringPtr(phone)
|
u.Phone = nullStringPtr(phone)
|
||||||
u.Bio = nullStringPtr(bio)
|
u.Bio = nullStringPtr(bio)
|
||||||
>>>>>>> dev
|
|
||||||
u.Roles, _ = r.getRoles(ctx, dbID)
|
u.Roles, _ = r.getRoles(ctx, dbID)
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *UserRepository) FindByID(ctx context.Context, id string) (*entity.User, error) {
|
func (r *UserRepository) FindByID(ctx context.Context, id string) (*entity.User, error) {
|
||||||
<<<<<<< HEAD
|
|
||||||
query := `
|
|
||||||
SELECT
|
|
||||||
id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
|
||||||
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
|
||||||
bio, profile_picture_url, skills, experience, education
|
|
||||||
FROM users WHERE id = $1
|
|
||||||
`
|
|
||||||
=======
|
|
||||||
query := `SELECT id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
query := `SELECT id, COALESCE(tenant_id::text, ''), COALESCE(name, full_name, ''),
|
||||||
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
COALESCE(email, identifier), password_hash, COALESCE(status, 'active'), created_at, updated_at, COALESCE(avatar_url, ''),
|
||||||
phone, bio, address, city, state, zip_code, birth_date, education, experience, skills, objective, title
|
phone, bio, address, city, state, zip_code, birth_date, education, experience, skills, objective, title
|
||||||
FROM users WHERE id = $1`
|
FROM users WHERE id = $1`
|
||||||
>>>>>>> dev
|
|
||||||
row := r.db.QueryRowContext(ctx, query, id)
|
row := r.db.QueryRowContext(ctx, query, id)
|
||||||
|
|
||||||
u := &entity.User{}
|
u := &entity.User{}
|
||||||
var dbID string
|
var dbID string
|
||||||
<<<<<<< HEAD
|
|
||||||
var skills, experience, education []byte // temp for Scanning
|
|
||||||
|
|
||||||
err := row.Scan(
|
|
||||||
&dbID, &u.TenantID, &u.Name, &u.Email, &u.PasswordHash, &u.Status, &u.CreatedAt, &u.UpdatedAt, &u.AvatarUrl,
|
|
||||||
&u.Bio, &u.ProfilePictureURL, &skills, &experience, &education,
|
|
||||||
=======
|
|
||||||
var phone sql.NullString
|
var phone sql.NullString
|
||||||
var bio sql.NullString
|
var bio sql.NullString
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
|
|
@ -240,29 +186,13 @@ func (r *UserRepository) FindByID(ctx context.Context, id string) (*entity.User,
|
||||||
pq.Array(&u.Skills),
|
pq.Array(&u.Skills),
|
||||||
&u.Objective,
|
&u.Objective,
|
||||||
&u.Title,
|
&u.Title,
|
||||||
>>>>>>> dev
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
u.ID = dbID
|
u.ID = dbID
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
// Unmarshal JSONB fields
|
|
||||||
if len(skills) > 0 {
|
|
||||||
_ = json.Unmarshal(skills, &u.Skills)
|
|
||||||
}
|
|
||||||
if len(experience) > 0 {
|
|
||||||
_ = json.Unmarshal(experience, &u.Experience)
|
|
||||||
}
|
|
||||||
if len(education) > 0 {
|
|
||||||
_ = json.Unmarshal(education, &u.Education)
|
|
||||||
}
|
|
||||||
|
|
||||||
=======
|
|
||||||
u.Phone = nullStringPtr(phone)
|
u.Phone = nullStringPtr(phone)
|
||||||
u.Bio = nullStringPtr(bio)
|
u.Bio = nullStringPtr(bio)
|
||||||
>>>>>>> dev
|
|
||||||
u.Roles, _ = r.getRoles(ctx, dbID)
|
u.Roles, _ = r.getRoles(ctx, dbID)
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
@ -336,9 +266,6 @@ func (r *UserRepository) Update(ctx context.Context, user *entity.User) (*entity
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
// 1. Update basic fields + legacy role column + Profile fields
|
|
||||||
// We use the first role as the "legacy" role for compatibility
|
|
||||||
// Prepare pq Array for skills
|
|
||||||
// 1. Update basic fields + legacy role column
|
// 1. Update basic fields + legacy role column
|
||||||
// We use the first role as the "legacy" role for compatibility
|
// We use the first role as the "legacy" role for compatibility
|
||||||
primaryRole := ""
|
primaryRole := ""
|
||||||
|
|
@ -346,21 +273,6 @@ func (r *UserRepository) Update(ctx context.Context, user *entity.User) (*entity
|
||||||
primaryRole = user.Roles[0].Name
|
primaryRole = user.Roles[0].Name
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
skillsJSON, _ := json.Marshal(user.Skills)
|
|
||||||
experienceJSON, _ := json.Marshal(user.Experience)
|
|
||||||
educationJSON, _ := json.Marshal(user.Education)
|
|
||||||
|
|
||||||
query := `
|
|
||||||
UPDATE users
|
|
||||||
SET name=$1, email=$2, status=$3, role=$4, updated_at=$5, avatar_url=$6,
|
|
||||||
bio=$7, profile_picture_url=$8, skills=$9, experience=$10, education=$11
|
|
||||||
WHERE id=$12
|
|
||||||
`
|
|
||||||
_, err = tx.ExecContext(ctx, query,
|
|
||||||
user.Name, user.Email, user.Status, primaryRole, user.UpdatedAt, user.AvatarUrl,
|
|
||||||
user.Bio, user.ProfilePictureURL, skillsJSON, experienceJSON, educationJSON,
|
|
||||||
=======
|
|
||||||
query := `
|
query := `
|
||||||
UPDATE users
|
UPDATE users
|
||||||
SET name=$1, full_name=$2, email=$3, status=$4, role=$5, updated_at=$6, avatar_url=$7,
|
SET name=$1, full_name=$2, email=$3, status=$4, role=$5, updated_at=$6, avatar_url=$7,
|
||||||
|
|
@ -392,7 +304,6 @@ func (r *UserRepository) Update(ctx context.Context, user *entity.User) (*entity
|
||||||
pq.Array(user.Skills),
|
pq.Array(user.Skills),
|
||||||
user.Objective,
|
user.Objective,
|
||||||
user.Title,
|
user.Title,
|
||||||
>>>>>>> dev
|
|
||||||
user.ID,
|
user.ID,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ func NewRouter() http.Handler {
|
||||||
|
|
||||||
// --- CORE ARCHITECTURE INITIALIZATION ---
|
// --- CORE ARCHITECTURE INITIALIZATION ---
|
||||||
// Infrastructure
|
// Infrastructure
|
||||||
// Infrastructure
|
|
||||||
userRepo := postgres.NewUserRepository(database.DB)
|
userRepo := postgres.NewUserRepository(database.DB)
|
||||||
companyRepo := postgres.NewCompanyRepository(database.DB)
|
companyRepo := postgres.NewCompanyRepository(database.DB)
|
||||||
locationRepo := postgres.NewLocationRepository(database.DB)
|
locationRepo := postgres.NewLocationRepository(database.DB)
|
||||||
|
|
@ -78,14 +77,11 @@ func NewRouter() http.Handler {
|
||||||
listUsersUC := userUC.NewListUsersUseCase(userRepo)
|
listUsersUC := userUC.NewListUsersUseCase(userRepo)
|
||||||
deleteUserUC := userUC.NewDeleteUserUseCase(userRepo)
|
deleteUserUC := userUC.NewDeleteUserUseCase(userRepo)
|
||||||
updateUserUC := userUC.NewUpdateUserUseCase(userRepo)
|
updateUserUC := userUC.NewUpdateUserUseCase(userRepo)
|
||||||
<<<<<<< HEAD
|
updatePasswordUC := userUC.NewUpdatePasswordUseCase(userRepo, authService)
|
||||||
forgotPasswordUC := authUC.NewForgotPasswordUseCase(userRepo, tokenRepo, emailService, frontendURL)
|
forgotPasswordUC := authUC.NewForgotPasswordUseCase(userRepo, tokenRepo, emailService, frontendURL)
|
||||||
resetPasswordUC := authUC.NewResetPasswordUseCase(userRepo, tokenRepo, authService)
|
resetPasswordUC := authUC.NewResetPasswordUseCase(userRepo, tokenRepo, authService)
|
||||||
|
|
||||||
// Admin Logic Services
|
// Admin Logic Services
|
||||||
=======
|
|
||||||
updatePasswordUC := userUC.NewUpdatePasswordUseCase(userRepo, authService)
|
|
||||||
>>>>>>> dev
|
|
||||||
auditService := services.NewAuditService(database.DB)
|
auditService := services.NewAuditService(database.DB)
|
||||||
notificationService := services.NewNotificationService(database.DB, fcmService)
|
notificationService := services.NewNotificationService(database.DB, fcmService)
|
||||||
ticketService := services.NewTicketService(database.DB)
|
ticketService := services.NewTicketService(database.DB)
|
||||||
|
|
@ -145,7 +141,7 @@ func NewRouter() http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
"message": "🐴 GoHorseJobs API is running!",
|
"message": "GoHorseJobs API is running!",
|
||||||
"docs": "/docs",
|
"docs": "/docs",
|
||||||
"health": "/health",
|
"health": "/health",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|
@ -160,12 +156,9 @@ func NewRouter() http.Handler {
|
||||||
// --- CORE ROUTES ---
|
// --- CORE ROUTES ---
|
||||||
// Public
|
// Public
|
||||||
mux.HandleFunc("POST /api/v1/auth/login", coreHandlers.Login)
|
mux.HandleFunc("POST /api/v1/auth/login", coreHandlers.Login)
|
||||||
<<<<<<< HEAD
|
mux.HandleFunc("POST /api/v1/auth/logout", coreHandlers.Logout)
|
||||||
mux.HandleFunc("POST /api/v1/auth/forgot-password", coreHandlers.ForgotPassword)
|
mux.HandleFunc("POST /api/v1/auth/forgot-password", coreHandlers.ForgotPassword)
|
||||||
mux.HandleFunc("POST /api/v1/auth/reset-password", coreHandlers.ResetPassword)
|
mux.HandleFunc("POST /api/v1/auth/reset-password", coreHandlers.ResetPassword)
|
||||||
=======
|
|
||||||
mux.HandleFunc("POST /api/v1/auth/logout", coreHandlers.Logout)
|
|
||||||
>>>>>>> dev
|
|
||||||
mux.HandleFunc("POST /api/v1/auth/register", coreHandlers.RegisterCandidate)
|
mux.HandleFunc("POST /api/v1/auth/register", coreHandlers.RegisterCandidate)
|
||||||
mux.HandleFunc("POST /api/v1/auth/register/candidate", coreHandlers.RegisterCandidate)
|
mux.HandleFunc("POST /api/v1/auth/register/candidate", coreHandlers.RegisterCandidate)
|
||||||
mux.HandleFunc("POST /api/v1/auth/register/company", coreHandlers.CreateCompany)
|
mux.HandleFunc("POST /api/v1/auth/register/company", coreHandlers.CreateCompany)
|
||||||
|
|
@ -201,24 +194,11 @@ func NewRouter() http.Handler {
|
||||||
mux.Handle("PATCH /api/v1/users/me/profile", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.UpdateMyProfile)))
|
mux.Handle("PATCH /api/v1/users/me/profile", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.UpdateMyProfile)))
|
||||||
mux.Handle("PATCH /api/v1/users/me/password", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.UpdateMyPassword)))
|
mux.Handle("PATCH /api/v1/users/me/password", authMiddleware.HeaderAuthGuard(http.HandlerFunc(coreHandlers.UpdateMyPassword)))
|
||||||
|
|
||||||
// /api/v1/admin/companies -> Handled by coreHandlers.ListCompanies (Smart Branching)
|
|
||||||
// Needs to be wired with Optional Auth to support both Public and Admin.
|
|
||||||
// I will create OptionalHeaderAuthGuard in middleware next.
|
|
||||||
|
|
||||||
// Company Management
|
// Company Management
|
||||||
mux.Handle("PATCH /api/v1/companies/{id}/status", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.UpdateCompanyStatus))))
|
mux.Handle("PATCH /api/v1/companies/{id}/status", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.UpdateCompanyStatus))))
|
||||||
mux.Handle("PATCH /api/v1/companies/{id}", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.UpdateCompany))))
|
mux.Handle("PATCH /api/v1/companies/{id}", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.UpdateCompany))))
|
||||||
mux.Handle("DELETE /api/v1/companies/{id}", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.DeleteCompany))))
|
mux.Handle("DELETE /api/v1/companies/{id}", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.DeleteCompany))))
|
||||||
|
|
||||||
// /api/v1/admin/jobs -> /api/v1/jobs?mode=admin (Need Smart Handler) or just separate path /api/v1/jobs/management?
|
|
||||||
// User said "remove admin from ALL routes".
|
|
||||||
// Maybe /api/v1/management/jobs?
|
|
||||||
// Or just /api/v1/jobs (guarded)?
|
|
||||||
// JobHandler.GetJobs is Public.
|
|
||||||
// I will leave /api/v1/admin/jobs mapped to `GET /api/v1/jobs` for now (Collision).
|
|
||||||
// OK, I will map it to `GET /api/v1/jobs/moderation` for clearer distinction without "admin" prefix?
|
|
||||||
// Or simply `GET /api/v1/jobs` handle it?
|
|
||||||
// Given safe constraints, `GET /api/v1/jobs/moderation` is safer than breaking public `GET /api/v1/jobs`.
|
|
||||||
mux.Handle("GET /api/v1/jobs/moderation", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.ListJobs))))
|
mux.Handle("GET /api/v1/jobs/moderation", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.ListJobs))))
|
||||||
|
|
||||||
// /api/v1/admin/jobs/{id}/status
|
// /api/v1/admin/jobs/{id}/status
|
||||||
|
|
@ -275,12 +255,7 @@ func NewRouter() http.Handler {
|
||||||
mux.Handle("POST /api/v1/system/cloudflare/purge", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.PurgeCache))))
|
mux.Handle("POST /api/v1/system/cloudflare/purge", authMiddleware.HeaderAuthGuard(adminOnly(http.HandlerFunc(adminHandlers.PurgeCache))))
|
||||||
|
|
||||||
// Seeder Routes (Dev Only)
|
// Seeder Routes (Dev Only)
|
||||||
// Guarded by Admin Roles, or you could make it Dev only via env check
|
mux.HandleFunc("GET /api/v1/seeder/seed/stream", seederHandlers.HandleSeedStream)
|
||||||
mux.HandleFunc("GET /api/v1/seeder/seed/stream", seederHandlers.HandleSeedStream) // Has its own auth or unrestricted for dev? Better unrestricted for simplicity in dev if safe.
|
|
||||||
// Actually, let's keep it open for now or simple admin guard if user is logged in.
|
|
||||||
// The frontend uses EventSource which sends cookies but not custom headers easily without polyfill.
|
|
||||||
// We'll leave it public for the requested "Dev" purpose, or rely on internal network.
|
|
||||||
// If needed, we can add query param token.
|
|
||||||
mux.HandleFunc("POST /api/v1/seeder/reset", seederHandlers.HandleReset)
|
mux.HandleFunc("POST /api/v1/seeder/reset", seederHandlers.HandleReset)
|
||||||
|
|
||||||
// Email Templates & Settings (Admin Only)
|
// Email Templates & Settings (Admin Only)
|
||||||
|
|
@ -309,14 +284,9 @@ func NewRouter() http.Handler {
|
||||||
mux.HandleFunc("POST /api/v1/subscription/checkout", subHandler.CreateCheckoutSession)
|
mux.HandleFunc("POST /api/v1/subscription/checkout", subHandler.CreateCheckoutSession)
|
||||||
mux.HandleFunc("POST /api/v1/subscription/webhook", subHandler.HandleWebhook)
|
mux.HandleFunc("POST /api/v1/subscription/webhook", subHandler.HandleWebhook)
|
||||||
|
|
||||||
// Application Routes
|
// Application Routes (merged: both OptionalAuth for create + both /me endpoints)
|
||||||
<<<<<<< HEAD
|
|
||||||
mux.HandleFunc("POST /api/v1/applications", applicationHandler.CreateApplication)
|
|
||||||
mux.Handle("GET /api/v1/applications/me", authMiddleware.HeaderAuthGuard(http.HandlerFunc(applicationHandler.ListUserApplications))) // New endpoint
|
|
||||||
=======
|
|
||||||
mux.Handle("POST /api/v1/applications", authMiddleware.OptionalHeaderAuthGuard(http.HandlerFunc(applicationHandler.CreateApplication)))
|
mux.Handle("POST /api/v1/applications", authMiddleware.OptionalHeaderAuthGuard(http.HandlerFunc(applicationHandler.CreateApplication)))
|
||||||
mux.Handle("GET /api/v1/applications/me", authMiddleware.HeaderAuthGuard(http.HandlerFunc(applicationHandler.GetMyApplications)))
|
mux.Handle("GET /api/v1/applications/me", authMiddleware.HeaderAuthGuard(http.HandlerFunc(applicationHandler.GetMyApplications)))
|
||||||
>>>>>>> dev
|
|
||||||
mux.HandleFunc("GET /api/v1/applications", applicationHandler.GetApplications)
|
mux.HandleFunc("GET /api/v1/applications", applicationHandler.GetApplications)
|
||||||
mux.HandleFunc("GET /api/v1/applications/{id}", applicationHandler.GetApplicationByID)
|
mux.HandleFunc("GET /api/v1/applications/{id}", applicationHandler.GetApplicationByID)
|
||||||
mux.HandleFunc("PUT /api/v1/applications/{id}/status", applicationHandler.UpdateApplicationStatus)
|
mux.HandleFunc("PUT /api/v1/applications/{id}/status", applicationHandler.UpdateApplicationStatus)
|
||||||
|
|
@ -331,12 +301,10 @@ func NewRouter() http.Handler {
|
||||||
|
|
||||||
// --- TICKET ROUTES ---
|
// --- TICKET ROUTES ---
|
||||||
ticketHandler := handlers.NewTicketHandler(ticketService)
|
ticketHandler := handlers.NewTicketHandler(ticketService)
|
||||||
// mux.HandleFunc("GET /api/v1/tickets/stats", ticketHandler.GetTicketStats) // Removed in hml
|
|
||||||
mux.HandleFunc("GET /api/v1/tickets", ticketHandler.GetTickets)
|
mux.HandleFunc("GET /api/v1/tickets", ticketHandler.GetTickets)
|
||||||
mux.HandleFunc("POST /api/v1/tickets", ticketHandler.CreateTicket)
|
mux.HandleFunc("POST /api/v1/tickets", ticketHandler.CreateTicket)
|
||||||
mux.HandleFunc("GET /api/v1/tickets/{id}", ticketHandler.GetTicketByID)
|
mux.HandleFunc("GET /api/v1/tickets/{id}", ticketHandler.GetTicketByID)
|
||||||
mux.HandleFunc("PUT /api/v1/tickets/{id}", ticketHandler.UpdateTicket)
|
mux.HandleFunc("PUT /api/v1/tickets/{id}", ticketHandler.UpdateTicket)
|
||||||
// mux.HandleFunc("GET /api/v1/tickets/{id}/messages", ticketHandler.GetTicketMessages) // Merged into GetByID
|
|
||||||
mux.HandleFunc("POST /api/v1/tickets/{id}/messages", ticketHandler.AddTicketMessage)
|
mux.HandleFunc("POST /api/v1/tickets/{id}/messages", ticketHandler.AddTicketMessage)
|
||||||
|
|
||||||
// --- ACTIVITY LOG ROUTES ---
|
// --- ACTIVITY LOG ROUTES ---
|
||||||
|
|
@ -347,13 +315,9 @@ func NewRouter() http.Handler {
|
||||||
|
|
||||||
// --- NOTIFICATION ROUTES ---
|
// --- NOTIFICATION ROUTES ---
|
||||||
notificationHandler := handlers.NewNotificationHandler(notificationService)
|
notificationHandler := handlers.NewNotificationHandler(notificationService)
|
||||||
mux.Handle("GET /api/v1/notifications", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.GetNotifications)))
|
|
||||||
// mux.Handle("GET /api/v1/notifications/unread-count", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.GetUnreadCount))) // Removed in hml
|
|
||||||
mux.Handle("PUT /api/v1/notifications/read-all", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAllAsRead)))
|
mux.Handle("PUT /api/v1/notifications/read-all", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAllAsRead)))
|
||||||
mux.Handle("PUT /api/v1/notifications/{id}/read", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAsRead)))
|
mux.Handle("PUT /api/v1/notifications/{id}/read", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAsRead)))
|
||||||
// mux.Handle("DELETE /api/v1/notifications/{id}", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.DeleteNotification))) // Removed in hml
|
|
||||||
mux.Handle("POST /api/v1/notifications/fcm-token", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.RegisterFCMToken)))
|
mux.Handle("POST /api/v1/notifications/fcm-token", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.RegisterFCMToken)))
|
||||||
// mux.Handle("DELETE /api/v1/notifications/fcm-token", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.UnregisterFCMToken))) // Removed in hml
|
|
||||||
|
|
||||||
// Swagger Route - available at /docs
|
// Swagger Route - available at /docs
|
||||||
mux.HandleFunc("/docs/", httpSwagger.WrapHandler)
|
mux.HandleFunc("/docs/", httpSwagger.WrapHandler)
|
||||||
|
|
|
||||||
|
|
@ -76,49 +76,31 @@ func (s *JobService) CreateJob(req dto.CreateJobRequest, createdBy string) (*mod
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany, int, error) {
|
func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany, int, error) {
|
||||||
// Merged Query: Includes hml fields + key HEAD logic
|
// Merged Query: Includes both HEAD and dev fields
|
||||||
baseQuery := `
|
baseQuery := `
|
||||||
<<<<<<< HEAD
|
|
||||||
SELECT
|
SELECT
|
||||||
j.id, j.company_id, j.title, j.description, j.salary_min, j.salary_max, j.salary_type,
|
j.id, j.company_id, j.title, j.description, j.salary_min, j.salary_max, j.salary_type,
|
||||||
j.employment_type, j.work_mode, j.working_hours, j.location, j.status, j.salary_negotiable, j.is_featured, j.created_at, j.updated_at,
|
j.employment_type, j.work_mode, j.working_hours, j.location, j.status, j.salary_negotiable, j.is_featured, j.created_at, j.updated_at,
|
||||||
COALESCE(c.name, '') as company_name, c.logo_url as company_logo_url,
|
CASE
|
||||||
|
WHEN c.type = 'CANDIDATE_WORKSPACE' OR c.name LIKE 'Candidate - %' THEN ''
|
||||||
|
ELSE COALESCE(c.name, '')
|
||||||
|
END as company_name, c.logo_url as company_logo_url,
|
||||||
r.name as region_name, ci.name as city_name,
|
r.name as region_name, ci.name as city_name,
|
||||||
j.view_count, j.featured_until
|
j.view_count, j.featured_until,
|
||||||
|
(SELECT COUNT(*) FROM applications a WHERE a.job_id = j.id) as applications_count
|
||||||
FROM jobs j
|
FROM jobs j
|
||||||
LEFT JOIN companies c ON j.company_id::text = c.id::text
|
LEFT JOIN companies c ON j.company_id::text = c.id::text
|
||||||
LEFT JOIN states r ON j.region_id::text = r.id::text
|
LEFT JOIN states r ON j.region_id::text = r.id::text
|
||||||
LEFT JOIN cities ci ON j.city_id::text = ci.id::text
|
LEFT JOIN cities ci ON j.city_id::text = ci.id::text
|
||||||
WHERE 1=1`
|
WHERE 1=1`
|
||||||
|
|
||||||
=======
|
|
||||||
SELECT
|
|
||||||
j.id, j.company_id, j.title, j.description, j.salary_min, j.salary_max, j.salary_type,
|
|
||||||
j.employment_type, j.work_mode, j.working_hours, j.location, j.status, j.salary_negotiable, j.is_featured, j.created_at, j.updated_at,
|
|
||||||
CASE
|
|
||||||
WHEN c.type = 'CANDIDATE_WORKSPACE' OR c.name LIKE 'Candidate - %' THEN ''
|
|
||||||
ELSE COALESCE(c.name, '')
|
|
||||||
END as company_name, c.logo_url as company_logo_url,
|
|
||||||
r.name as region_name, ci.name as city_name,
|
|
||||||
(SELECT COUNT(*) FROM applications a WHERE a.job_id = j.id) as applications_count
|
|
||||||
FROM jobs j
|
|
||||||
LEFT JOIN companies c ON j.company_id::text = c.id::text
|
|
||||||
LEFT JOIN states r ON j.region_id::text = r.id::text
|
|
||||||
LEFT JOIN cities ci ON j.city_id::text = ci.id::text
|
|
||||||
WHERE 1=1`
|
|
||||||
>>>>>>> dev
|
|
||||||
countQuery := `SELECT COUNT(*) FROM jobs j WHERE 1=1`
|
countQuery := `SELECT COUNT(*) FROM jobs j WHERE 1=1`
|
||||||
|
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
argId := 1
|
argId := 1
|
||||||
|
|
||||||
// Search (merged logic)
|
// Search (merged logic)
|
||||||
// Supports full text search if available, or ILIKE fallback.
|
|
||||||
// Using generic ILIKE for broad compatibility as hml did, but incorporating HEAD's concept.
|
|
||||||
if filter.Search != nil && *filter.Search != "" {
|
if filter.Search != nil && *filter.Search != "" {
|
||||||
searchTerm := fmt.Sprintf("%%%s%%", *filter.Search)
|
searchTerm := fmt.Sprintf("%%%s%%", *filter.Search)
|
||||||
// HEAD had tsvector. If DB supports it great. But to avoid "function not found" if extension missing, safe bet is ILIKE.
|
|
||||||
// hml used ILIKE.
|
|
||||||
clause := fmt.Sprintf(" AND (j.title ILIKE $%d OR j.description ILIKE $%d OR c.name ILIKE $%d)", argId, argId, argId)
|
clause := fmt.Sprintf(" AND (j.title ILIKE $%d OR j.description ILIKE $%d OR c.name ILIKE $%d)", argId, argId, argId)
|
||||||
baseQuery += clause
|
baseQuery += clause
|
||||||
countQuery += clause
|
countQuery += clause
|
||||||
|
|
@ -174,7 +156,7 @@ func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany
|
||||||
args = append(args, locTerm)
|
args = append(args, locTerm)
|
||||||
argId++
|
argId++
|
||||||
}
|
}
|
||||||
// Support HEAD's LocationSearch explicitly if different (mapped to same in requests.go but just in case)
|
// Support HEAD's LocationSearch explicitly if different
|
||||||
if filter.LocationSearch != nil && *filter.LocationSearch != "" && (filter.Location == nil || *filter.Location != *filter.LocationSearch) {
|
if filter.LocationSearch != nil && *filter.LocationSearch != "" && (filter.Location == nil || *filter.Location != *filter.LocationSearch) {
|
||||||
locTerm := fmt.Sprintf("%%%s%%", *filter.LocationSearch)
|
locTerm := fmt.Sprintf("%%%s%%", *filter.LocationSearch)
|
||||||
baseQuery += fmt.Sprintf(" AND j.location ILIKE $%d", argId)
|
baseQuery += fmt.Sprintf(" AND j.location ILIKE $%d", argId)
|
||||||
|
|
@ -254,7 +236,6 @@ func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany
|
||||||
case "salary_desc":
|
case "salary_desc":
|
||||||
sortClause = " ORDER BY j.salary_max DESC NULLS LAST"
|
sortClause = " ORDER BY j.salary_max DESC NULLS LAST"
|
||||||
case "relevance":
|
case "relevance":
|
||||||
// Simple relevance if no fulltext rank
|
|
||||||
sortClause = " ORDER BY j.is_featured DESC, j.created_at DESC"
|
sortClause = " ORDER BY j.is_featured DESC, j.created_at DESC"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -262,10 +243,7 @@ func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany
|
||||||
// Override sort order if explicit
|
// Override sort order if explicit
|
||||||
if filter.SortOrder != nil {
|
if filter.SortOrder != nil {
|
||||||
if *filter.SortOrder == "asc" {
|
if *filter.SortOrder == "asc" {
|
||||||
// Naive replace/append. hml logic didn't support generic SortOrder param well (it embedded in SortBy).
|
// Rely on SortBy providing correct default or direction.
|
||||||
// If SortBy was one of the above, we might just append ASC?
|
|
||||||
// But for now, rely on SortBy providing correct default or direction.
|
|
||||||
// HEAD relied on SortOrder.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,12 +277,8 @@ func (s *JobService) GetJobs(filter dto.JobFilterQuery) ([]models.JobWithCompany
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&j.ID, &j.CompanyID, &j.Title, &j.Description, &j.SalaryMin, &j.SalaryMax, &j.SalaryType,
|
&j.ID, &j.CompanyID, &j.Title, &j.Description, &j.SalaryMin, &j.SalaryMax, &j.SalaryType,
|
||||||
&j.EmploymentType, &j.WorkMode, &j.WorkingHours, &j.Location, &j.Status, &j.SalaryNegotiable, &j.IsFeatured, &j.CreatedAt, &j.UpdatedAt,
|
&j.EmploymentType, &j.WorkMode, &j.WorkingHours, &j.Location, &j.Status, &j.SalaryNegotiable, &j.IsFeatured, &j.CreatedAt, &j.UpdatedAt,
|
||||||
<<<<<<< HEAD
|
|
||||||
&j.CompanyName, &j.CompanyLogoURL, &j.RegionName, &j.CityName,
|
&j.CompanyName, &j.CompanyLogoURL, &j.RegionName, &j.CityName,
|
||||||
&j.ViewCount, &j.FeaturedUntil,
|
&j.ViewCount, &j.FeaturedUntil, &j.ApplicationsCount,
|
||||||
=======
|
|
||||||
&j.CompanyName, &j.CompanyLogoURL, &j.RegionName, &j.CityName, &j.ApplicationsCount,
|
|
||||||
>>>>>>> dev
|
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
@ -329,17 +303,11 @@ func (s *JobService) GetJobByID(id string) (*models.Job, error) {
|
||||||
salary_negotiable, currency, work_mode
|
salary_negotiable, currency, work_mode
|
||||||
FROM jobs WHERE id = $1
|
FROM jobs WHERE id = $1
|
||||||
`
|
`
|
||||||
// Added extra fields to SELECT to cover both models
|
|
||||||
err := s.DB.QueryRow(query, id).Scan(
|
err := s.DB.QueryRow(query, id).Scan(
|
||||||
&j.ID, &j.CompanyID, &j.Title, &j.Description, &j.SalaryMin, &j.SalaryMax, &j.SalaryType,
|
&j.ID, &j.CompanyID, &j.Title, &j.Description, &j.SalaryMin, &j.SalaryMax, &j.SalaryType,
|
||||||
<<<<<<< HEAD
|
|
||||||
&j.EmploymentType, &j.WorkingHours, &j.Location, &j.RegionID, &j.CityID,
|
&j.EmploymentType, &j.WorkingHours, &j.Location, &j.RegionID, &j.CityID,
|
||||||
&j.Requirements, &j.Benefits, &j.VisaSupport, &j.LanguageLevel, &j.Status, &j.IsFeatured, &j.FeaturedUntil, &j.ViewCount, &j.CreatedAt, &j.UpdatedAt,
|
&j.Requirements, &j.Benefits, &j.VisaSupport, &j.LanguageLevel, &j.Status, &j.IsFeatured, &j.FeaturedUntil, &j.ViewCount, &j.CreatedAt, &j.UpdatedAt,
|
||||||
&j.SalaryNegotiable, &j.Currency, &j.WorkMode,
|
&j.SalaryNegotiable, &j.Currency, &j.WorkMode,
|
||||||
=======
|
|
||||||
&j.EmploymentType, &j.WorkingHours, &j.Location, &j.RegionID, &j.CityID, &j.SalaryNegotiable,
|
|
||||||
&j.Requirements, &j.Benefits, &j.VisaSupport, &j.LanguageLevel, &j.Status, &j.CreatedAt, &j.UpdatedAt,
|
|
||||||
>>>>>>> dev
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -362,8 +330,6 @@ func (s *JobService) UpdateJob(id string, req dto.UpdateJobRequest) (*models.Job
|
||||||
args = append(args, *req.Description)
|
args = append(args, *req.Description)
|
||||||
argId++
|
argId++
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
if req.SalaryMin != nil {
|
if req.SalaryMin != nil {
|
||||||
setClauses = append(setClauses, fmt.Sprintf("salary_min = $%d", argId))
|
setClauses = append(setClauses, fmt.Sprintf("salary_min = $%d", argId))
|
||||||
args = append(args, *req.SalaryMin)
|
args = append(args, *req.SalaryMin)
|
||||||
|
|
@ -434,7 +400,6 @@ func (s *JobService) UpdateJob(id string, req dto.UpdateJobRequest) (*models.Job
|
||||||
args = append(args, *req.LanguageLevel)
|
args = append(args, *req.LanguageLevel)
|
||||||
argId++
|
argId++
|
||||||
}
|
}
|
||||||
>>>>>>> dev
|
|
||||||
if req.Status != nil {
|
if req.Status != nil {
|
||||||
setClauses = append(setClauses, fmt.Sprintf("status = $%d", argId))
|
setClauses = append(setClauses, fmt.Sprintf("status = $%d", argId))
|
||||||
args = append(args, *req.Status)
|
args = append(args, *req.Status)
|
||||||
|
|
@ -447,13 +412,10 @@ func (s *JobService) UpdateJob(id string, req dto.UpdateJobRequest) (*models.Job
|
||||||
}
|
}
|
||||||
if req.FeaturedUntil != nil {
|
if req.FeaturedUntil != nil {
|
||||||
setClauses = append(setClauses, fmt.Sprintf("featured_until = $%d", argId))
|
setClauses = append(setClauses, fmt.Sprintf("featured_until = $%d", argId))
|
||||||
// HEAD had string parsing. hml didn't show parsing logic but request field might be string.
|
|
||||||
// Assuming ISO8601 string from DTO.
|
|
||||||
parsedTime, err := time.Parse(time.RFC3339, *req.FeaturedUntil)
|
parsedTime, err := time.Parse(time.RFC3339, *req.FeaturedUntil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
args = append(args, parsedTime)
|
args = append(args, parsedTime)
|
||||||
} else {
|
} else {
|
||||||
// Fallback or error? For now fallback null or skip
|
|
||||||
args = append(args, nil)
|
args = append(args, nil)
|
||||||
}
|
}
|
||||||
argId++
|
argId++
|
||||||
|
|
@ -463,11 +425,6 @@ func (s *JobService) UpdateJob(id string, req dto.UpdateJobRequest) (*models.Job
|
||||||
args = append(args, *req.SalaryNegotiable)
|
args = append(args, *req.SalaryNegotiable)
|
||||||
argId++
|
argId++
|
||||||
}
|
}
|
||||||
if req.Currency != nil {
|
|
||||||
setClauses = append(setClauses, fmt.Sprintf("currency = $%d", argId))
|
|
||||||
args = append(args, *req.Currency)
|
|
||||||
argId++
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(setClauses) == 0 {
|
if len(setClauses) == 0 {
|
||||||
return s.GetJobByID(id)
|
return s.GetJobByID(id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue