Skip to content

Commit

Permalink
Fix API with @Body in request
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Feb 9, 2025
1 parent bdd94ad commit 2752848
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ interface PixelfedApi {
@GET("api/v1.1/direct/thread")
fun getChat(@Query("pid") accountId: String, @Query("max_id") maxId: String): Call<ChatDto>

@Headers("Content-Type: application/json")
@POST("api/v1.1/direct/thread/send")
fun sendMessage(@Body createMessageDto: CreateMessageDto): Call<MessageDto>
fun sendMessage(@Body createMessageDto: String): Call<MessageDto>

@DELETE("api/v1.1/direct/thread/message")
fun deleteMessage(@Query("id") id: String): Call<List<Int>>
Expand Down Expand Up @@ -361,9 +362,10 @@ interface PixelfedApi {
@Query("q") searchText: String
): Call<List<PlaceDto>>

@Headers("Content-Type: application/json")
@POST("api/v2/media")
fun uploadMedia(
@Body body: MultiPartFormDataContent
@Body body: String
): Call<MediaAttachmentDto>

@FormUrlEncoded
Expand All @@ -379,14 +381,16 @@ interface PixelfedApi {
@Body createPostDto: String
): Call<PostDto>

@Headers("Content-Type: application/json")
@POST("api/v1/statuses")
fun createReply(
@Body createReplyDto: CreateReplyDto
@Body createReplyDto: String
): Call<PostDto>

@Headers("Content-Type: application/json")
@PUT("api/v1/statuses/{id}")
suspend fun updatePost(
@Path("id") postId: String, @Body updatePostDto: UpdatePostDto
@Path("id") postId: String, @Body updatePostDto: String
): Call<Unit>

@DELETE("api/v1/statuses/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ import com.daniebeler.pfpixelix.utils.execute
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.serialization.json.Json
import me.tatarka.inject.annotations.Inject


class CountryRepositoryImpl @Inject constructor(
private val userDataStorePreferences: DataStore<Preferences>,
private val pixelfedApi: PixelfedApi
private val pixelfedApi: PixelfedApi,
private val json: Json
) : CountryRepository {
override fun getAuthV1Token(): Flow<String> = userDataStorePreferences.data.map { preferences ->
preferences[stringPreferencesKey(Constants.ACCESS_TOKEN_DATASTORE_KEY)] ?: ""
Expand Down Expand Up @@ -128,7 +130,9 @@ class CountryRepositoryImpl @Inject constructor(

override fun createReply(postId: String, content: String): Flow<Resource<Post>> {
val dto = CreateReplyDto(status = content, in_reply_to_id = postId)
return NetworkCall<Post, PostDto>().makeCall(pixelfedApi.createReply(dto))
return NetworkCall<Post, PostDto>().makeCall(
pixelfedApi.createReply(json.encodeToString(dto))
)
}

// Auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import com.daniebeler.pfpixelix.utils.NetworkCall
import com.daniebeler.pfpixelix.utils.execute
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.serialization.json.Json
import me.tatarka.inject.annotations.Inject

class DirectMessagesRepositoryImpl @Inject constructor(
private val pixelfedApi: PixelfedApi
private val pixelfedApi: PixelfedApi,
private val json: Json
) : DirectMessagesRepository {

override fun getConversations(): Flow<Resource<List<Conversation>>> {
Expand All @@ -33,7 +35,9 @@ class DirectMessagesRepositoryImpl @Inject constructor(
}

override fun sendMessage(createMessageDto: CreateMessageDto): Flow<Resource<Message>> {
return NetworkCall<Message, MessageDto>().makeCall(pixelfedApi.sendMessage(createMessageDto))
return NetworkCall<Message, MessageDto>().makeCall(
pixelfedApi.sendMessage(json.encodeToString(createMessageDto))
)
}

override fun deleteMessage(id: String): Flow<Resource<List<Int>>> = flow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PostEditorRepositoryImpl @Inject constructor(
)

try {
val res = pixelfedApi.uploadMedia(data).execute().toModel()
val res = pixelfedApi.uploadMedia(json.encodeToString(data)).execute().toModel()
emit(Resource.Success(res))
} catch (e: Exception) {
emit(Resource.Error("Unknown Error"))
Expand Down Expand Up @@ -100,7 +100,7 @@ class PostEditorRepositoryImpl @Inject constructor(
flow {
try {
emit(Resource.Loading())
pixelfedApi.updatePost(postId, updatePostDto).execute()
pixelfedApi.updatePost(postId, json.encodeToString(updatePostDto)).execute()
emit(Resource.Success(null))
} catch (exception: Exception) {
if (exception.message != null) {
Expand Down

0 comments on commit 2752848

Please sign in to comment.