Yimaru-BackEnd/internal/services/course_management/service.go

215 lines
7.2 KiB
Go

package course_management
import (
"context"
"Yimaru-Backend/internal/config"
"Yimaru-Backend/internal/domain"
"Yimaru-Backend/internal/ports"
notificationservice "Yimaru-Backend/internal/services/notification"
)
type Service struct {
userStore ports.UserStore
courseStore ports.CourseStore
notificationSvc *notificationservice.Service
// messengerSvc *messenger.Service
config *config.Config
}
func NewService(
userStore ports.UserStore,
courseStore ports.CourseStore,
notificationSvc *notificationservice.Service,
// messengerSvc *messenger.Service,
cfg *config.Config,
) *Service {
return &Service{
userStore: userStore,
courseStore: courseStore,
notificationSvc: notificationSvc,
// messengerSvc: messengerSvc,
config: cfg,
}
}
// Course category methods
func (s *Service) CreateCourseCategory(ctx context.Context, name string) (domain.CourseCategory, error) {
return s.courseStore.CreateCourseCategory(ctx, name)
}
func (s *Service) GetCourseCategoryByID(ctx context.Context, id int64) (domain.CourseCategory, error) {
return s.courseStore.GetCourseCategoryByID(ctx, id)
}
func (s *Service) ListActiveCourseCategories(ctx context.Context) ([]domain.CourseCategory, error) {
return s.courseStore.ListActiveCourseCategories(ctx)
}
func (s *Service) UpdateCourseCategory(ctx context.Context, id int64, name string, isActive bool) (domain.CourseCategory, error) {
return s.courseStore.UpdateCourseCategory(ctx, id, name, isActive)
}
func (s *Service) DeactivateCourseCategory(ctx context.Context, id int64) error {
return s.courseStore.DeactivateCourseCategory(ctx, id)
}
// Courses
func (s *Service) CreateCourse(ctx context.Context, c domain.Course) (domain.Course, error) {
return s.courseStore.CreateCourse(ctx, c)
}
func (s *Service) GetCourseByID(ctx context.Context, id int64) (domain.Course, error) {
return s.courseStore.GetCourseByID(ctx, id)
}
func (s *Service) ListCoursesByCategory(ctx context.Context, categoryID int64) ([]domain.Course, error) {
return s.courseStore.ListCoursesByCategory(ctx, categoryID)
}
func (s *Service) ListActiveCourses(ctx context.Context) ([]domain.Course, error) {
return s.courseStore.ListActiveCourses(ctx)
}
func (s *Service) UpdateCourse(ctx context.Context, c domain.Course) (domain.Course, error) {
return s.courseStore.UpdateCourse(ctx, c)
}
func (s *Service) DeactivateCourse(ctx context.Context, id int64) error {
return s.courseStore.DeactivateCourse(ctx, id)
}
// Programs
func (s *Service) CreateProgram(ctx context.Context, p domain.Program) (domain.Program, error) {
return s.courseStore.CreateProgram(ctx, p)
}
func (s *Service) GetProgramByID(ctx context.Context, id int64) (domain.Program, error) {
return s.courseStore.GetProgramByID(ctx, id)
}
func (s *Service) ListProgramsByCourse(ctx context.Context, courseID int64) ([]domain.Program, error) {
return s.courseStore.ListProgramsByCourse(ctx, courseID)
}
func (s *Service) ListActivePrograms(ctx context.Context) ([]domain.Program, error) {
return s.courseStore.ListActivePrograms(ctx)
}
func (s *Service) UpdateProgram(ctx context.Context, p domain.Program) (domain.Program, error) {
return s.courseStore.UpdateProgram(ctx, p)
}
func (s *Service) DeactivateProgram(ctx context.Context, id int64) error {
return s.courseStore.DeactivateProgram(ctx, id)
}
// Modules
func (s *Service) CreateModule(ctx context.Context, m domain.Module) (domain.Module, error) {
return s.courseStore.CreateModule(ctx, m)
}
func (s *Service) GetModuleByID(ctx context.Context, id int64) (domain.Module, error) {
return s.courseStore.GetModuleByID(ctx, id)
}
func (s *Service) ListModulesByLevel(ctx context.Context, levelID int64) ([]domain.Module, error) {
return s.courseStore.ListModulesByLevel(ctx, levelID)
}
func (s *Service) UpdateModule(ctx context.Context, m domain.Module) (domain.Module, error) {
return s.courseStore.UpdateModule(ctx, m)
}
func (s *Service) DeactivateModule(ctx context.Context, id int64) error {
return s.courseStore.DeactivateModule(ctx, id)
}
// Module videos
func (s *Service) CreateModuleVideo(ctx context.Context, v domain.ModuleVideo) (domain.ModuleVideo, error) {
return s.courseStore.CreateModuleVideo(ctx, v)
}
func (s *Service) GetModuleVideoByID(ctx context.Context, id int64) (domain.ModuleVideo, error) {
return s.courseStore.GetModuleVideoByID(ctx, id)
}
func (s *Service) ListAllVideosByModule(ctx context.Context, moduleID int64) ([]domain.ModuleVideo, error) {
return s.courseStore.ListAllVideosByModule(ctx, moduleID)
}
func (s *Service) ListPublishedVideosByModule(ctx context.Context, moduleID int64) ([]domain.ModuleVideo, error) {
return s.courseStore.ListPublishedVideosByModule(ctx, moduleID)
}
func (s *Service) UpdateModuleVideo(ctx context.Context, v domain.ModuleVideo) (domain.ModuleVideo, error) {
return s.courseStore.UpdateModuleVideo(ctx, v)
}
func (s *Service) DeactivateModuleVideo(ctx context.Context, id int64) error {
return s.courseStore.DeactivateModuleVideo(ctx, id)
}
// Practices
func (s *Service) CreatePractice(ctx context.Context, p domain.Practice) (domain.Practice, error) {
return s.courseStore.CreatePractice(ctx, p)
}
func (s *Service) GetPracticeByID(ctx context.Context, id int64) (domain.Practice, error) {
return s.courseStore.GetPracticeByID(ctx, id)
}
func (s *Service) ListPracticesByOwner(ctx context.Context, ownerType string, ownerID int64) ([]domain.Practice, error) {
return s.courseStore.ListPracticesByOwner(ctx, ownerType, ownerID)
}
func (s *Service) UpdatePractice(ctx context.Context, p domain.Practice) (domain.Practice, error) {
return s.courseStore.UpdatePractice(ctx, p)
}
func (s *Service) DeactivatePractice(ctx context.Context, id int64) error {
return s.courseStore.DeactivatePractice(ctx, id)
}
// Practice questions
func (s *Service) CreatePracticeQuestion(ctx context.Context, qn domain.PracticeQuestion) (domain.PracticeQuestion, error) {
return s.courseStore.CreatePracticeQuestion(ctx, qn)
}
func (s *Service) GetPracticeQuestionByID(ctx context.Context, id int64) (domain.PracticeQuestion, error) {
return s.courseStore.GetPracticeQuestionByID(ctx, id)
}
func (s *Service) ListPracticeQuestions(ctx context.Context, practiceID int64) ([]domain.PracticeQuestion, error) {
return s.courseStore.ListPracticeQuestions(ctx, practiceID)
}
func (s *Service) UpdatePracticeQuestion(ctx context.Context, qn domain.PracticeQuestion) (domain.PracticeQuestion, error) {
return s.courseStore.UpdatePracticeQuestion(ctx, qn)
}
func (s *Service) DeletePracticeQuestion(ctx context.Context, id int64) error {
return s.courseStore.DeletePracticeQuestion(ctx, id)
}
// Levels
func (s *Service) CreateLevel(ctx context.Context, l domain.Level) (domain.Level, error) {
return s.courseStore.CreateLevel(ctx, l)
}
func (s *Service) GetLevelByID(ctx context.Context, id int64) (domain.Level, error) {
return s.courseStore.GetLevelByID(ctx, id)
}
func (s *Service) ListLevelsByProgram(ctx context.Context, programID int64) ([]domain.Level, error) {
return s.courseStore.ListLevelsByProgram(ctx, programID)
}
func (s *Service) UpdateLevel(ctx context.Context, l domain.Level) (domain.Level, error) {
return s.courseStore.UpdateLevel(ctx, l)
}
func (s *Service) DeactivateLevel(ctx context.Context, id int64) error {
return s.courseStore.DeactivateLevel(ctx, id)
}