Skip to content

Commit a33ec67

Browse files
authored
Add Identity interface (#62)
1 parent 7ad9941 commit a33ec67

35 files changed

Lines changed: 142 additions & 53 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package it.vercruysse.lemmyapi
2+
3+
/**
4+
* This declares a property to compare the identity of two objects of the same type
5+
*
6+
* This is useful to create to define uniqueness when the other fields can be different
7+
*/
8+
interface Identity {
9+
val id: Long
10+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgeCommunity(
8-
val id: Long,
9+
override val id: Long,
910
val admin_person_id: PersonId,
1011
val reason: String? = null,
1112
val when_: String,
12-
) : DatatypeRoot
13+
) : DatatypeRoot, Identity
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgeCommunityView(
89
val admin_purge_community: AdminPurgeCommunity,
910
val admin: Person? = null,
10-
) : DatatypeRoot
11+
) : DatatypeRoot, Identity {
12+
override val id: Long
13+
get() = admin_purge_community.id
14+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgePerson(
8-
val id: Long,
9+
override val id: Long,
910
val admin_person_id: PersonId,
1011
val reason: String? = null,
1112
val when_: String,
12-
) : DatatypeRoot
13+
) : DatatypeRoot, Identity
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgePersonView(
89
val admin_purge_person: AdminPurgePerson,
910
val admin: Person? = null,
10-
) : DatatypeRoot
11+
) : DatatypeRoot, Identity {
12+
override val id: Long
13+
get() = admin_purge_person.id
14+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgePost(
8-
val id: Long,
9+
override val id: Long,
910
val admin_person_id: PersonId,
1011
val community_id: CommunityId,
1112
val reason: String? = null,
1213
val when_: String,
13-
) : DatatypeRoot
14+
) : DatatypeRoot, Identity
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class AdminPurgePostView(
89
val admin_purge_post: AdminPurgePost,
910
val admin: Person? = null,
1011
val community: Community,
11-
) : DatatypeRoot
12+
) : DatatypeRoot, Identity {
13+
override val id: Long
14+
get() = admin_purge_post.id
15+
}

app/src/commonMain/kotlin/it/vercruysse/lemmyapi/datatypes/Comment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class Comment(
8-
val id: CommentId,
9+
override val id: CommentId,
910
val creator_id: PersonId,
1011
val post_id: PostId,
1112
val content: String,
@@ -18,4 +19,4 @@ data class Comment(
1819
val path: String,
1920
val distinguished: Boolean,
2021
val language_id: LanguageId,
21-
) : DatatypeRoot
22+
) : DatatypeRoot, Identity
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class CommentReply(
8-
val id: CommentReplyId,
9+
override val id: CommentReplyId,
910
val recipient_id: PersonId,
1011
val comment_id: CommentId,
1112
val read: Boolean,
1213
val published: String,
13-
) : DatatypeRoot
14+
) : DatatypeRoot, Identity

app/src/commonMain/kotlin/it/vercruysse/lemmyapi/datatypes/CommentReplyView.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.vercruysse.lemmyapi.datatypes
22

33
import it.vercruysse.lemmyapi.DatatypeRoot
4+
import it.vercruysse.lemmyapi.Identity
45
import it.vercruysse.lemmyapi.dto.SubscribedType
56
import kotlinx.serialization.Serializable
67

@@ -21,4 +22,7 @@ data class CommentReplyView(
2122
val saved: Boolean,
2223
val creator_blocked: Boolean,
2324
val my_vote: Int = 0,
24-
) : DatatypeRoot
25+
) : DatatypeRoot, Identity {
26+
override val id: Long
27+
get() = comment_reply.id
28+
}

0 commit comments

Comments
 (0)