Skip to content

Commit

Permalink
Remove submit diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Isti01 committed Oct 2, 2024
1 parent c43c953 commit 5573469
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 107 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package hu.bme.sch.cmsch.component.form

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import hu.bme.sch.cmsch.component.app.DebugComponent
import hu.bme.sch.cmsch.component.login.CmschUser
import hu.bme.sch.cmsch.extending.FormSubmissionListener
import hu.bme.sch.cmsch.model.RoleType
Expand All @@ -26,7 +24,6 @@ open class FormService(
private val responseRepository: ResponseRepository,
private val userRepository: UserRepository,
private val clock: TimeService,
private val debugComponent: DebugComponent,
private val listeners: MutableList<out FormSubmissionListener>,
private val formComponent: FormComponent,
) {
Expand Down Expand Up @@ -62,7 +59,7 @@ open class FormService(
if ((form.minRole.value > user.role.value || form.maxRole.value < user.role.value) && !user.role.isAdmin)
return FormView(status = FormStatus.NOT_FOUND)

val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
val now = clock.getTimeInSeconds()
if (!form.open)
return FormView(status = FormStatus.NOT_ENABLED)
if (form.availableFrom > now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class TaskApiController(
when (startupPropertyConfig.taskOwnershipMode) {
OwnershipType.USER -> {
user ?: return TasksView()
categories = tasks.getCategoriesForUserInTimeRange(user.id, clock.getNowInSeconds(), user.role)
categories = tasks.getCategoriesForUserInTimeRange(user.id, clock.getTimeInSeconds(), user.role)

return TasksView(
categories = categories
.filter { clock.inRange(it.availableFrom, it.availableTo, clock.getNowInSeconds()) },
.filter { clock.inRange(it.availableFrom, it.availableTo, clock.getTimeInSeconds()) },
)
}
OwnershipType.GROUP -> {
val groupId = user?.groupId ?: return TasksView( )
categories = tasks.getCategoriesForGroupInRange(groupId, clock.getNowInSeconds(), userRole = user.role)
categories = tasks.getCategoriesForGroupInRange(groupId, clock.getTimeInSeconds(), userRole = user.role)

return TasksView(
categories = categories
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hu.bme.sch.cmsch.component.task

import hu.bme.sch.cmsch.component.app.DebugComponent
import hu.bme.sch.cmsch.component.login.CmschUser
import hu.bme.sch.cmsch.extending.TaskSubmissionListener
import hu.bme.sch.cmsch.model.RoleType
Expand Down Expand Up @@ -29,7 +28,6 @@ open class TasksService(
private val categories: TaskCategoryRepository,
private val clock: TimeService,
private val taskComponent: TaskComponent,
private val debugComponent: DebugComponent,
private val listeners: List<TaskSubmissionListener>,
private val userRepository: UserRepository,
private val groupRepository: GroupRepository
Expand Down Expand Up @@ -191,7 +189,7 @@ open class TasksService(
val task = taskRepository.findById(answer.taskId).orElse(null)
?: return TaskSubmissionStatus.INVALID_TASK_ID

val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
val now = clock.getTimeInSeconds()
if (task.availableFrom > now || task.availableTo < now) {
return TaskSubmissionStatus.TOO_EARLY_OR_LATE
}
Expand Down Expand Up @@ -219,7 +217,7 @@ open class TasksService(
val task = taskRepository.findById(answer.taskId).orElse(null)
?: return TaskSubmissionStatus.INVALID_TASK_ID

val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
val now = clock.getTimeInSeconds()
if (task.availableFrom > now || task.availableTo < now) {
return TaskSubmissionStatus.TOO_EARLY_OR_LATE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ open class TeamService(

private fun mapTasks(team: GroupEntity, user: CmschUser): List<TaskCategoryPreview> {
return tasksService.map { tasks ->
tasks.getCategoriesForGroupInRange(team.id, clock.getNowInSeconds(), advertisedOnly = true, user.role)
tasks.getCategoriesForGroupInRange(team.id, clock.getTimeInSeconds(), advertisedOnly = true, user.role)
.map { TaskCategoryPreview(
name = it.name,
completed = it.approved,
Expand Down
21 changes: 4 additions & 17 deletions backend/src/main/kotlin/hu/bme/sch/cmsch/service/TimeService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hu.bme.sch.cmsch.service

import hu.bme.sch.cmsch.component.app.DebugComponent
import hu.bme.sch.cmsch.config.StartupPropertyConfig
import org.springframework.stereotype.Service
import java.time.ZoneId
Expand All @@ -9,10 +8,7 @@ import java.time.format.DateTimeFormatter
import java.util.*

@Service
class TimeService(
startupPropertyConfig: StartupPropertyConfig,
private val debugComponent: DebugComponent
) {
class TimeService(startupPropertyConfig: StartupPropertyConfig) {

val timeZone: ZoneId = Objects.requireNonNull(ZoneId.of(startupPropertyConfig.zoneId), "Invalid time zone")
private val sqlDateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
Expand All @@ -21,19 +17,10 @@ class TimeService(

fun getTime() = ZonedDateTime.now(timeZone)?.toInstant()?.toEpochMilli() ?: 0

fun inRange(availableFrom: Long, availableTo: Long, timeInSeconds: Long): Boolean {
val now = timeInSeconds + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
return now in availableFrom..availableTo
}
fun inRange(availableFrom: Long, availableTo: Long, timeInSeconds: Long): Boolean =
timeInSeconds in availableFrom..availableTo

fun isTimePassed(timeToBeAfter: Long, timeInSeconds: Long): Boolean {
val now = timeInSeconds + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
return now > timeToBeAfter
}

fun getNowInSeconds(): Long {
return getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0)
}
fun isTimePassed(timeToBeAfter: Long, timeInSeconds: Long): Boolean = timeInSeconds > timeToBeAfter

fun todayInSqlFormat(): String = ZonedDateTime.now(timeZone).format(sqlDateFormatter)

Expand Down

0 comments on commit 5573469

Please sign in to comment.