mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-02-02 15:07:59 -05:00
Refactored response
This commit is contained in:
parent
d6436021f1
commit
b11bfe46fd
@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Post PostModel `json:"post,omitempty"`
|
||||
Posts []PostModel `json:"latest_posts,omitempty"`
|
||||
Post PostModel `json:"post,omitempty"`
|
||||
}
|
||||
|
||||
type RequestError struct {
|
||||
|
@ -7,6 +7,10 @@ import (
|
||||
|
||||
const PostsBaseURL = "/posts"
|
||||
|
||||
type ListPostsResponse struct {
|
||||
LatestPosts []PostModel `json:"latest_posts,omitempty"`
|
||||
}
|
||||
|
||||
type PostModel struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@ -68,7 +72,7 @@ type PostsService interface {
|
||||
) (PostModel, error)
|
||||
List(
|
||||
ctx context.Context,
|
||||
) ([]PostModel, error)
|
||||
) (*ListPostsResponse, error)
|
||||
}
|
||||
|
||||
type PostServiceHandler struct {
|
||||
@ -98,18 +102,18 @@ func (a *PostServiceHandler) Show(
|
||||
// List
|
||||
func (a *PostServiceHandler) List(
|
||||
ctx context.Context,
|
||||
) ([]PostModel, error) {
|
||||
) (*ListPostsResponse, error) {
|
||||
uri := PostsBaseURL + ".json"
|
||||
|
||||
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return []PostModel{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := new(Response)
|
||||
response := new(ListPostsResponse)
|
||||
if err = a.client.Do(ctx, req, response); err != nil {
|
||||
return []PostModel{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Posts, nil
|
||||
return response, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user