1+ package com.texthip.thip.data.repository
2+
3+ import com.texthip.thip.data.model.base.handleBaseResponse
4+ import com.texthip.thip.data.model.comments.request.CommentsCreateRequest
5+ import com.texthip.thip.data.model.comments.request.CommentsLikesRequest
6+ import com.texthip.thip.data.service.CommentsService
7+ import javax.inject.Inject
8+ import javax.inject.Singleton
9+
10+ @Singleton
11+ class CommentsRepository @Inject constructor(
12+ private val commentsService : CommentsService ,
13+ ) {
14+ suspend fun getComments (
15+ postId : Long ,
16+ postType : String = "RECORD ",
17+ cursor : String? = null,
18+ ) = runCatching {
19+ commentsService.getComments(
20+ postId = postId,
21+ postType = postType,
22+ cursor = cursor
23+ ).handleBaseResponse().getOrThrow()
24+ }
25+
26+ suspend fun likeComment (
27+ commentId : Long ,
28+ type : Boolean
29+ ) = runCatching {
30+ commentsService.likeComment(
31+ commentId = commentId,
32+ response = CommentsLikesRequest (type)
33+ ).handleBaseResponse().getOrThrow()
34+ }
35+
36+ suspend fun createComment (
37+ postId : Long ,
38+ content : String ,
39+ isReplyRequest : Boolean ,
40+ parentId : Int? = null,
41+ postType : String = "RECORD ",
42+ ) = runCatching {
43+ commentsService.createComment(
44+ postId = postId,
45+ request = CommentsCreateRequest (
46+ content = content,
47+ isReplyRequest = isReplyRequest,
48+ parentId = parentId,
49+ postType = postType
50+ )
51+ ).handleBaseResponse().getOrThrow()
52+ }
53+ }
0 commit comments