webapi/src/main/kotlin/model/Articles.kt
author Da Risk <da_risk@geekorum.com>
Mon, 16 Jan 2023 17:05:31 -0400
changeset 943 298742859784
parent 882 7a74abf66c49
child 1135 5dd06d1fbe83
permissions -rw-r--r--
build: update license headers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
137
5464f07a306c Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents: 113
diff changeset
     1
/*
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     2
 * Geekttrss is a RSS feed reader application on the Android Platform.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     3
 *
943
298742859784 build: update license headers
Da Risk <da_risk@geekorum.com>
parents: 882
diff changeset
     4
 * Copyright (C) 2017-2023 by Frederic-Charles Barthelery.
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     5
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     6
 * This file is part of Geekttrss.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     7
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     8
 * Geekttrss is free software: you can redistribute it and/or modify
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     9
 * it under the terms of the GNU General Public License as published by
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    10
 * the Free Software Foundation, either version 3 of the License, or
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    11
 * (at your option) any later version.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    12
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    13
 * Geekttrss is distributed in the hope that it will be useful,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    16
 * GNU General Public License for more details.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    17
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    19
 * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    20
 */
754
a138890f66f0 webapi: update dependencies and fix some warnings
Da Risk <da_risk@geekorum.com>
parents: 750
diff changeset
    21
@file:OptIn(ExperimentalSerializationApi::class)
310
bd0611482474 Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents: 300
diff changeset
    22
package com.geekorum.ttrss.webapi.model
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    23
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    24
import androidx.annotation.Keep
754
a138890f66f0 webapi: update dependencies and fix some warnings
Da Risk <da_risk@geekorum.com>
parents: 750
diff changeset
    25
import kotlinx.serialization.ExperimentalSerializationApi
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    26
import kotlinx.serialization.KSerializer
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    27
import kotlinx.serialization.SerialName
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    28
import kotlinx.serialization.Serializable
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    29
import kotlinx.serialization.Serializer
651
dac728baf12b webapi: update to latest serialization runtime library
Da Risk <da_risk@geekorum.com>
parents: 649
diff changeset
    30
import kotlinx.serialization.builtins.nullable
dac728baf12b webapi: update to latest serialization runtime library
Da Risk <da_risk@geekorum.com>
parents: 649
diff changeset
    31
import kotlinx.serialization.builtins.serializer
750
3a182d06fb1b update to kotlin 1.4
Da Risk <da_risk@geekorum.com>
parents: 651
diff changeset
    32
import kotlinx.serialization.encoding.CompositeDecoder
3a182d06fb1b update to kotlin 1.4
Da Risk <da_risk@geekorum.com>
parents: 651
diff changeset
    33
import kotlinx.serialization.encoding.Decoder
3a182d06fb1b update to kotlin 1.4
Da Risk <da_risk@geekorum.com>
parents: 651
diff changeset
    34
