改包名com.aiosman.ravenow
This commit is contained in:
169
app/src/main/java/com/aiosman/ravenow/data/MomentService.kt
Normal file
169
app/src/main/java/com/aiosman/ravenow/data/MomentService.kt
Normal file
@@ -0,0 +1,169 @@
|
||||
package com.aiosman.ravenow.data
|
||||
|
||||
import com.aiosman.ravenow.R
|
||||
import com.aiosman.ravenow.data.api.ApiClient
|
||||
import com.aiosman.ravenow.entity.MomentEntity
|
||||
import com.aiosman.ravenow.entity.MomentImageEntity
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import java.io.File
|
||||
|
||||
data class Moment(
|
||||
@SerializedName("id")
|
||||
val id: Long,
|
||||
@SerializedName("textContent")
|
||||
val textContent: String,
|
||||
@SerializedName("images")
|
||||
val images: List<Image>,
|
||||
@SerializedName("user")
|
||||
val user: User,
|
||||
@SerializedName("likeCount")
|
||||
val likeCount: Long,
|
||||
@SerializedName("isLiked")
|
||||
val isLiked: Boolean,
|
||||
@SerializedName("favoriteCount")
|
||||
val favoriteCount: Long,
|
||||
@SerializedName("isFavorite")
|
||||
val isFavorite: Boolean,
|
||||
@SerializedName("shareCount")
|
||||
val isCommented: Boolean,
|
||||
@SerializedName("commentCount")
|
||||
val commentCount: Long,
|
||||
@SerializedName("time")
|
||||
val time: String,
|
||||
@SerializedName("isFollowed")
|
||||
val isFollowed: Boolean,
|
||||
) {
|
||||
fun toMomentItem(): MomentEntity {
|
||||
return MomentEntity(
|
||||
id = id.toInt(),
|
||||
avatar = "${ApiClient.BASE_SERVER}${user.avatar}",
|
||||
nickname = user.nickName,
|
||||
location = "Worldwide",
|
||||
time = ApiClient.dateFromApiString(time),
|
||||
followStatus = isFollowed,
|
||||
momentTextContent = textContent,
|
||||
momentPicture = R.drawable.default_moment_img,
|
||||
likeCount = likeCount.toInt(),
|
||||
commentCount = commentCount.toInt(),
|
||||
shareCount = 0,
|
||||
favoriteCount = favoriteCount.toInt(),
|
||||
images = images.map {
|
||||
MomentImageEntity(
|
||||
url = "${ApiClient.BASE_SERVER}${it.url}",
|
||||
thumbnail = "${ApiClient.BASE_SERVER}${it.thumbnail}",
|
||||
id = it.id,
|
||||
blurHash = it.blurHash,
|
||||
width = it.width,
|
||||
height = it.height
|
||||
)
|
||||
},
|
||||
authorId = user.id.toInt(),
|
||||
liked = isLiked,
|
||||
isFavorite = isFavorite,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class Image(
|
||||
@SerializedName("id")
|
||||
val id: Long,
|
||||
@SerializedName("url")
|
||||
val url: String,
|
||||
@SerializedName("thumbnail")
|
||||
val thumbnail: String,
|
||||
@SerializedName("blurHash")
|
||||
val blurHash: String?,
|
||||
@SerializedName("width")
|
||||
val width: Int?,
|
||||
@SerializedName("height")
|
||||
val height: Int?
|
||||
)
|
||||
|
||||
data class User(
|
||||
@SerializedName("id")
|
||||
val id: Long,
|
||||
@SerializedName("nickName")
|
||||
val nickName: String,
|
||||
@SerializedName("avatar")
|
||||
val avatar: String
|
||||
)
|
||||
|
||||
data class UploadImage(
|
||||
val file: File,
|
||||
val filename: String,
|
||||
val url: String,
|
||||
val ext: String
|
||||
)
|
||||
|
||||
interface MomentService {
|
||||
/**
|
||||
* 获取动态详情
|
||||
* @param id 动态ID
|
||||
*/
|
||||
suspend fun getMomentById(id: Int): MomentEntity
|
||||
|
||||
/**
|
||||
* 点赞动态
|
||||
* @param id 动态ID
|
||||
*/
|
||||
suspend fun likeMoment(id: Int)
|
||||
|
||||
/**
|
||||
* 取消点赞动态
|
||||
* @param id 动态ID
|
||||
*/
|
||||
suspend fun dislikeMoment(id: Int)
|
||||
|
||||
/**
|
||||
* 获取动态列表
|
||||
* @param pageNumber 页码
|
||||
* @param author 作者ID,过滤条件
|
||||
* @param timelineId 用户时间线ID,指定用户 ID 的时间线
|
||||
* @param contentSearch 内容搜索,过滤条件
|
||||
* @param trend 是否趋势动态
|
||||
* @param explore 是否探索动态
|
||||
* @return 动态列表
|
||||
*/
|
||||
suspend fun getMoments(
|
||||
pageNumber: Int,
|
||||
author: Int? = null,
|
||||
timelineId: Int? = null,
|
||||
contentSearch: String? = null,
|
||||
trend: Boolean? = false,
|
||||
explore: Boolean? = false,
|
||||
favoriteUserId: Int? = null
|
||||
): ListContainer<MomentEntity>
|
||||
|
||||
/**
|
||||
* 创建动态
|
||||
* @param content 动态内容
|
||||
* @param authorId 作者ID
|
||||
* @param images 图片列表
|
||||
* @param relPostId 关联动态ID
|
||||
*/
|
||||
suspend fun createMoment(
|
||||
content: String,
|
||||
authorId: Int,
|
||||
images: List<UploadImage>,
|
||||
relPostId: Int? = null
|
||||
): MomentEntity
|
||||
|
||||
/**
|
||||
* 收藏动态
|
||||
* @param id 动态ID
|
||||
*/
|
||||
suspend fun favoriteMoment(id: Int)
|
||||
|
||||
/**
|
||||
* 取消收藏动态
|
||||
* @param id 动态ID
|
||||
*/
|
||||
suspend fun unfavoriteMoment(id: Int)
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
*/
|
||||
suspend fun deleteMoment(id: Int)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user