All checks were successful
Build / build (push) Successful in 2m17s
Extract business logic from gRPC handlers into a dedicated service package. Add context support throughout for cancellation and timeouts. Move models to their own package, remove hardcoded credentials from config, and simplify parsers to only handle HTML parsing.
30 lines
688 B
Go
30 lines
688 B
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"log/slog"
|
|
|
|
pb "schedule_converter/proto/runner"
|
|
|
|
apperr "schedule_converter/pkg/errors"
|
|
)
|
|
|
|
func (h *TaskHandler) getExams(ctx context.Context, payload []byte) ([]byte, error) {
|
|
var req pb.GetExamsPayload
|
|
if err := unmarshalPayload(payload, &req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log := slog.With("username", req.Username, "semester", req.Semester)
|
|
log.Info("获取考试安排任务")
|
|
|
|
result, err := h.service.GetExams(ctx, &req)
|
|
if err != nil {
|
|
return nil, apperr.New("get_exams", err, "获取考试安排失败")
|
|
}
|
|
|
|
log.Info("考试安排获取成功", "exam_count", len(result.Exams))
|
|
return json.Marshal(result)
|
|
}
|