mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-12 06:16:19 +00:00
Compare commits
10 Commits
v1.5.0-dev
...
v1.6.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
712ab3be8c | ||
|
|
db22874f06 | ||
|
|
5d5533a920 | ||
|
|
7f6e29de52 | ||
|
|
48469d32c2 | ||
|
|
7f9159fef1 | ||
|
|
b063b4daf2 | ||
|
|
58ba4cb11c | ||
|
|
55e3774f07 | ||
|
|
d5d9e04325 |
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,3 +1,42 @@
|
||||
# [1.6.0-dev.2](https://github.com/ReVanced/revanced-api/compare/v1.6.0-dev.1...v1.6.0-dev.2) (2024-12-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Make some announcements schema fields nullable ([db22874](https://github.com/ReVanced/revanced-api/commit/db22874f063bae0c9e7f0c99a20cdf1b16addd89))
|
||||
|
||||
# [1.6.0-dev.1](https://github.com/ReVanced/revanced-api/compare/v1.5.0...v1.6.0-dev.1) (2024-11-23)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Allow setting `Announcement.createdAt` when creating an announcement ([7f6e29d](https://github.com/ReVanced/revanced-api/commit/7f6e29de5205f63ac4aaea490c844b58e14000c8))
|
||||
|
||||
# [1.5.0](https://github.com/ReVanced/revanced-api/compare/v1.4.0...v1.5.0) (2024-11-06)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Allow updating `createdAt` field for announcements ([58ba4cb](https://github.com/ReVanced/revanced-api/commit/58ba4cb11c789507826cd70ac548943a94da4223))
|
||||
* Move spec url to versioned path ([e871b23](https://github.com/ReVanced/revanced-api/commit/e871b23210798723c34bce93c7567d8fbcf4e060))
|
||||
* Simplify log pattern ([d5d9e04](https://github.com/ReVanced/revanced-api/commit/d5d9e04325fa93540be0438e7b51243e2aeeab3d))
|
||||
|
||||
# [1.5.0-dev.2](https://github.com/ReVanced/revanced-api/compare/v1.5.0-dev.1...v1.5.0-dev.2) (2024-11-06)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Allow updating `createdAt` field for announcements ([58ba4cb](https://github.com/ReVanced/revanced-api/commit/58ba4cb11c789507826cd70ac548943a94da4223))
|
||||
* Simplify log pattern ([d5d9e04](https://github.com/ReVanced/revanced-api/commit/d5d9e04325fa93540be0438e7b51243e2aeeab3d))
|
||||
|
||||
# [1.5.0-dev.1](https://github.com/ReVanced/revanced-api/compare/v1.4.0...v1.5.0-dev.1) (2024-11-06)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Move spec url to versioned path ([e871b23](https://github.com/ReVanced/revanced-api/commit/e871b23210798723c34bce93c7567d8fbcf4e060))
|
||||
* Simplify log pattern ([d5d9e04](https://github.com/ReVanced/revanced-api/commit/d5d9e04325fa93540be0438e7b51243e2aeeab3d))
|
||||
|
||||
# [1.5.0-dev.1](https://github.com/ReVanced/revanced-api/compare/v1.4.0...v1.5.0-dev.1) (2024-11-06)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
org.gradle.parallel = true
|
||||
org.gradle.caching = true
|
||||
kotlin.code.style = official
|
||||
version = 1.5.0-dev.1
|
||||
version = 1.6.0-dev.2
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package app.revanced.api.configuration
|
||||
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
interface ApiUser {
|
||||
@@ -60,9 +63,10 @@ class ApiAnnouncement(
|
||||
val title: String,
|
||||
val content: String? = null,
|
||||
// Using a list instead of a set because set semantics are unnecessary here.
|
||||
val attachments: List<String> = emptyList(),
|
||||
val attachments: List<String>? = null,
|
||||
// Using a list instead of a set because set semantics are unnecessary here.
|
||||
val tags: List<String> = emptyList(),
|
||||
val tags: List<String>? = null,
|
||||
val createdAt: LocalDateTime = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()),
|
||||
val archivedAt: LocalDateTime? = null,
|
||||
val level: Int = 0,
|
||||
)
|
||||
@@ -74,9 +78,9 @@ class ApiResponseAnnouncement(
|
||||
val title: String,
|
||||
val content: String? = null,
|
||||
// Using a list instead of a set because set semantics are unnecessary here.
|
||||
val attachments: List<String> = emptyList(),
|
||||
val attachments: List<String>? = null,
|
||||
// Using a list instead of a set because set semantics are unnecessary here.
|
||||
val tags: List<String> = emptyList(),
|
||||
val tags: List<String>? = null,
|
||||
val createdAt: LocalDateTime,
|
||||
val archivedAt: LocalDateTime? = null,
|
||||
val level: Int = 0,
|
||||
|
||||
@@ -69,8 +69,7 @@ internal class AnnouncementRepository(private val database: Database) {
|
||||
|
||||
fun latestId() = latestAnnouncement?.id?.value.toApiResponseAnnouncementId()
|
||||
|
||||
fun latestId(tags: Set<String>) =
|
||||
tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
|
||||
fun latestId(tags: Set<String>) = tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
|
||||
|
||||
suspend fun paged(cursor: Int, count: Int, tags: Set<String>?) = transaction {
|
||||
Announcement.find {
|
||||
@@ -100,13 +99,16 @@ internal class AnnouncementRepository(private val database: Database) {
|
||||
author = new.author
|
||||
title = new.title
|
||||
content = new.content
|
||||
createdAt = new.createdAt
|
||||
archivedAt = new.archivedAt
|
||||
level = new.level
|
||||
tags = SizedCollection(
|
||||
new.tags.map { tag -> Tag.find { Tags.name eq tag }.firstOrNull() ?: Tag.new { name = tag } },
|
||||
)
|
||||
if (new.tags != null) {
|
||||
tags = SizedCollection(
|
||||
new.tags.map { tag -> Tag.find { Tags.name eq tag }.firstOrNull() ?: Tag.new { name = tag } },
|
||||
)
|
||||
}
|
||||
}.apply {
|
||||
new.attachments.map { attachmentUrl ->
|
||||
new.attachments?.map { attachmentUrl ->
|
||||
Attachment.new {
|
||||
url = attachmentUrl
|
||||
announcement = this@apply
|
||||
@@ -120,27 +122,32 @@ internal class AnnouncementRepository(private val database: Database) {
|
||||
it.author = new.author
|
||||
it.title = new.title
|
||||
it.content = new.content
|
||||
it.createdAt = new.createdAt
|
||||
it.archivedAt = new.archivedAt
|
||||
it.level = new.level
|
||||
|
||||
// Get the old tags, create new tags if they don't exist,
|
||||
// and delete tags that are not in the new tags, after updating the announcement.
|
||||
val oldTags = it.tags.toList()
|
||||
val updatedTags = new.tags.map { name ->
|
||||
Tag.find { Tags.name eq name }.firstOrNull() ?: Tag.new { this.name = name }
|
||||
}
|
||||
it.tags = SizedCollection(updatedTags)
|
||||
oldTags.forEach { tag ->
|
||||
if (tag in updatedTags || !tag.announcements.empty()) return@forEach
|
||||
tag.delete()
|
||||
if (new.tags != null) {
|
||||
// Get the old tags, create new tags if they don't exist,
|
||||
// and delete tags that are not in the new tags, after updating the announcement.
|
||||
val oldTags = it.tags.toList()
|
||||
val updatedTags = new.tags.map { name ->
|
||||
Tag.find { Tags.name eq name }.firstOrNull() ?: Tag.new { this.name = name }
|
||||
}
|
||||
it.tags = SizedCollection(updatedTags)
|
||||
oldTags.forEach { tag ->
|
||||
if (tag in updatedTags || !tag.announcements.empty()) return@forEach
|
||||
tag.delete()
|
||||
}
|
||||
}
|
||||
|
||||
// Delete old attachments and create new attachments.
|
||||
it.attachments.forEach { attachment -> attachment.delete() }
|
||||
new.attachments.map { attachment ->
|
||||
Attachment.new {
|
||||
url = attachment
|
||||
announcement = it
|
||||
if (new.attachments != null) {
|
||||
it.attachments.forEach { attachment -> attachment.delete() }
|
||||
new.attachments.map { attachment ->
|
||||
Attachment.new {
|
||||
url = attachment
|
||||
announcement = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}?.let(::updateLatestAnnouncement) ?: Unit
|
||||
@@ -173,8 +180,7 @@ internal class AnnouncementRepository(private val database: Database) {
|
||||
Tag.all().toList().toApiTag()
|
||||
}
|
||||
|
||||
private suspend fun <T> transaction(statement: suspend Transaction.() -> T) =
|
||||
newSuspendedTransaction(Dispatchers.IO, database, statement = statement)
|
||||
private suspend fun <T> transaction(statement: suspend Transaction.() -> T) = newSuspendedTransaction(Dispatchers.IO, database, statement = statement)
|
||||
|
||||
private object Announcements : IntIdTable() {
|
||||
val author = varchar("author", 32).nullable()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="\${LOG_LEVEL:-INFO}">
|
||||
|
||||
@@ -135,7 +135,7 @@ private object AnnouncementServiceTest {
|
||||
val latestAnnouncement = announcementService.latest()!!
|
||||
val latestId = latestAnnouncement.id
|
||||
|
||||
val attachments = latestAnnouncement.attachments
|
||||
val attachments = latestAnnouncement.attachments!!
|
||||
assertEquals(2, attachments.size)
|
||||
assert(attachments.any { it == "attachment1" })
|
||||
assert(attachments.any { it == "attachment2" })
|
||||
@@ -144,7 +144,7 @@ private object AnnouncementServiceTest {
|
||||
latestId,
|
||||
ApiAnnouncement(title = "title", attachments = listOf("attachment1", "attachment3")),
|
||||
)
|
||||
assert(announcementService.get(latestId)!!.attachments.any { it == "attachment3" })
|
||||
assert(announcementService.get(latestId)!!.attachments!!.any { it == "attachment3" })
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user