Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion infrastructure/fiber/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (f *fiberServer) initUseCase() {
scoreUseCase := usecase.NewScoreUseCase(f.scoreRepository, enrollmentUseCase, assignmentUseCase, courseUseCase, userUseCase, studentUseCase)
courseStreamUseCase := usecase.NewCourseStreamUseCase(f.courseStreamRepository, courseUseCase)
coursePortfolioUseCase := usecase.NewCoursePortfolioUseCase(f.coursePortfolioRepository, courseUseCase, userUseCase, enrollmentUseCase, assignmentUseCase, scoreUseCase, studentUseCase, courseLearningOutcomeUseCase, courseStreamUseCase)
importerUseCase := usecase.NewImporterUseCase(f.importerRepository, courseUseCase, enrollmentUseCase, assignmentUseCase, programOutcomeUseCase, programLearningOutcomeUseCase, courseLearningOutcomeUseCase, userUseCase)
importerUseCase := usecase.NewImporterUseCase(f.importerRepository, courseUseCase, enrollmentUseCase, assignmentUseCase, programOutcomeUseCase, programLearningOutcomeUseCase, courseLearningOutcomeUseCase, userUseCase, studentUseCase)
predictionUseCase := usecase.NewPredictionUseCase(f.config)

f.assignmentUseCase = assignmentUseCase
Expand Down
17 changes: 17 additions & 0 deletions usecase/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ImporterUseCase struct {
programLearningOutcomeUseCase entity.ProgramLearningOutcomeUseCase
courseLearningOutcomeUseCase entity.CourseLearningOutcomeUseCase
userUseCase entity.UserUseCase
studentUseCase entity.StudentUseCase
}

func NewImporterUseCase(
Expand All @@ -29,6 +30,7 @@ func NewImporterUseCase(
programLearningOutcomeUseCase entity.ProgramLearningOutcomeUseCase,
courseLearningOutcomeUseCase entity.CourseLearningOutcomeUseCase,
userUseCase entity.UserUseCase,
studentUseCase entity.StudentUseCase,
) ImporterUseCase {
return ImporterUseCase{
importerRepository: importerRepository,
Expand All @@ -39,6 +41,7 @@ func NewImporterUseCase(
programLearningOutcomeUseCase: programLearningOutcomeUseCase,
courseLearningOutcomeUseCase: courseLearningOutcomeUseCase,
userUseCase: userUseCase,
studentUseCase: studentUseCase,
}
}

Expand Down Expand Up @@ -250,8 +253,18 @@ func (u ImporterUseCase) UpdateOrCreate(

}

isStudentNotFound := false
missingStudentList := make([]string, 0)

// prepare enrollments
for _, studentId := range studentIds {
student, err := u.studentUseCase.GetById(studentId)
if err != nil {
return errs.New(errs.ErrStudentNotFound, "cannot get student id %s while import course", studentId)
} else if student == nil {
isStudentNotFound = true
missingStudentList = append(missingStudentList, studentId)
}
enrollmentsToCreate = append(enrollmentsToCreate, entity.Enrollment{
Id: ulid.Make().String(),
CourseId: courseId,
Expand All @@ -260,6 +273,10 @@ func (u ImporterUseCase) UpdateOrCreate(
})
}

if isStudentNotFound {
return errs.New(errs.ErrStudentNotFound, "student ids: %v not found while import course", missingStudentList)
}

// let's go bro
err = u.importerRepository.UpdateOrCreate(
courseId,
Expand Down