Skip to content

Commit

Permalink
remove unnecessary apis
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 23, 2024
1 parent aac0bfe commit 9da37f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,6 @@ internal class AnnouncementRepository {
}
}

suspend fun archive(
id: Int,
archivedAt: LocalDateTime?,
) = transaction {
Announcement.findByIdAndUpdate(id) {
it.archivedAt = archivedAt ?: java.time.LocalDateTime.now().toKotlinLocalDateTime()
}?.let(::updateLatestAnnouncement)
}

suspend fun unarchive(id: Int) = transaction {
Announcement.findByIdAndUpdate(id) {
it.archivedAt = null
}?.let(::updateLatestAnnouncement) ?: Unit
}

suspend fun tags() = transaction {
Tag.all().toList().toApiTag()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import app.revanced.api.configuration.installCache
import app.revanced.api.configuration.installNotarizedRoute
import app.revanced.api.configuration.respondOrNotFound
import app.revanced.api.configuration.schema.ApiAnnouncement
import app.revanced.api.configuration.schema.ApiAnnouncementArchivedAt
import app.revanced.api.configuration.schema.ApiResponseAnnouncement
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
import app.revanced.api.configuration.services.AnnouncementService
Expand Down Expand Up @@ -105,27 +104,6 @@ internal fun Route.announcementsRoute() = route("announcements") {
}
}

route("archive") {
installAnnouncementsArchiveRouteDocumentation()

post {
val id: Int by call.parameters
val archivedAt = call.receiveNullable<ApiAnnouncementArchivedAt>()?.archivedAt

announcementService.archive(id, archivedAt)

call.respond(HttpStatusCode.OK)
}

delete {
val id: Int by call.parameters

announcementService.unarchive(id)

call.respond(HttpStatusCode.OK)
}
}

route("tags") {
installAnnouncementsTagsRouteDocumentation()

Expand Down Expand Up @@ -324,52 +302,6 @@ private fun Route.installAnnouncementsIdRouteDocumentation() = installNotarizedR
}
}

private fun Route.installAnnouncementsArchiveRouteDocumentation() = installNotarizedRoute {
tags = setOf("Announcements")

parameters = listOf(
Parameter(
name = "id",
`in` = Parameter.Location.path,
schema = TypeDefinition.INT,
description = "The ID of the announcement to archive",
required = true,
),
authHeaderParameter,
)

post = PostInfo.builder {
description("Archive an announcement")
summary("Archive announcement")
parameters(
Parameter(
name = "archivedAt",
`in` = Parameter.Location.query,
schema = TypeDefinition.STRING,
description = "The date and time the announcement to be archived",
required = false,
),
)
response {
description("The announcement is archived")
responseCode(HttpStatusCode.OK)
responseType<Unit>()
}
canRespondUnauthorized()
}

delete = DeleteInfo.builder {
description("Unarchive an announcement")
summary("Unarchive announcement")
response {
description("The announcement is unarchived")
responseCode(HttpStatusCode.OK)
responseType<Unit>()
}
canRespondUnauthorized()
}
}

private fun Route.installAnnouncementsTagsRouteDocumentation() = installNotarizedRoute {
tags = setOf("Announcements")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.revanced.api.configuration.services

import app.revanced.api.configuration.repository.AnnouncementRepository
import app.revanced.api.configuration.schema.ApiAnnouncement
import kotlinx.datetime.LocalDateTime

internal class AnnouncementService(
private val announcementRepository: AnnouncementRepository,
Expand All @@ -25,9 +24,5 @@ internal class AnnouncementService(

suspend fun new(new: ApiAnnouncement) = announcementRepository.new(new)

suspend fun archive(id: Int, archivedAt: LocalDateTime?) = announcementRepository.archive(id, archivedAt)

suspend fun unarchive(id: Int) = announcementRepository.unarchive(id)

suspend fun tags() = announcementRepository.tags()
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ private object AnnouncementServiceTest {
@Test
fun `archiving works properly`() = runBlocking {
announcementService.new(ApiAnnouncement(title = "title"))
val latestId = announcementService.latestId()!!.id

announcementService.archive(latestId, LocalDateTime.now().toKotlinLocalDateTime())
assertNotNull(announcementService.get(latestId)?.archivedAt)
val latest = announcementService.latest()!!
assertNull(announcementService.get(latest.id)?.archivedAt)

val updated = ApiAnnouncement(
title = latest.title,
archivedAt = LocalDateTime.now().toKotlinLocalDateTime(),
)

announcementService.update(latest.id, updated)
assertNotNull(announcementService.get(latest.id)?.archivedAt)

announcementService.unarchive(latestId)
assertNull(announcementService.get(latestId)?.archivedAt)
return@runBlocking
}

@Test
Expand Down

0 comments on commit 9da37f1

Please sign in to comment.