<commit_before>package models.question.derivative

import mathml._
import mathml.scalar._
import scala.slick.session.Session
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick.DB
import play.api.Play.current
import models.organization.table._
import models.question.derivative.table._
import service.User
import models.id._
import org.joda.time.DateTime
import service._

case class Quiz(id: QuizId, owner: UserId, name: String, creationDate: DateTime, updateDate: DateTime)

case class QuizTmp(owner: UserId, name: String, date: DateTime){
	def apply(id: QuizId) = Quiz(id, owner, name, date, date)
}

object Quizzes {

	def find(quizId: QuizId) = DB.withSession { implicit session: Session =>
		Query(new QuizzesTable).where(_.id === quizId).firstOption
	}
	
	def findQuestions(quizId: QuizId) = DB.withSession { implicit session: Session =>
		(for {
			l <- (new QuizzesQuestionsTable) if l.quizId === quizId
			q <- (new QuestionsTable) if l.questionId === q.id
		} yield q).list
	}
	
	def create(info: QuizTmp, courseId: Option[CourseId]) = DB.withSession { implicit session: Session =>
		val quizId = (new QuizzesTable).insert(info)
		(new UsersQuizzesTable).insert(User2Quiz(info.owner, quizId, Own))
		courseId.foreach(c => { (new CoursesQuizzesTable).insert(Course2Quiz(c, quizId)) })
		quizId
	}

	def findByCourse(courseId: CourseId) = DB.withSession { implicit session: Session =>
		(for (
			q <- (new QuizzesTable);
			cq <- (new CoursesQuizzesTable) if cq.quizId === q.id
		) yield q).list
	}

}
<commit_msg>fixed a bug where quizzes would show up for the wrong course<commit_after>package models.question.derivative

import mathml._
import mathml.scalar._
import scala.slick.session.Session
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick.DB
import play.api.Play.current
import models.organization.table._
import models.question.derivative.table._
import service.User
import models.id._
import org.joda.time.DateTime
import service._

case class Quiz(id: QuizId, owner: UserId, name: String, creationDate: DateTime, updateDate: DateTime)

case class QuizTmp(owner: UserId, name: String, date: DateTime){
	def apply(id: QuizId) = Quiz(id, owner, name, date, date)
}

object Quizzes {

	def find(quizId: QuizId) = DB.withSession { implicit session: Session =>
		Query(new QuizzesTable).where(_.id === quizId).firstOption
	}
	
	def findQuestions(quizId: QuizId) = DB.withSession { implicit session: Session =>
		(for {
			l <- (new QuizzesQuestionsTable) if l.quizId === quizId
			q <- (new QuestionsTable) if l.questionId === q.id
		} yield q).list
	}
	
	def create(info: QuizTmp, courseId: Option[CourseId]) = DB.withSession { implicit session: Session =>
		val quizId = (new QuizzesTable).insert(info)
		(new UsersQuizzesTable).insert(User2Quiz(info.owner, quizId, Own))
		courseId.foreach(c => { (new CoursesQuizzesTable).insert(Course2Quiz(c, quizId)) })
		quizId
	}

	def findByCourse(courseId: CourseId) = DB.withSession { implicit session: Session =>
		(for (
			q <- (new QuizzesTable);
			cq <- (new CoursesQuizzesTable) if cq.quizId === q.id && cq.courseId === courseId
		) yield q).list
	}

}

{'fraction_non_alphanumeric': 0.1263823064770932, 'fraction_numerical': 0.001263823064770932, 'mean_word_length': 4.603539823008849, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4032371', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1078, 'n_words': 271}