Skip to content

Commit 8ad614e

Browse files
committed
feat: Remove "archived" query parameter
It doesn't seem to be necessary for the purpose of viewing announcements.
1 parent fc40427 commit 8ad614e

File tree

4 files changed

+11
-36
lines changed

4 files changed

+11
-36
lines changed

src/main/kotlin/app/revanced/api/configuration/repository/AnnouncementRepository.kt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import app.revanced.api.configuration.schema.ApiResponseAnnouncement
66
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
77
import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.runBlocking
9-
import kotlinx.datetime.toKotlinLocalDateTime
109
import org.jetbrains.exposed.dao.IntEntity
1110
import org.jetbrains.exposed.dao.IntEntityClass
1211
import org.jetbrains.exposed.dao.id.EntityID
@@ -15,7 +14,6 @@ import org.jetbrains.exposed.sql.*
1514
import org.jetbrains.exposed.sql.kotlin.datetime.CurrentDateTime
1615
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
1716
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
18-
import java.time.LocalDateTime
1917

2018
internal class AnnouncementRepository(private val database: Database) {
2119
// This is better than doing a maxByOrNull { it.id } on every request.
@@ -74,33 +72,21 @@ internal class AnnouncementRepository(private val database: Database) {
7472
fun latestId(tags: Set<String>) =
7573
tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
7674

77-
suspend fun paged(cursor: Int, count: Int, tags: Set<String>?, archived: Boolean) = transaction {
75+
suspend fun paged(cursor: Int, count: Int, tags: Set<String>?) = transaction {
7876
Announcement.find {
7977
fun idLessEq() = Announcements.id lessEq cursor
80-
fun archivedAtIsNull() = Announcements.archivedAt.isNull()
81-
fun archivedAtGreaterNow() = Announcements.archivedAt greater LocalDateTime.now().toKotlinLocalDateTime()
8278

8379
if (tags == null) {
84-
if (archived) {
85-
idLessEq()
86-
} else {
87-
idLessEq() and (archivedAtIsNull() or archivedAtGreaterNow())
88-
}
80+
idLessEq()
8981
} else {
90-
fun archivedAtGreaterOrNullOrTrue() = if (archived) {
91-
Op.TRUE
92-
} else {
93-
archivedAtIsNull() or archivedAtGreaterNow()
94-
}
95-
9682
fun hasTags() = Announcements.id inSubQuery (
97-
Tags.innerJoin(AnnouncementTags)
83+
AnnouncementTags.innerJoin(Tags)
9884
.select(AnnouncementTags.announcement)
99-
.where { Tags.name inList tags }
10085
.withDistinct()
86+
.where { Tags.name inList tags }
10187
)
10288

103-
idLessEq() and archivedAtGreaterOrNullOrTrue() and hasTags()
89+
idLessEq() and hasTags()
10490
}
10591
}.orderBy(Announcements.id to SortOrder.DESC).limit(count).toApiAnnouncement()
10692
}

src/main/kotlin/app/revanced/api/configuration/routes/Announcements.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ internal fun Route.announcementsRoute() = route("announcements") {
3636
val cursor = call.parameters["cursor"]?.toInt() ?: Int.MAX_VALUE
3737
val count = call.parameters["count"]?.toInt() ?: 16
3838
val tags = call.parameters.getAll("tag")
39-
val archived = call.parameters["archived"]?.toBoolean() ?: true
4039

41-
call.respond(announcementService.paged(cursor, count, tags?.toSet(), archived))
40+
call.respond(announcementService.paged(cursor, count, tags?.toSet()))
4241
}
4342
}
4443

@@ -153,13 +152,6 @@ private fun Route.installAnnouncementsRouteDocumentation() = installNotarizedRou
153152
description = "The tags to filter the announcements by. Default is all tags",
154153
required = false,
155154
),
156-
Parameter(
157-
name = "archived",
158-
`in` = Parameter.Location.query,
159-
schema = TypeDefinition.BOOLEAN,
160-
description = "Whether to include archived announcements. Default is true",
161-
required = false,
162-
),
163155
)
164156
response {
165157
responseCode(HttpStatusCode.OK)

src/main/kotlin/app/revanced/api/configuration/services/AnnouncementService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal class AnnouncementService(
1414

1515
fun latestId() = announcementRepository.latestId()
1616

17-
suspend fun paged(cursor: Int, limit: Int, tags: Set<String>?, archived: Boolean) =
18-
announcementRepository.paged(cursor, limit, tags, archived)
17+
suspend fun paged(cursor: Int, limit: Int, tags: Set<String>?) =
18+
announcementRepository.paged(cursor, limit, tags)
1919

2020
suspend fun get(id: Int) = announcementRepository.get(id)
2121

src/test/kotlin/app/revanced/api/configuration/services/AnnouncementServiceTest.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private object AnnouncementServiceTest {
153153
announcementService.new(ApiAnnouncement(title = "title$it"))
154154
}
155155

156-
val announcements = announcementService.paged(Int.MAX_VALUE, 5, null, true)
156+
val announcements = announcementService.paged(Int.MAX_VALUE, 5, null)
157157
assertEquals(5, announcements.size, "Returns correct number of announcements")
158158
assertEquals("title9", announcements.first().title, "Starts from the latest announcement")
159159

160-
val announcements2 = announcementService.paged(5, 5, null, true)
160+
val announcements2 = announcementService.paged(5, 5, null)
161161
assertEquals(5, announcements2.size, "Returns correct number of announcements when starting from the cursor")
162162
assertEquals("title4", announcements2.first().title, "Starts from the cursor")
163163

@@ -180,10 +180,7 @@ private object AnnouncementServiceTest {
180180
val tags = announcementService.tags()
181181
assertEquals(5, tags.size, "Returns correct number of newly created tags")
182182

183-
val announcements3 = announcementService.paged(5, 5, setOf(tags[1].name), true)
183+
val announcements3 = announcementService.paged(5, 5, setOf(tags[1].name))
184184
assertEquals(4, announcements3.size, "Filters announcements by tag")
185-
186-
val announcements4 = announcementService.paged(Int.MAX_VALUE, 10, null, false)
187-
assertEquals(8, announcements4.size, "Filters out archived announcements")
188185
}
189186
}

0 commit comments

Comments
 (0)