Newer
Older
CosmosClient / app / src / main / java / com / example / cosmosclient / services / NotificationDone.java
package com.example.cosmosclient.services;

import android.os.Handler;

import com.example.cosmosclient.entities.AddRequestsResponse;
import com.example.cosmosclient.entities.Group;
import com.example.cosmosclient.entities.Request;
import com.example.cosmosclient.resources.GroupsRest;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

public class NotificationDone {
    //retrofitの処理
    final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/rest/")
            //            .baseUrl("http://10.0.2.2:8080/rest/")
            .addConverterFactory(JacksonConverterFactory.create())
            .build();
    //interfaceから実装を取得
    final GroupsRest requestsService = retrofit.create(GroupsRest.class);


    public void onClick(Notification notification){
        Group group = notification.getGroup();
        Request request = notification.getRequest();

        String deadline = null;
        if (request.getDeadline() != null) {
            deadline = String.format("%d-%02d-%02d %02d:%02d:%02d", request.getDeadline().getYear(), request.getDeadline().getMonth() + 1, request.getDeadline().getDate() + 1, 23, 59, 59);
        }

        try {
            final Call<AddRequestsResponse> updateRequestCall = requestsService.updateRequest(group.getgId(), request.getrId(), request.getIssuer().getuId(), request.getProduct(), deadline, request.getLocation(), true, "token");
            Response<AddRequestsResponse> response = updateRequestCall.execute();
            if (!response.isSuccessful()) {
                // onFailure
                try {
                    System.out.println(response.errorBody().string());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}