Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle data structures like BaseResponse #138

Closed
fqz100 opened this issue Jul 28, 2023 · 2 comments
Closed

How to handle data structures like BaseResponse #138

fqz100 opened this issue Jul 28, 2023 · 2 comments

Comments

@fqz100
Copy link

fqz100 commented Jul 28, 2023

Our backend developer returns the following data structure:
{ code: 0, msg: "success", data: { } }
How should this be handled globally?

@skydoves
Copy link
Owner

You can just make your data structure depending on your backend structure and wrap the data. It's a serialization problem.

@fqz100
Copy link
Author

fqz100 commented Jul 30, 2023

data class BaseResponse<T>(
    val code: Int, 
    val msg: String, 
    val data: T? 
) 

I am defining the response type in this way

 suspend fun getPosts(): ApiResponse<BaseResponse<T>> 

I now want to return directly when code == 0

 suspend fun getPosts(): ApiResponse<T>> 

Any ideas?

@fqz100 fqz100 closed this as completed Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants