diff --git a/main b/main index 1b555d0..3fc71d4 100755 Binary files a/main and b/main differ diff --git a/models/lab_exercise.go b/models/lab_exercise.go new file mode 100644 index 0000000..78946e7 --- /dev/null +++ b/models/lab_exercise.go @@ -0,0 +1,29 @@ +package models + +import ( + "encoding/json" + "time" + + "github.com/google/uuid" +) + +type LabExercise struct { + ExerciseID uuid.UUID `gorm:"type:varchar(36);primaryKey;column:exercise_id"` + ChapterID *uuid.UUID `gorm:"type:varchar(36);column:chapter_id"` + Level *string `gorm:"type:enum('0','1','2','3','4','5','6')"` + Name *string `gorm:"type:varchar(1024)"` + Content *string `gorm:"type:mediumtext"` + Testcase string `gorm:"type:enum('NO_INPUT','YES','UNDEFINED');not null;default:'NO_INPUT'"` + Sourcecode *string `gorm:"type:varchar(50)"` + FullMark int `gorm:"type:int;not null;default:10"` + AddedDate time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP"` + LastUpdate *time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP"` + UserDefinedConstraints *json.RawMessage `gorm:"type:json"` + SuggestedConstraints *json.RawMessage `gorm:"type:json"` + AddedBy *string `gorm:"type:varchar(40)"` + CreatedBy *uuid.UUID `gorm:"type:varchar(36)"` +} + +func (LabExercise) TableName() string { + return "lab_exercises" +} diff --git a/repositories/lab_exercise_repository.go b/repositories/lab_exercise_repository.go new file mode 100644 index 0000000..e645d12 --- /dev/null +++ b/repositories/lab_exercise_repository.go @@ -0,0 +1,25 @@ +package repositories + +import ( + "github.com/Project-IPCA/ipca-worker-go-v2/models" + "github.com/google/uuid" + "gorm.io/gorm" +) + +type LabExerciseRepository struct { + DB *gorm.DB +} + +func NewLabExerciseRePository(db *gorm.DB) *LabExerciseRepository { + return &LabExerciseRepository{ + DB: db, + } +} + +func (labExerciseRepo *LabExerciseRepository) GetLabExerciseById(labExercise *models.LabExercise,exerciseId uuid.UUID) { + labExerciseRepo.DB.Where("exercise_id",exerciseId).Find(labExercise) +} + +func (labExerciseRepo *LabExerciseRepository) UpdateExerciseTestcaseEnum(labExercise *models.LabExercise,testcaseEnum string) { + labExerciseRepo.DB.Model(labExercise).Update("testcase" , testcaseEnum) +} \ No newline at end of file diff --git a/service/update_testcase_submission.go b/service/update_testcase_submission.go index 0b7bf67..a24a272 100644 --- a/service/update_testcase_submission.go +++ b/service/update_testcase_submission.go @@ -33,16 +33,20 @@ func AddAndUpdateTestCase(channel *amqp.Channel, db_pool *gorm.DB, msg amqp.Deli func compileCodeTestcase (db_pool *gorm.DB, msgBody models.ReciveMessage) error{ exerciseTestcaseRepo := repositories.NewExcerciseTestCaseRePository(db_pool) + labExerciseRepo := repositories.NewLabExerciseRePository(db_pool) + + exerciseUuid,err := uuid.Parse(*msgBody.ExcerciseID) + if(err!=nil){ + return utils.NewAppError(utils.ERROR_NAME.FUNCTION_ERROR,"failed to convert exercise uuid", err.Error()) + } + var labExercise models.LabExercise + labExerciseRepo.GetLabExerciseById(&labExercise,exerciseUuid) if(len(msgBody.TestCaseList)>0){ for i:=0; i