@@ -69,8 +69,7 @@ internal class AnnouncementRepository(private val database: Database) {
69
69
70
70
fun latestId () = latestAnnouncement?.id?.value.toApiResponseAnnouncementId()
71
71
72
- fun latestId (tags : Set <String >) =
73
- tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
72
+ fun latestId (tags : Set <String >) = tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
74
73
75
74
suspend fun paged (cursor : Int , count : Int , tags : Set <String >? ) = transaction {
76
75
Announcement .find {
@@ -103,11 +102,13 @@ internal class AnnouncementRepository(private val database: Database) {
103
102
createdAt = new.createdAt
104
103
archivedAt = new.archivedAt
105
104
level = new.level
106
- tags = SizedCollection (
107
- new.tags.map { tag -> Tag .find { Tags .name eq tag }.firstOrNull() ? : Tag .new { name = tag } },
108
- )
105
+ if (new.tags != null ) {
106
+ tags = SizedCollection (
107
+ new.tags.map { tag -> Tag .find { Tags .name eq tag }.firstOrNull() ? : Tag .new { name = tag } },
108
+ )
109
+ }
109
110
}.apply {
110
- new.attachments.map { attachmentUrl ->
111
+ new.attachments? .map { attachmentUrl ->
111
112
Attachment .new {
112
113
url = attachmentUrl
113
114
announcement = this @apply
@@ -125,24 +126,28 @@ internal class AnnouncementRepository(private val database: Database) {
125
126
it.archivedAt = new.archivedAt
126
127
it.level = new.level
127
128
128
- // Get the old tags, create new tags if they don't exist,
129
- // and delete tags that are not in the new tags, after updating the announcement.
130
- val oldTags = it.tags.toList()
131
- val updatedTags = new.tags.map { name ->
132
- Tag .find { Tags .name eq name }.firstOrNull() ? : Tag .new { this .name = name }
133
- }
134
- it.tags = SizedCollection (updatedTags)
135
- oldTags.forEach { tag ->
136
- if (tag in updatedTags || ! tag.announcements.empty()) return @forEach
137
- tag.delete()
129
+ if (new.tags != null ) {
130
+ // Get the old tags, create new tags if they don't exist,
131
+ // and delete tags that are not in the new tags, after updating the announcement.
132
+ val oldTags = it.tags.toList()
133
+ val updatedTags = new.tags.map { name ->
134
+ Tag .find { Tags .name eq name }.firstOrNull() ? : Tag .new { this .name = name }
135
+ }
136
+ it.tags = SizedCollection (updatedTags)
137
+ oldTags.forEach { tag ->
138
+ if (tag in updatedTags || ! tag.announcements.empty()) return @forEach
139
+ tag.delete()
140
+ }
138
141
}
139
142
140
143
// Delete old attachments and create new attachments.
141
- it.attachments.forEach { attachment -> attachment.delete() }
142
- new.attachments.map { attachment ->
143
- Attachment .new {
144
- url = attachment
145
- announcement = it
144
+ if (new.attachments != null ) {
145
+ it.attachments.forEach { attachment -> attachment.delete() }
146
+ new.attachments.map { attachment ->
147
+ Attachment .new {
148
+ url = attachment
149
+ announcement = it
150
+ }
146
151
}
147
152
}
148
153
}?.let (::updateLatestAnnouncement) ? : Unit
@@ -175,8 +180,7 @@ internal class AnnouncementRepository(private val database: Database) {
175
180
Tag .all().toList().toApiTag()
176
181
}
177
182
178
- private suspend fun <T > transaction (statement : suspend Transaction .() -> T ) =
179
- newSuspendedTransaction(Dispatchers .IO , database, statement = statement)
183
+ private suspend fun <T > transaction (statement : suspend Transaction .() -> T ) = newSuspendedTransaction(Dispatchers .IO , database, statement = statement)
180
184
181
185
private object Announcements : IntIdTable() {
182
186
val author = varchar(" author" , 32 ).nullable()
0 commit comments