0

I would like to know how to make Include filter request in android using retrofit. This is how the request looks like in loopback.

{
"filter": {     
    "counts":["agendas"],
    "include":["meetingHall"]
    }
}

This is how the response from the loopback server looks like

{
"count": 1,
"rows": [
    {
        "meetingId": "2010-5-8",
        "titleEn": "horticulture follow up final report.",
        "descriptionEn": "Management Letter Gewane Collage ኣፈጉባኤ ፎረም tigray.pdf ኣፈጉባኤ ፎረም tigray.pdf የፌደራል መንግስት የህግ አወጣጥ.pdf የፌደራል መንግስት የህግ አወጣጥ.pdf",
        "titleAm": "horticulture follow up final report.",
        "descriptionAm": ".የአካባቢ ደንና አየር ንብረት ለውጥ  ኣፈጉባኤ ፎረም tigray.pdf ኣፈጉባኤ ፎረም tigray.pdf የፌደራል መንግስት የህግ አወጣጥ.pdf የፌደራል መንግስት የህግ አወጣጥ.pdf",
        "status": "FINISHED",
        "finishDetail": {
            "attendanceNo": 0,
            "remark": ""
        },
        "postponeDetail": null,
        "cancelDetail": null,
        "startDateGe": "2018-09-10T00:00:00.000Z",
        "startDateEt": "2010-13-05",
        "startTimeGe": {
            "hour": 10,
            "minute": 0
        },
        "startTimeEt": {
            "hour": 10,
            "minute": 0
        },
        "isArchive": false,
        "regularMeetingDetail": {
            "meetingNo": 8,
            "round": 5,
            "year": 2010
        },
        "seenStatus": 0,
        "id": "5b926b5b9fab48001459004e",
        "meetingHallId": "5b926a899fab480014590049",
        "userGroupIds": [
            "5b926a5b9fab480014590045",
            "5b926a619fab480014590046"
        ],
        "createdAt": "2018-09-07T12:13:15.880Z",
        "updatedAt": "2018-09-18T12:43:28.577Z",
        "meetingTypeId": "5b92668c9fab480014590021",
        "agendasCount": 1,
        "meetingHall": {
            "nameEn": "በቋሚ ኮሚቴ አዳራሽ\t",
            "nameAm": "በቋሚ ኮሚቴ አዳራሽ\t",
            "id": "5b926a899fab480014590049",
            "createdAt": "2018-09-07T12:09:45.776Z",
            "updatedAt": "2018-09-07T12:09:45.776Z",
            "name": "",
            "description": ""
        }
    }
]

}

Because of that in the response other attributes have been serverd which normaly would take for more than just one request at the time... my Point is I would liek to know what my endpoint calling looks like for my retrofit in android.

sample api calls

 @GET(ENDPOINT_MEETING)
 @Headers(ApiHeader.API_AUTH_TYPE + HEADER_PARAM_SEPARATOR + ApiHeader.PROTECTED_API)
 Observable<MeetingsResponse> loadMeetings(@Query("isArchive") Boolean isArchive);

reference for this kind of request can be found in the official page of loopback in here How can I make my request? should I use Query of any other properties? Thanks!

Kidus Tekeste
  • 651
  • 2
  • 10
  • 28

3 Answers3

1

You can include filters in your request like this

@GET(ENDPOINT_MEETING)
 @Headers(ApiHeader.API_AUTH_TYPE + HEADER_PARAM_SEPARATOR + ApiHeader.PROTECTED_API)
 Observable<MeetingsResponse> loadMeetings(@Query("isArchive") Boolean isArchive,@Query("filter" String filter);
Nathaniel
  • 71
  • 1
  • 6
0

Looks like you are sending this data in body of request so use this :

create class of your request body like :

for filter FilterRequestWrapper.java :

public class FilterRequestWrapper {
  /*  {
"filter": {
    "counts":["agendas"],
    "include":["meetingHall"]
    }
}
*/

    @Expose
    public FilterRequest filter;

    public class FilterRequest {
        @Expose
        public List<String> counts;
        @Expose
        public List<String> include;

    }
}

And use it like :

@GET(ENDPOINT_MEETING)
@Headers(ApiHeader.API_AUTH_TYPE + HEADER_PARAM_SEPARATOR + ApiHeader.PROTECTED_API)
Observable<MeetingsResponse> loadMeetings(@Query("isArchive") Boolean isArchive, @Body FilterRequestWrapper filterRequestWrapper);
NehaK
  • 2,639
  • 1
  • 15
  • 31
  • Do I need to do the `@SerializedName("counts")` and `@SerializedName("include")` on top of @Expose annotation? for the `FilterRequestWrapper` class? – Kidus Tekeste Sep 20 '18 at 11:26
  • 1
    no its is required only if you name your variables different than actual, like counts, you could take countsForFiler and put @SerializedName("counts") above it. – NehaK Sep 20 '18 at 17:38
  • hey Nehak, I checked other it elsewhere and I got this https://stackoverflow.com/questions/29834959/http-get-with-request-body-retrofit#38487357 can you tell me what you think about it concerning my situation. Thanks! – Kidus Tekeste Sep 24 '18 at 07:09
  • is it still not working for you? can you post actual request with body? – NehaK Sep 25 '18 at 05:41
  • yes It didn't work since I was using retrofit and retrofit will return an error for trying to send a body inside a GET request .. so what I did for getting around this u can check it below. But thanks for the hint and your time! – Kidus Tekeste Oct 10 '18 at 07:26
0

The endpoint to the API and how I called it

@GET(ENDPOINT_MEETING)
@Headers(ApiHeader.API_AUTH_TYPE + HEADER_PARAM_SEPARATOR + ApiHeader.PROTECTED_API)
Observable<MeetingsResponse> loadMeetings(@Query("filter") String meetingFilter);

How I called it in my Presenter class

    getMvpView().showLoading();
    getCompositeDisposable().add(getDataManager()
            .loadMeetings("{ \"counts\":[\"agendas\"], \"include\":[\"meetingHall\"]}")
            //.loadArchiveMeetings()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(meetingsResponse -> {

                        if (!isViewAttached()) {
                            return;
                        }

                        getMvpView().showMeetings(meetingsResponse.getMeetings());
                    },
                    throwable -> {

                        if (!isViewAttached()) {
                            return;
                        }

                        getMvpView().hideLoading();
                        if (!CommonUtils.getErrorMessage(throwable).isEmpty())
                            getMvpView().onError(CommonUtils.getErrorMessage(throwable));
                    }));

and this is how I implemented a filter in the GET request.

Kidus Tekeste
  • 651
  • 2
  • 10
  • 28