refactor: 一部のAPのJSONマッピング用のPOJOをNull-safeに

This commit is contained in:
usbharu 2023-11-28 10:44:54 +09:00
parent e2f355f4d3
commit 6c2d5dae94
2 changed files with 8 additions and 9 deletions

View File

@ -3,10 +3,10 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Note : Object { open class Note : Object {
var attributedTo: String? = null lateinit var attributedTo: String
var attachment: List<Document> = emptyList() var attachment: List<Document> = emptyList()
var content: String? = null lateinit var content: String
var published: String? = null lateinit var published: String
var to: List<String> = emptyList() var to: List<String> = emptyList()
var cc: List<String> = emptyList() var cc: List<String> = emptyList()
var sensitive: Boolean = false var sensitive: Boolean = false
@ -19,9 +19,9 @@ open class Note : Object {
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, name: String,
id: String?, id: String?,
attributedTo: String?, attributedTo: String,
content: String?, content: String,
published: String?, published: String,
to: List<String> = emptyList(), to: List<String> = emptyList(),
cc: List<String> = emptyList(), cc: List<String> = emptyList(),
sensitive: Boolean = false, sensitive: Boolean = false,

View File

@ -1,7 +1,6 @@
package dev.usbharu.hideout.activitypub.service.objects.note package dev.usbharu.hideout.activitypub.service.objects.note
import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
import dev.usbharu.hideout.activitypub.domain.model.Note import dev.usbharu.hideout.activitypub.domain.model.Note
import dev.usbharu.hideout.activitypub.query.NoteQueryService import dev.usbharu.hideout.activitypub.query.NoteQueryService
import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService
@ -99,7 +98,7 @@ class APNoteServiceImpl(
private suspend fun saveNote(note: Note, targetActor: String?, url: String): Note { private suspend fun saveNote(note: Note, targetActor: String?, url: String): Note {
val person = apUserService.fetchPersonWithEntity( val person = apUserService.fetchPersonWithEntity(
note.attributedTo ?: throw IllegalActivityPubObjectException("note.attributedTo is null"), note.attributedTo,
targetActor targetActor
) )
@ -142,7 +141,7 @@ class APNoteServiceImpl(
postBuilder.of( postBuilder.of(
id = postRepository.generateId(), id = postRepository.generateId(),
userId = person.second.id, userId = person.second.id,
text = note.content.orEmpty(), text = note.content,
createdAt = Instant.parse(note.published).toEpochMilli(), createdAt = Instant.parse(note.published).toEpochMilli(),
visibility = visibility, visibility = visibility,
url = note.id ?: url, url = note.id ?: url,