[API/Vulcan] Force presence of a TeamClass.

This commit is contained in:
Kuba Szczodrzyński 2021-10-30 21:51:19 +02:00
parent cb953ea8a8
commit 519d75d9d9
3 changed files with 40 additions and 34 deletions

View File

@ -22,7 +22,6 @@ import pl.szczodrzynski.edziennik.data.api.models.ApiError
import pl.szczodrzynski.edziennik.data.db.entity.LessonRange
import pl.szczodrzynski.edziennik.data.db.entity.Subject
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
import pl.szczodrzynski.edziennik.data.db.entity.Team
import pl.szczodrzynski.edziennik.ext.*
import pl.szczodrzynski.edziennik.utils.Utils.d
import pl.szczodrzynski.edziennik.utils.models.Date
@ -91,41 +90,31 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
fun getTeamId(json: JsonObject?, key: String): Long? {
val team = json.getJsonObject(key)
val teamId = team.getLong("Id") ?: return null
if (data.teamList[teamId] == null) {
var name = team.getString("Shortcut")
val teamId = team.getLong("Id")
var teamName = team.getString("Shortcut")
?: team.getString("Name")
?: ""
name = "${profile?.studentClassName ?: ""} $name"
data.teamList[teamId] = Team(
data.profileId,
teamId,
name,
Team.TYPE_VIRTUAL,
"${data.schoolCode}:$name",
-1
)
}
return teamId
teamName = "${profile?.studentClassName ?: ""} $teamName"
return data.getTeam(
id = teamId,
name = teamName,
schoolCode = data.schoolCode ?: "",
isTeamClass = false,
).id
}
fun getClassId(json: JsonObject?, key: String): Long? {
val team = json.getJsonObject(key)
val teamId = team.getLong("Id") ?: return null
if (data.teamList[teamId] == null) {
val name = data.profile?.studentClassName
val teamId = team.getLong("Id")
val teamName = data.profile?.studentClassName
?: team.getString("Name")
?: ""
data.teamList[teamId] = Team(
data.profileId,
teamId,
name,
Team.TYPE_CLASS,
"${data.schoolCode}:$name",
-1
)
}
return teamId
return data.getTeam(
id = teamId,
name = teamName,
schoolCode = data.schoolCode ?: "",
isTeamClass = true,
).id
}
fun getLessonRange(json: JsonObject?, key: String): LessonRange? {

View File

@ -151,6 +151,15 @@ class VulcanHebeMain(
studentData["senderAddressName"] = senderAddressName
studentData["senderAddressHash"] = senderAddressHash
studentData["hebeContext"] = hebeContext
// create the default TeamClass
data.getTeam(
id = null,
name = studentClassName,
schoolCode = schoolCode,
isTeamClass = true,
profileId = this.id,
)
}
dateSemester1Start?.let {
newProfile.dateSemester1Start = it

View File

@ -406,7 +406,13 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
return subject
}
fun getTeam(id: Long?, name: String, schoolCode: String, isTeamClass: Boolean = false): Team {
fun getTeam(
id: Long?,
name: String,
schoolCode: String,
isTeamClass: Boolean = false,
profileId: Int? = null,
): Team {
if (isTeamClass && teamClass != null)
return teamClass as Team
var team = teamList.singleOrNull { it.id == id }
@ -417,7 +423,7 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
if (team == null) {
team = Team(
profileId,
profileId ?: this.profileId,
id ?: name.crc32(),
name,
if (isTeamClass) Team.TYPE_CLASS else Team.TYPE_VIRTUAL,
@ -425,6 +431,8 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
-1
)
teamList[team.id] = team
} else if (id != null) {
team.id = id
}
return team
}