Skip to content

Commit

Permalink
Add out of office delete endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
terolaakso committed Dec 27, 2024
1 parent d0d7d73 commit 8856e85
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,15 @@ class OutOfOfficeIntegrationTest : FullApplicationTest(resetDbBeforeEach = true)
val updatedPeriods =
outOfOfficeController.getOutOfOfficePeriods(dbInstance(), employee, clock)
assertEquals(listOf(updatedPeriod.period), updatedPeriods.map { it.period })

outOfOfficeController.deleteOutOfOfficePeriod(
dbInstance(),
employee,
clock,
updatedPeriod.id!!,
)
val deletedPeriods =
outOfOfficeController.getOutOfOfficePeriods(dbInstance(), employee, clock)
assertEquals(0, deletedPeriods.size)
}
}
1 change: 1 addition & 0 deletions service/src/main/kotlin/fi/espoo/evaka/Audit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ enum class Audit(
OtherAssistanceMeasureDelete,
OutOfOfficeRead,
OutOfOfficeUpdate,
OutOfOfficeDelete,
PairingInit(securityEvent = true),
PairingChallenge(securityEvent = true),
PairingResponse(securityEvent = true, securityLevel = "high"),
Expand Down
12 changes: 12 additions & 0 deletions service/src/main/kotlin/fi/espoo/evaka/outofoffice/OutOfOffice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ WHERE id = ${bind(period.id)}
.updateExactlyOne()
}
}

fun Database.Transaction.deleteOutOfOfficePeriod(id: OutOfOfficeId) {
createUpdate {
sql(
"""
DELETE FROM out_of_office
WHERE id = ${bind(id)}
"""
)
}
.updateExactlyOne()
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package fi.espoo.evaka.outofoffice

import fi.espoo.evaka.Audit
import fi.espoo.evaka.shared.OutOfOfficeId
import fi.espoo.evaka.shared.auth.AuthenticatedUser
import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.domain.BadRequest
import fi.espoo.evaka.shared.domain.EvakaClock
import fi.espoo.evaka.shared.security.AccessControl
import fi.espoo.evaka.shared.security.Action
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController

Expand Down Expand Up @@ -62,4 +65,26 @@ class OutOfOfficeController(private val accessControl: AccessControl) {
}
.also { Audit.OutOfOfficeUpdate.log(targetId = fi.espoo.evaka.AuditId(user.id)) }
}

@DeleteMapping("/employee/out-of-office/{id}")
fun deleteOutOfOfficePeriod(
db: Database,
user: AuthenticatedUser.Employee,
clock: EvakaClock,
@PathVariable id: OutOfOfficeId,
) {
return db.connect { dbc ->
dbc.transaction {
accessControl.requirePermissionFor(
it,
user,
clock,
Action.Employee.UPDATE_OUT_OF_OFFICE,
user.id,
)
it.deleteOutOfOfficePeriod(id = id)
}
}
.also { Audit.OutOfOfficeDelete.log(targetId = fi.espoo.evaka.AuditId(user.id)) }
}
}

0 comments on commit 8856e85

Please sign in to comment.