import kotlinx.serialization.encoding.Encoder
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    35
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    36
/**
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    37
 * The payload gor a getHeadlines request.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    38
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    39
 * It allows to retrieve articles from the Tiny Tiny Rss server.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    40
 */
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    41
@Keep
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    42
@Serializable
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    43
data class GetArticlesRequestPayload(
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    44
    @SerialName("feed_id")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    45
    val feedId: Long,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    46
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    47
    @SerialName("view_mode")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    48
    val viewMode: ViewMode = ViewMode.ALL_ARTICLES,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    49
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    50
    @SerialName("show_content")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    51
    val showContent: Boolean = true,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    52
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    53
    @SerialName("show_excerpt")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    54
    val showExcerpt: Boolean = true,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    55
624
cd636ef89d05 webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    56
    @SerialName("include_attachments")
cd636ef89d05 webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    57
    val includeAttachments: Boolean = false,
cd636ef89d05 webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    58
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    59
    private val skip: Int = 0,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    60
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    61
    @SerialName("since_id")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    62
    val sinceId: Long = 0,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    63
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    64
    val limit: Int = 200,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    65
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    66
    @SerialName("order_by")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    67
    val orderBy: SortOrder = SortOrder.NOTHING
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    68
) : LoggedRequestPayload() {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    69
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    70
    @SerialName("op")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    71
    override val operation = "getHeadlines"
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    72
600
c9d6a339dd04 build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents: 565
diff changeset
    73
    @Serializable
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    74
    enum class ViewMode {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    75
        @SerialName("all_articles")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    76
        ALL_ARTICLES,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    77
        @SerialName("unread")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    78
        UNREAD,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    79
        @SerialName("adaptive")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    80
        ADAPTIVE,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    81
        @SerialName("marked")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    82
        MARKED,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    83
        @SerialName("updated")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    84
        UPDATED
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    85
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    86
600
c9d6a339dd04 build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents: 565
diff changeset
    87
    @Serializable
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    88
    enum class SortOrder {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    89
        @SerialName("title")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    90
        TITLE,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    91
        @SerialName("date_reverse")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    92
        DATE_REVERSE,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    93
        @SerialName("feed_dates")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    94
        FEED_DATES,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    95
        @SerialName("")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    96
        NOTHING
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    97
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    98
}
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    99
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   100
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   101
/**
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   102
 * Request payload to update an Article.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   103
 */
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   104
@Keep
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   105
@Serializable
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   106
data class UpdateArticleRequestPayload(
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   107
    @SerialName("article_ids")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   108
    val articleIds: String,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   109
    val mode: Int,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   110
    val field: Int,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   111
    val data: String? = null
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   112
) : LoggedRequestPayload() {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   113
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   114
    @SerialName("op")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   115
    override val operation = "updateArticle"
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   116
}
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   117
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   118
/**
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   119
 * The response of an update article request.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   120
 */
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   121
@Keep
565
22a9c6bb238d webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents: 563
diff changeset
   122
@Serializable(UpdateArticleResponsePayload.OwnSerializer::class)
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   123
data class UpdateArticleResponsePayload(
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   124
    @SerialName("seq")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   125
    override val sequence: Int? = null,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   126
    override val status: Int = 0,
565
22a9c6bb238d webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents: 563
diff changeset
   127
    override val content: Content
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   128
) : ResponsePayload<UpdateArticleResponsePayload.Content>() {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   129
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   130
    @Transient
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   131
    val updated: Int = content.updated ?: 0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   132
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   133
    @Serializable
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   134
    data class Content(
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   135
        val status: String? = null,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   136
        val updated: Int? = null,
248
47e6ff1ded90 Json: use enum for Error in BaseContent
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   137
        override var error: Error? = null
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   138
    ): BaseContent()
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   139
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   140
    @Serializer(UpdateArticleResponsePayload::class)
565
22a9c6bb238d webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents: 563
diff changeset
   141
    internal object OwnSerializer : KSerializer<UpdateArticleResponsePayload> {
649
bfd55ae54658 Remove some warnings
Da Risk <da_risk@geekorum.com>
parents: 640
diff changeset
   142
        override fun serialize(encoder: Encoder, value: UpdateArticleResponsePayload) {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   143
            TODO("not implemented")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   144
        }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   145
300
f7561ea41b64 Fix a few warnings
Da Risk <da_risk@geekorum.com>
parents: 248
diff changeset
   146
        override fun deserialize(decoder: Decoder): UpdateArticleResponsePayload {
f7561ea41b64 Fix a few warnings
Da Risk <da_risk@geekorum.com>
parents: 248
diff changeset
   147
            val contentDecoder = decoder.beginStructure(descriptor)
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   148
            lateinit var content: Content
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   149
            var seq: Int? = null
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   150
            var status = 0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   151
            loop@ while (true) {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   152
                when(val i = contentDecoder.decodeElementIndex(descriptor)) {
750
3a182d06fb1b update to kotlin 1.4
Da Risk <da_risk@geekorum.com>
parents: 651
diff changeset
   153
                    CompositeDecoder.DECODE_DONE -> break@loop
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   154
                    0 -> seq = contentDecoder.decodeNullableSerializableElement(descriptor, i,
640
f6f64ebc7773 webapi, faviKonSnoop: update serialization runtime for kotlin 1.3.70
Da Risk <da_risk@geekorum.com>
parents: 624
diff changeset
   155
                        Int.serializer().nullable)
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   156
                    1 -> status = contentDecoder.decodeIntElement(descriptor, i)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   157
                    2 -> {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   158
                        val contentSerializer = Content.serializer()
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   159
                        content = contentDecoder.decodeSerializableElement(contentSerializer.descriptor, i,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   160
                            contentSerializer)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   161
                    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   162
                }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   163
            }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   164
            contentDecoder.endStructure(descriptor)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   165
            return UpdateArticleResponsePayload(
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   166
                content = content,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   167
                sequence = seq,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   168
                status = status
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   169
            )
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   170
        }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   171
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   172
}