Replaced the database to match the new schema
This commit is contained in:
parent
bfeb5f5132
commit
a3dc69b23b
43 changed files with 323 additions and 443 deletions
|
@ -4,33 +4,24 @@ import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import com.faraphel.tasks_valider.database.converters.InstantConverter
|
import com.faraphel.tasks_valider.database.converters.InstantConverter
|
||||||
import com.faraphel.tasks_valider.database.dao.GroupDao
|
import com.faraphel.tasks_valider.database.dao.*
|
||||||
import com.faraphel.tasks_valider.database.dao.GroupStudentDao
|
import com.faraphel.tasks_valider.database.entities.*
|
||||||
import com.faraphel.tasks_valider.database.dao.StudentDao
|
|
||||||
import com.faraphel.tasks_valider.database.dao.TaskDao
|
|
||||||
import com.faraphel.tasks_valider.database.dao.TaskGroupDao
|
|
||||||
import com.faraphel.tasks_valider.database.dao.TeacherDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupEntity
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupStudentEntity
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.StudentEntity
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskEntity
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskGroupEntity
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TeacherEntity
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The database for the tasks application.
|
* The database for the tasks' application.
|
||||||
* Contains the entities and the relations between them.
|
* Contains the entities and the relations between them.
|
||||||
*/
|
*/
|
||||||
@Database(
|
@Database(
|
||||||
entities = [
|
entities = [
|
||||||
GroupEntity::class,
|
ClassEntity::class,
|
||||||
StudentEntity::class,
|
PersonEntity::class,
|
||||||
TeacherEntity::class,
|
SessionEntity::class,
|
||||||
|
SubjectEntity::class,
|
||||||
TaskEntity::class,
|
TaskEntity::class,
|
||||||
|
ValidationEntity::class,
|
||||||
|
|
||||||
GroupStudentEntity::class,
|
RelationClassPersonEntity::class,
|
||||||
TaskGroupEntity::class,
|
|
||||||
],
|
],
|
||||||
version = 1
|
version = 1
|
||||||
)
|
)
|
||||||
|
@ -38,11 +29,12 @@ import com.faraphel.tasks_valider.database.entities._old.TeacherEntity
|
||||||
InstantConverter::class
|
InstantConverter::class
|
||||||
)
|
)
|
||||||
abstract class TaskDatabase: RoomDatabase() {
|
abstract class TaskDatabase: RoomDatabase() {
|
||||||
abstract fun groupDao(): GroupDao
|
abstract fun classDao(): ClassDao
|
||||||
abstract fun studentDao(): StudentDao
|
abstract fun personDao(): PersonDao
|
||||||
abstract fun teacherDao(): TeacherDao
|
abstract fun sessionDao(): SessionDao
|
||||||
|
abstract fun subjectDao(): SubjectDao
|
||||||
abstract fun taskDao(): TaskDao
|
abstract fun taskDao(): TaskDao
|
||||||
|
abstract fun validationDao(): ValidationDao
|
||||||
|
|
||||||
abstract fun groupStudentDao(): GroupStudentDao
|
abstract fun relationClassPersonDao(): RelationClassPersonDao
|
||||||
abstract fun taskGroupDao(): TaskGroupDao
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,19 @@ import com.faraphel.tasks_valider.connectivity.task.session.TaskSession
|
||||||
import com.faraphel.tasks_valider.database.TaskDatabase
|
import com.faraphel.tasks_valider.database.TaskDatabase
|
||||||
import com.faraphel.tasks_valider.database.api.entities.*
|
import com.faraphel.tasks_valider.database.api.entities.*
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseApi
|
||||||
|
import com.faraphel.tasks_valider.database.entities.*
|
||||||
import fi.iki.elonen.NanoHTTPD
|
import fi.iki.elonen.NanoHTTPD
|
||||||
|
|
||||||
class TaskDatabaseApi(private val database: TaskDatabase) {
|
class TaskDatabaseApi(private val database: TaskDatabase) {
|
||||||
private val api: Map<String, BaseApi> = mapOf(
|
private val api: Map<String, BaseApi> = mapOf(
|
||||||
"group" to GroupApi(this.database.groupDao()),
|
ClassEntity.TABLE_NAME to ClassApi(this.database.classDao()),
|
||||||
"student" to StudentApi(this.database.studentDao()),
|
PersonEntity.TABLE_NAME to PersonApi(this.database.personDao()),
|
||||||
"teacher" to TeacherApi(this.database.teacherDao()),
|
SessionEntity.TABLE_NAME to SessionApi(this.database.sessionDao()),
|
||||||
"task" to TaskApi(this.database.taskDao()),
|
SubjectEntity.TABLE_NAME to SubjectApi(this.database.subjectDao()),
|
||||||
|
TaskEntity.TABLE_NAME to TaskApi(this.database.taskDao()),
|
||||||
|
ValidationEntity.TABLE_NAME to ValidationApi(this.database.validationDao()),
|
||||||
|
|
||||||
"group_student" to GroupStudentApi(this.database.groupStudentDao()),
|
RelationClassPersonEntity.TABLE_NAME to RelationClassPersonApi(this.database.relationClassPersonDao()),
|
||||||
"task_group" to TaskGroupApi(this.database.taskGroupDao()),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,6 @@ package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupEntity
|
import com.faraphel.tasks_valider.database.entities.ClassEntity
|
||||||
|
|
||||||
class GroupApi(dao: BaseDao<GroupEntity>) : BaseJsonApi<GroupEntity>(dao)
|
class ClassApi(dao: BaseDao<ClassEntity>) : BaseJsonApi<ClassEntity>(dao)
|
|
@ -1,7 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.api.entities
|
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupStudentEntity
|
|
||||||
|
|
||||||
class GroupStudentApi(dao: BaseDao<GroupStudentEntity>) : BaseJsonApi<GroupStudentEntity>(dao)
|
|
|
@ -2,6 +2,6 @@ package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TeacherEntity
|
import com.faraphel.tasks_valider.database.entities.PersonEntity
|
||||||
|
|
||||||
class TeacherApi(dao: BaseDao<TeacherEntity>) : BaseJsonApi<TeacherEntity>(dao)
|
class PersonApi(dao: BaseDao<PersonEntity>) : BaseJsonApi<PersonEntity>(dao)
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.RelationClassPersonEntity
|
||||||
|
|
||||||
|
class RelationClassPersonApi(dao: BaseDao<RelationClassPersonEntity>) : BaseJsonApi<RelationClassPersonEntity>(dao)
|
|
@ -2,6 +2,6 @@ package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.StudentEntity
|
import com.faraphel.tasks_valider.database.entities.SessionEntity
|
||||||
|
|
||||||
class StudentApi(dao: BaseDao<StudentEntity>) : BaseJsonApi<StudentEntity>(dao)
|
class SessionApi(dao: BaseDao<SessionEntity>) : BaseJsonApi<SessionEntity>(dao)
|
|
@ -2,6 +2,6 @@ package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskGroupEntity
|
import com.faraphel.tasks_valider.database.entities.SubjectEntity
|
||||||
|
|
||||||
class TaskGroupApi(dao: BaseDao<TaskGroupEntity>) : BaseJsonApi<TaskGroupEntity>(dao)
|
class SubjectApi(dao: BaseDao<SubjectEntity>) : BaseJsonApi<SubjectEntity>(dao)
|
|
@ -2,6 +2,6 @@ package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskEntity
|
import com.faraphel.tasks_valider.database.entities.TaskEntity
|
||||||
|
|
||||||
class TaskApi(dao: BaseDao<TaskEntity>) : BaseJsonApi<TaskEntity>(dao)
|
class TaskApi(dao: BaseDao<TaskEntity>) : BaseJsonApi<TaskEntity>(dao)
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.faraphel.tasks_valider.database.api.entities
|
||||||
|
|
||||||
|
import com.faraphel.tasks_valider.database.api.entities.base.BaseJsonApi
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.ValidationEntity
|
||||||
|
|
||||||
|
class ValidationApi(dao: BaseDao<ValidationEntity>) : BaseJsonApi<ValidationEntity>(dao)
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.ClassEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.PersonEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.RelationClassPersonEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.SessionEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface ClassDao : BaseDao<ClassEntity> {
|
||||||
|
@Query("SELECT * FROM ${ClassEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<ClassEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifier
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${ClassEntity.TABLE_NAME} WHERE id = :id")
|
||||||
|
fun getById(id: Long): ClassEntity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the sessions this class attended
|
||||||
|
* @param id the id of the class
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${SessionEntity.TABLE_NAME} WHERE class_id = :id")
|
||||||
|
fun getSessions(id: Long): List<SessionEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the students in a class
|
||||||
|
* @param id the id of the class
|
||||||
|
*/
|
||||||
|
@Query(
|
||||||
|
"SELECT * FROM ${PersonEntity.TABLE_NAME} " +
|
||||||
|
"JOIN ${RelationClassPersonEntity.TABLE_NAME} " +
|
||||||
|
"ON ${PersonEntity.TABLE_NAME}.id = ${RelationClassPersonEntity.TABLE_NAME}.student_id " +
|
||||||
|
"WHERE ${RelationClassPersonEntity.TABLE_NAME}.class_id = :id"
|
||||||
|
)
|
||||||
|
fun getStudents(id: Long): List<PersonEntity>
|
||||||
|
}
|
|
@ -1,28 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.RewriteQueriesToDropUnusedColumns
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface GroupDao : BaseDao<GroupEntity> {
|
|
||||||
@Query("SELECT * FROM `groups`")
|
|
||||||
override fun getAll(): List<GroupEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM `groups` WHERE id = :id")
|
|
||||||
fun getById(id: Long): GroupEntity
|
|
||||||
|
|
||||||
/**
|
|
||||||
Allow to get all groups with a specific student
|
|
||||||
*/
|
|
||||||
@Query(
|
|
||||||
"SELECT * FROM `groups` " +
|
|
||||||
"JOIN `group_student` ON `groups`.id = `group_student`.student_id " +
|
|
||||||
"WHERE `group_student`.student_id = :studentId"
|
|
||||||
)
|
|
||||||
@RewriteQueriesToDropUnusedColumns
|
|
||||||
fun filterByStudentId(studentId: Long): List<GroupEntity>
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupStudentEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface GroupStudentDao : BaseDao<GroupStudentEntity> {
|
|
||||||
@Query("SELECT * FROM `group_student`")
|
|
||||||
override fun getAll(): List<GroupStudentEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM `group_student` WHERE group_id = :groupId AND student_id = :studentId")
|
|
||||||
fun getById(groupId: Long, studentId: Long): GroupStudentEntity
|
|
||||||
}
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.*
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface PersonDao : BaseDao<PersonEntity> {
|
||||||
|
@Query("SELECT * FROM ${PersonEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<PersonEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifier
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${PersonEntity.TABLE_NAME} WHERE id = :id")
|
||||||
|
fun getById(id: Long): PersonEntity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow to get all the classes the person is attending as a student
|
||||||
|
*/
|
||||||
|
@Query(
|
||||||
|
"SELECT * FROM ${ClassEntity.TABLE_NAME} " +
|
||||||
|
"JOIN ${RelationClassPersonEntity.TABLE_NAME} " +
|
||||||
|
"ON ${ClassEntity.TABLE_NAME}.id = ${RelationClassPersonEntity.TABLE_NAME}.student_id " +
|
||||||
|
"WHERE ${RelationClassPersonEntity.TABLE_NAME}.student_id = :id"
|
||||||
|
)
|
||||||
|
fun getClasses(id: Long): List<ClassEntity>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the tasks this user approved as a teacher
|
||||||
|
* @param id the id of the person
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${ValidationEntity.TABLE_NAME} WHERE teacher_id = :id")
|
||||||
|
fun getTasksApproved(id: Long): List<ValidationEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the tasks this user validated as a student
|
||||||
|
* @param id the id of the person
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${ValidationEntity.TABLE_NAME} WHERE student_id = :id")
|
||||||
|
fun getTasksValidated(id: Long): List<ValidationEntity>
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.RelationClassPersonEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface RelationClassPersonDao : BaseDao<RelationClassPersonEntity> {
|
||||||
|
@Query("SELECT * FROM ${RelationClassPersonEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<RelationClassPersonEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifiers
|
||||||
|
*/
|
||||||
|
@Query(
|
||||||
|
"SELECT * FROM ${RelationClassPersonEntity.TABLE_NAME} " +
|
||||||
|
"WHERE " +
|
||||||
|
"class_id = :classId AND " +
|
||||||
|
"student_id = :studentId"
|
||||||
|
)
|
||||||
|
fun getById(classId: Long, studentId: Long): RelationClassPersonEntity
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.SessionEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface SessionDao : BaseDao<SessionEntity> {
|
||||||
|
@Query("SELECT * FROM ${SessionEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<SessionEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifier
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${SessionEntity.TABLE_NAME} WHERE id = :id")
|
||||||
|
fun getById(id: Long): SessionEntity
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.RewriteQueriesToDropUnusedColumns
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.StudentEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface StudentDao : BaseDao<StudentEntity> {
|
|
||||||
@Query("SELECT * FROM `students`")
|
|
||||||
override fun getAll(): List<StudentEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM `students` WHERE id = :id")
|
|
||||||
fun getById(id: Long): StudentEntity
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Allow to get all the students in a group
|
|
||||||
*/
|
|
||||||
@Query(
|
|
||||||
"SELECT * FROM `students` " +
|
|
||||||
"JOIN `group_student` ON `students`.id = `group_student`.student_id " +
|
|
||||||
"WHERE `group_student`.group_id = :groupId"
|
|
||||||
)
|
|
||||||
@RewriteQueriesToDropUnusedColumns
|
|
||||||
fun filterByGroupId(groupId: Long): List<StudentEntity>
|
|
||||||
}
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.SessionEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.SubjectEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.TaskEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface SubjectDao : BaseDao<SubjectEntity> {
|
||||||
|
@Query("SELECT * FROM ${SubjectEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<SubjectEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifier
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${SubjectEntity.TABLE_NAME} WHERE id = :id")
|
||||||
|
fun getById(id: Long): SubjectEntity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the tasks available in a subject
|
||||||
|
* @param id the id of the subject
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${TaskEntity.TABLE_NAME} WHERE subject_id = :id")
|
||||||
|
fun getSessions(id: Long): List<SessionEntity>
|
||||||
|
}
|
|
@ -2,27 +2,25 @@ package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.RewriteQueriesToDropUnusedColumns
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskEntity
|
import com.faraphel.tasks_valider.database.entities.TaskEntity
|
||||||
|
import com.faraphel.tasks_valider.database.entities.ValidationEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface TaskDao : BaseDao<TaskEntity> {
|
interface TaskDao : BaseDao<TaskEntity> {
|
||||||
@Query("SELECT * FROM `tasks`")
|
@Query("SELECT * FROM ${TaskEntity.TABLE_NAME}")
|
||||||
override fun getAll(): List<TaskEntity>
|
override fun getAll(): List<TaskEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM `tasks` WHERE id = :id")
|
/**
|
||||||
|
* Get the object from its identifier
|
||||||
|
*/
|
||||||
|
@Query("SELECT * FROM ${TaskEntity.TABLE_NAME} WHERE id = :id")
|
||||||
fun getById(id: Long): TaskEntity
|
fun getById(id: Long): TaskEntity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get all the tasks for a specific group
|
* Get all the validations have been approved for this tasks
|
||||||
|
* @param id the id of the task
|
||||||
*/
|
*/
|
||||||
@Query(
|
@Query("SELECT * FROM ${ValidationEntity.TABLE_NAME} WHERE task_id = :id")
|
||||||
"SELECT * FROM `tasks` " +
|
fun getTasksValidated(id: Long): List<ValidationEntity>
|
||||||
"JOIN `task_group` ON `tasks`.id = `task_group`.task_id " +
|
|
||||||
"WHERE `task_group`.group_id = :groupId"
|
|
||||||
)
|
|
||||||
@RewriteQueriesToDropUnusedColumns
|
|
||||||
fun filterByGroupId(groupId: Long): List<TaskEntity>
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskGroupEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface TaskGroupDao : BaseDao<TaskGroupEntity> {
|
|
||||||
@Query("SELECT * FROM `task_group`")
|
|
||||||
override fun getAll(): List<TaskGroupEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM `task_group` WHERE task_id = :taskId AND group_id = :groupId")
|
|
||||||
fun getById(taskId: Long, groupId: Long): TaskGroupEntity
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TeacherEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface TeacherDao : BaseDao<TeacherEntity> {
|
|
||||||
@Query("SELECT * FROM `teachers`")
|
|
||||||
override fun getAll(): List<TeacherEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM `teachers` WHERE id = :id")
|
|
||||||
fun getById(id: Long): TeacherEntity
|
|
||||||
}
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.faraphel.tasks_valider.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||||
|
import com.faraphel.tasks_valider.database.entities.ValidationEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface ValidationDao : BaseDao<ValidationEntity> {
|
||||||
|
@Query("SELECT * FROM ${ValidationEntity.TABLE_NAME}")
|
||||||
|
override fun getAll(): List<ValidationEntity>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object from its identifiers
|
||||||
|
*/
|
||||||
|
@Query(
|
||||||
|
"SELECT * FROM ${ValidationEntity.TABLE_NAME} " +
|
||||||
|
"WHERE " +
|
||||||
|
"teacher_id = :teacherId and " +
|
||||||
|
"student_id = :studentId and " +
|
||||||
|
"task_id = :taskId"
|
||||||
|
)
|
||||||
|
fun getById(teacherId: Long, studentId: Long, taskId: Long): ValidationEntity
|
||||||
|
}
|
|
@ -5,8 +5,13 @@ import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
|
|
||||||
@Entity(tableName = "classes")
|
|
||||||
|
@Entity(tableName = ClassEntity.TABLE_NAME)
|
||||||
data class ClassEntity (
|
data class ClassEntity (
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
@ColumnInfo("name") val name: String,
|
@ColumnInfo("name") val name: String,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "classes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,10 +6,14 @@ import androidx.room.PrimaryKey
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = "students")
|
@Entity(tableName = PersonEntity.TABLE_NAME)
|
||||||
data class StudentEntity (
|
data class PersonEntity (
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
@ColumnInfo("first_name") val firstName: String,
|
@ColumnInfo("first_name") val firstName: String,
|
||||||
@ColumnInfo("last_name") val lastName: String,
|
@ColumnInfo("last_name") val lastName: String,
|
||||||
@ColumnInfo("card_id") val cardId: UUID,
|
@ColumnInfo("card_id") val cardId: UUID,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "persons"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
package com.faraphel.tasks_valider.database.entities
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
@ -6,27 +6,31 @@ import androidx.room.ForeignKey
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "group_student",
|
tableName = RelationClassPersonEntity.TABLE_NAME,
|
||||||
primaryKeys = [
|
primaryKeys = [
|
||||||
"group_id",
|
"student_id",
|
||||||
"student_id"
|
"class_id",
|
||||||
],
|
],
|
||||||
foreignKeys = [
|
foreignKeys = [
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = GroupEntity::class,
|
entity = PersonEntity::class,
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["group_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
ForeignKey(
|
|
||||||
entity = StudentEntity::class,
|
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["student_id"],
|
childColumns = ["student_id"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
)
|
),
|
||||||
|
ForeignKey(
|
||||||
|
entity = ClassEntity::class,
|
||||||
|
parentColumns = ["id"],
|
||||||
|
childColumns = ["class_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
data class GroupStudentEntity(
|
data class RelationClassPersonEntity (
|
||||||
@ColumnInfo("group_id", index = true) val groupId: Long,
|
|
||||||
@ColumnInfo("student_id", index = true) val studentId: Long,
|
@ColumnInfo("student_id", index = true) val studentId: Long,
|
||||||
) : BaseEntity()
|
@ColumnInfo("class_id", index = true) val classId: Long,
|
||||||
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "relation_class_person"
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "sessions",
|
tableName = SessionEntity.TABLE_NAME,
|
||||||
foreignKeys = [
|
foreignKeys = [
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = ClassEntity::class,
|
entity = ClassEntity::class,
|
||||||
|
@ -23,5 +23,9 @@ data class SessionEntity (
|
||||||
@ColumnInfo("name") val name: String? = null,
|
@ColumnInfo("name") val name: String? = null,
|
||||||
@ColumnInfo("start") val start: Instant,
|
@ColumnInfo("start") val start: Instant,
|
||||||
|
|
||||||
@ColumnInfo("class_id") val classId: Long? = null,
|
@ColumnInfo("class_id", index = true) val classId: Long? = null,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "sessions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,8 +5,12 @@ import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
|
|
||||||
@Entity(tableName = "subjects")
|
@Entity(tableName = SubjectEntity.TABLE_NAME)
|
||||||
data class SubjectEntity (
|
data class SubjectEntity (
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
@ColumnInfo("name") val name: String,
|
@ColumnInfo("name") val name: String,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "subjects"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "tasks",
|
tableName = TaskEntity.TABLE_NAME,
|
||||||
foreignKeys = [
|
foreignKeys = [
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = SubjectEntity::class,
|
entity = SubjectEntity::class,
|
||||||
|
@ -22,5 +22,9 @@ data class TaskEntity (
|
||||||
@ColumnInfo("title") val title: String,
|
@ColumnInfo("title") val title: String,
|
||||||
@ColumnInfo("description") val description: String? = null,
|
@ColumnInfo("description") val description: String? = null,
|
||||||
|
|
||||||
@ColumnInfo("subject_id") val subjectId: Long,
|
@ColumnInfo("subject_id", index = true) val subjectId: Long,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "tasks"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
|
||||||
|
|
||||||
|
|
||||||
// TODO(Faraphel): is this class really required ?
|
|
||||||
@Entity(tableName = "teachers")
|
|
||||||
data class TeacherEntity (
|
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
|
||||||
@ColumnInfo("first_name") val firstName: String,
|
|
||||||
@ColumnInfo("last_name") val lastName: String,
|
|
||||||
) : BaseEntity()
|
|
|
@ -7,37 +7,42 @@ import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "validations",
|
tableName = ValidationEntity.TABLE_NAME,
|
||||||
primaryKeys = [
|
primaryKeys = [
|
||||||
"teacher_id",
|
"teacher_id",
|
||||||
"task_id",
|
|
||||||
"student_id",
|
"student_id",
|
||||||
|
"task_id",
|
||||||
],
|
],
|
||||||
foreignKeys = [
|
foreignKeys = [
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = TeacherEntity::class,
|
entity = PersonEntity::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["teacher_id"],
|
childColumns = ["teacher_id"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
),
|
),
|
||||||
|
ForeignKey(
|
||||||
|
entity = PersonEntity::class,
|
||||||
|
parentColumns = ["id"],
|
||||||
|
childColumns = ["student_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = TaskEntity::class,
|
entity = TaskEntity::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["task_id"],
|
childColumns = ["task_id"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
),
|
),
|
||||||
ForeignKey(
|
|
||||||
entity = StudentEntity::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["student_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
data class ValidationEntity (
|
data class ValidationEntity (
|
||||||
@ColumnInfo("date") val date: Instant,
|
@ColumnInfo("date") val date: Instant,
|
||||||
|
|
||||||
@ColumnInfo("teacher_id") val teacherId: Long,
|
@ColumnInfo("teacher_id", index = true) val teacherId: Long,
|
||||||
@ColumnInfo("task_id") val taskId: Long,
|
@ColumnInfo("student_id", index = true) val studentId: Long,
|
||||||
@ColumnInfo("student_id") val studentId: Long,
|
@ColumnInfo("task_id", index = true) val taskId: Long,
|
||||||
) : BaseEntity()
|
) : BaseEntity() {
|
||||||
|
companion object {
|
||||||
|
const val TABLE_NAME = "validations"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
|
||||||
|
|
||||||
|
|
||||||
// TODO(Faraphel): should be renamed to TeamEntity
|
|
||||||
@Entity(tableName = "groups")
|
|
||||||
data class GroupEntity (
|
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
|
||||||
@ColumnInfo("name") val name: String? = null,
|
|
||||||
) : BaseEntity()
|
|
|
@ -1,19 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import java.util.Locale
|
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
|
||||||
|
|
||||||
|
|
||||||
open class PersonEntity (
|
|
||||||
open val id: Long = 0,
|
|
||||||
open val firstName: String,
|
|
||||||
open val lastName: String,
|
|
||||||
) : BaseEntity() {
|
|
||||||
/**
|
|
||||||
Get the full name of the person
|
|
||||||
*/
|
|
||||||
val fullName: String
|
|
||||||
get() {
|
|
||||||
return "${firstName.capitalize(Locale.ROOT)} ${lastName.uppercase()}"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "students")
|
|
||||||
class StudentEntity(
|
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) override val id: Long = 0,
|
|
||||||
@ColumnInfo("first_name") override val firstName: String,
|
|
||||||
@ColumnInfo("last_name") override val lastName: String
|
|
||||||
) : PersonEntity(id, firstName, lastName)
|
|
|
@ -1,13 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
|
||||||
|
|
||||||
@Entity(tableName = "tasks")
|
|
||||||
data class TaskEntity (
|
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) val id: Long = 0,
|
|
||||||
@ColumnInfo("title") val title: String,
|
|
||||||
@ColumnInfo("description") val description: String,
|
|
||||||
) : BaseEntity()
|
|
|
@ -1,44 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.ForeignKey
|
|
||||||
import com.faraphel.tasks_valider.database.entities.base.BaseEntity
|
|
||||||
import java.time.Instant
|
|
||||||
|
|
||||||
|
|
||||||
@Entity(
|
|
||||||
tableName = "task_group",
|
|
||||||
primaryKeys = [
|
|
||||||
"task_id",
|
|
||||||
"group_id"
|
|
||||||
],
|
|
||||||
foreignKeys = [
|
|
||||||
ForeignKey(
|
|
||||||
entity = GroupEntity::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["group_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
ForeignKey(
|
|
||||||
entity = TaskEntity::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["task_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
ForeignKey(
|
|
||||||
entity = TeacherEntity::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["approval_teacher_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
data class TaskGroupEntity (
|
|
||||||
@ColumnInfo("task_id") val taskId: Long,
|
|
||||||
@ColumnInfo("group_id") val groupId: Long,
|
|
||||||
@ColumnInfo("approval_status") var approvalStatus: Boolean = false,
|
|
||||||
@ColumnInfo("approval_teacher_id") val approvalTeacherId: Long? = null,
|
|
||||||
@ColumnInfo("approval_time") val approvalTime: Instant? = null
|
|
||||||
) : BaseEntity()
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.database.entities._old
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "teachers")
|
|
||||||
class TeacherEntity(
|
|
||||||
@ColumnInfo("id") @PrimaryKey(autoGenerate = true) override val id: Long = 0,
|
|
||||||
@ColumnInfo("first_name") override val firstName: String,
|
|
||||||
@ColumnInfo("last_name") override val lastName: String
|
|
||||||
) : PersonEntity(id, firstName, lastName)
|
|
|
@ -16,7 +16,7 @@ import com.faraphel.tasks_valider.connectivity.task.TaskClient
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_ADDRESS
|
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_ADDRESS
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.task.TaskGroupScreen
|
import com.faraphel.tasks_valider.ui.screen.task.TaskSessionScreen
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -24,7 +24,7 @@ fun CommunicationInternetClientScreen(activity: Activity) {
|
||||||
val client = remember { mutableStateOf<TaskClient?>(null) }
|
val client = remember { mutableStateOf<TaskClient?>(null) }
|
||||||
|
|
||||||
if (client.value == null) CommunicationInternetClientContent(client)
|
if (client.value == null) CommunicationInternetClientContent(client)
|
||||||
else TaskGroupScreen(activity, client.value!!)
|
else TaskSessionScreen(activity, client.value!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.faraphel.tasks_valider.connectivity.task.TaskServer
|
||||||
import com.faraphel.tasks_valider.database.TaskDatabase
|
import com.faraphel.tasks_valider.database.TaskDatabase
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.task.TaskGroupScreen
|
import com.faraphel.tasks_valider.ui.screen.task.TaskSessionScreen
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -31,7 +31,7 @@ fun CommunicationInternetServerScreen(activity: Activity) {
|
||||||
// if the server is not created, prompt the user for the server configuration
|
// if the server is not created, prompt the user for the server configuration
|
||||||
if (client.value == null) CommunicationInternetServerContent(activity, client)
|
if (client.value == null) CommunicationInternetServerContent(activity, client)
|
||||||
// else, go to the base tasks screen
|
// else, go to the base tasks screen
|
||||||
else TaskGroupScreen(activity, client.value!!)
|
else TaskSessionScreen(activity, client.value!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import com.faraphel.tasks_valider.connectivity.task.TaskServer
|
||||||
import com.faraphel.tasks_valider.database.TaskDatabase
|
import com.faraphel.tasks_valider.database.TaskDatabase
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.DEFAULT_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
import com.faraphel.tasks_valider.ui.screen.communication.RANGE_SERVER_PORT
|
||||||
import com.faraphel.tasks_valider.ui.screen.task.TaskGroupScreen
|
import com.faraphel.tasks_valider.ui.screen.task.TaskSessionScreen
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -32,7 +32,7 @@ fun CommunicationWifiP2pServerScreen(activity: Activity, bwfManager: BwfManager)
|
||||||
// if the server is not created, prompt the user for the server configuration
|
// if the server is not created, prompt the user for the server configuration
|
||||||
if (client.value == null) CommunicationWifiP2pServerContent(activity, bwfManager, client)
|
if (client.value == null) CommunicationWifiP2pServerContent(activity, bwfManager, client)
|
||||||
// else, go to the base tasks screen
|
// else, go to the base tasks screen
|
||||||
else TaskGroupScreen(activity, client.value!!)
|
else TaskSessionScreen(activity, client.value!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,22 @@
|
||||||
package com.faraphel.tasks_valider.ui.screen.task
|
package com.faraphel.tasks_valider.ui.screen.task
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import com.faraphel.tasks_valider.connectivity.task.TaskClient
|
import com.faraphel.tasks_valider.connectivity.task.TaskClient
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskGroupEntity
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.reflect.TypeToken
|
|
||||||
|
|
||||||
|
|
||||||
val jsonParser = Gson()
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This screen let the user decide which student team he wants to interact with
|
* This screen represent a session
|
||||||
|
* @param activity the android activity
|
||||||
* @param client an HTTP client that can communicate with the server
|
* @param client an HTTP client that can communicate with the server
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun TaskGroupScreen(activity: Activity, client: TaskClient) {
|
fun TaskSessionScreen(activity: Activity, client: TaskClient) {
|
||||||
val groups = remember { mutableStateOf<List<TaskGroupEntity>?>(null) }
|
Text("WIP : Session Screen")
|
||||||
|
|
||||||
|
/*
|
||||||
|
val students = remember { mutableStateOf<List<TaskGroupEntity>?>(null) }
|
||||||
|
|
||||||
// title
|
// title
|
||||||
Text(text = "Task Group")
|
Text(text = "Task Group")
|
||||||
|
@ -37,9 +31,11 @@ fun TaskGroupScreen(activity: Activity, client: TaskClient) {
|
||||||
for (group in groups.value!!) {
|
for (group in groups.value!!) {
|
||||||
Text(text = group.toString())
|
Text(text = group.toString())
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
fun refreshGroups(activity: Activity, client: TaskClient, groups: MutableState<List<TaskGroupEntity>?>) {
|
fun refreshGroups(activity: Activity, client: TaskClient, groups: MutableState<List<TaskGroupEntity>?>) {
|
||||||
// try to obtain the list of groups
|
// try to obtain the list of groups
|
||||||
val response = client.get("entities/group")
|
val response = client.get("entities/group")
|
||||||
|
@ -56,3 +52,4 @@ fun refreshGroups(activity: Activity, client: TaskClient, groups: MutableState<L
|
||||||
object : TypeToken<List<TaskGroupEntity>>(){}
|
object : TypeToken<List<TaskGroupEntity>>(){}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -1,18 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.ui.widgets.task
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.GroupEntity
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun WidgetGroup(group: GroupEntity) {
|
|
||||||
// TODO
|
|
||||||
Column {
|
|
||||||
Text(text = group.name!!)
|
|
||||||
|
|
||||||
// group.tasks.forEach { task ->
|
|
||||||
// WidgetTask(task)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.ui.widgets.task
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskEntity
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun WidgetTask(task: TaskEntity) {
|
|
||||||
// task information
|
|
||||||
Column {
|
|
||||||
Text(text = task.title)
|
|
||||||
Text(text = task.description)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.faraphel.tasks_valider.ui.widgets.task
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.material3.Checkbox
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.faraphel.tasks_valider.database.TaskDatabase
|
|
||||||
import com.faraphel.tasks_valider.database.entities._old.TaskGroupEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun WidgetTaskStudent(database: TaskDatabase, taskStudent: TaskGroupEntity) {
|
|
||||||
val teacherDao = database.teacherDao()
|
|
||||||
|
|
||||||
Column {
|
|
||||||
// row for this task
|
|
||||||
Row {
|
|
||||||
// task information
|
|
||||||
// TODO: WidgetTask(task = taskStudent.task)
|
|
||||||
|
|
||||||
// align the other columns to the right
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
|
|
||||||
// task status
|
|
||||||
Checkbox(
|
|
||||||
checked = taskStudent.approvalStatus,
|
|
||||||
onCheckedChange = { status -> taskStudent.approvalStatus = status }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the task has been approved
|
|
||||||
if (taskStudent.approvalStatus) {
|
|
||||||
Row (
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
// teacher who approved the task
|
|
||||||
Text(text = teacherDao.getById(taskStudent.approvalTeacherId!!).fullName)
|
|
||||||
|
|
||||||
// align the other columns to the right
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
|
|
||||||
// date of approval
|
|
||||||
Text(text = taskStudent.approvalTime.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue