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
686 B
Go
30 lines
686 B
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"log/slog"
|
|
|
|
pb "schedule_converter/proto/runner"
|
|
|
|
apperr "schedule_converter/pkg/errors"
|
|
)
|
|
|
|
func (h *TaskHandler) getSchedule(ctx context.Context, payload []byte) ([]byte, error) {
|
|
var req pb.GetSchedulePayload
|
|
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.GetSchedule(ctx, &req)
|
|
if err != nil {
|
|
return nil, apperr.New("get_schedule", err, "获取课表失败")
|
|
}
|
|
|
|
log.Info("课表获取成功", "course_count", len(result.Courses))
|
|
return json.Marshal(result)
|
|
}
|