gohorsejobs/backend/internal/handlers/video_interview_handler.go
GoHorse Deploy ae475e41a9 feat: implement careerjet gap analysis improvements
- Video Interview system (backend + frontend)
- Date Posted filter (24h, 7d, 30d)
- Company filter in jobs listing
- Recent searches persistence (LocalStorage)
- Job Alerts with email confirmation
- Favorite jobs with API
- Company followers system
- Careerjet URL compatibility (s/l aliases)
2026-02-14 19:37:25 +00:00

149 lines
4.4 KiB
Go

package handlers
import (
"encoding/json"
"net/http"
"strings"
"github.com/rede5/gohorsejobs/backend/internal/api/middleware"
"github.com/rede5/gohorsejobs/backend/internal/dto"
"github.com/rede5/gohorsejobs/backend/internal/models"
)
type VideoInterviewServiceInterface interface {
CreateInterview(req dto.CreateVideoInterviewRequest, createdBy string) (*models.VideoInterview, error)
GetInterviewByID(id string) (*models.VideoInterview, error)
GetInterviewsByApplication(applicationID string) ([]models.VideoInterview, error)
GetInterviewsByCompany(companyID string) ([]models.VideoInterviewWithDetails, error)
UpdateInterview(id string, req dto.UpdateVideoInterviewRequest) (*models.VideoInterview, error)
SubmitFeedback(id string, req dto.VideoInterviewFeedbackRequest) (*models.VideoInterview, error)
DeleteInterview(id string) error
}
type VideoInterviewHandler struct {
Service VideoInterviewServiceInterface
}
func NewVideoInterviewHandler(service VideoInterviewServiceInterface) *VideoInterviewHandler {
return &VideoInterviewHandler{Service: service}
}
func (h *VideoInterviewHandler) CreateInterview(w http.ResponseWriter, r *http.Request) {
var req dto.CreateVideoInterviewRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
userID := ""
if uid, ok := r.Context().Value(middleware.ContextUserID).(string); ok {
userID = uid
}
interview, err := h.Service.CreateInterview(req, userID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(interview)
}
func (h *VideoInterviewHandler) GetInterview(w http.ResponseWriter, r *http.Request) {
id := strings.TrimPrefix(r.URL.Path, "/api/v1/interviews/")
interview, err := h.Service.GetInterviewByID(id)
if err != nil {
http.Error(w, "Interview not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(interview)
}
func (h *VideoInterviewHandler) GetInterviewsByApplication(w http.ResponseWriter, r *http.Request) {
applicationID := r.URL.Query().Get("applicationId")
if applicationID == "" {
http.Error(w, "applicationId is required", http.StatusBadRequest)
return
}
interviews, err := h.Service.GetInterviewsByApplication(applicationID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(interviews)
}
func (h *VideoInterviewHandler) GetCompanyInterviews(w http.ResponseWriter, r *http.Request) {
companyID := r.URL.Query().Get("companyId")
if companyID == "" {
http.Error(w, "companyId is required", http.StatusBadRequest)
return
}
interviews, err := h.Service.GetInterviewsByCompany(companyID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(interviews)
}
func (h *VideoInterviewHandler) UpdateInterview(w http.ResponseWriter, r *http.Request) {
id := strings.TrimPrefix(r.URL.Path, "/api/v1/interviews/")
var req dto.UpdateVideoInterviewRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
interview, err := h.Service.UpdateInterview(id, req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(interview)
}
func (h *VideoInterviewHandler) SubmitFeedback(w http.ResponseWriter, r *http.Request) {
id := strings.TrimPrefix(r.URL.Path, "/api/v1/interviews/")
var req dto.VideoInterviewFeedbackRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
interview, err := h.Service.SubmitFeedback(id, req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(interview)
}
func (h *VideoInterviewHandler) DeleteInterview(w http.ResponseWriter, r *http.Request) {
id := strings.TrimPrefix(r.URL.Path, "/api/v1/interviews/")
err := h.Service.DeleteInterview(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
}