Skip to content

Commit

Permalink
feat(order-api): Refactor orders api (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
erenalpaslan committed Mar 9, 2023
1 parent 2440e14 commit 7f5feaa
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 502 deletions.
516 changes: 18 additions & 498 deletions src/main/java/mobi/appcent/medusa/store/api/OrderApi.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class QueryParamConstant {
public static final String LIMIT = "limit";
public static final String CREATED_AT = "created_at";
public static final String UPDATED_AT = "updated_at";
public static final String SHIPPING_ADDRESS = "shipping_address";
public static final String Q = "q";
public static final String ID = "id";
public static final String CSV_FORMAT = "csv";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package mobi.appcent.medusa.store.model.request.order;

import com.squareup.okhttp.Call;
import mobi.appcent.medusa.store.*;
import mobi.appcent.medusa.store.common.HeaderConstant;
import mobi.appcent.medusa.store.common.HttpMethod;
import mobi.appcent.medusa.store.common.QueryParamConstant;
import mobi.appcent.medusa.store.common.UrlConstant;
import mobi.appcent.medusa.store.model.request.BaseRequest;
import mobi.appcent.medusa.store.model.response.StoreOrdersRes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by erenalpaslan on 9.03.2023
*/
public class GetOrderByCartIdRequest extends BaseRequest<StoreOrdersRes> {

private final MedusaSdkClient client;
private final String cartId;

public GetOrderByCartIdRequest(MedusaSdkClient client, String cartId) {
this.client = client;
this.cartId = cartId;
}

@Override
protected Call buildCall() throws ApiException {
String path = UrlConstant.ORDER_PATH + "/cart/" + cartId;
Map<String, String> headers = new HashMap<>();

final String[] localVarAccepts = { HeaderConstant.APPLICATION_JSON };
final String localVarAccept = client.selectHeaderAccept(localVarAccepts);

if (localVarAccept != null) headers.put(HeaderConstant.ACCEPT, localVarAccept);
headers.put(HeaderConstant.CONTENT_TYPE, HeaderConstant.APPLICATION_JSON);

return client.buildCall(path, HttpMethod.GET, null, null, null, headers, null, null);
}

@Override
public ApiResponse<StoreOrdersRes> execute() throws ApiException {
Call call = buildCall();
return client.execute(call);
}

@Override
public void executeAsync(ApiCallback<StoreOrdersRes> callback) throws ApiException {
Call call = buildCall();
client.executeAsync(call, callback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package mobi.appcent.medusa.store.model.request.order;

import com.squareup.okhttp.Call;
import jdk.javadoc.internal.doclets.formats.html.markup.Head;
import mobi.appcent.medusa.store.*;
import mobi.appcent.medusa.store.common.HeaderConstant;
import mobi.appcent.medusa.store.common.HttpMethod;
import mobi.appcent.medusa.store.common.QueryParamConstant;
import mobi.appcent.medusa.store.common.UrlConstant;
import mobi.appcent.medusa.store.model.request.BaseRequest;
import mobi.appcent.medusa.store.model.response.StoreOrdersRes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by erenalpaslan on 9.03.2023
*/
public class GetOrderRequest extends BaseRequest<StoreOrdersRes> {

private final MedusaSdkClient client;
private final String id;
private String fields;
private String expand;

public GetOrderRequest(MedusaSdkClient client, String id) {
this.client = client;
this.id = id;
}

public GetOrderRequest fields(String fields) {
this.fields = fields;
return this;
}

public GetOrderRequest expand(String expand) {
this.expand = expand;
return this;
}

@Override
protected Call buildCall() throws ApiException {
String path = UrlConstant.ORDER_PATH + "/" + id;
Map<String, String> headers = new HashMap<>();

final String[] localVarAccepts = { HeaderConstant.APPLICATION_JSON };
final String localVarAccept = client.selectHeaderAccept(localVarAccepts);

if (localVarAccept != null) headers.put(HeaderConstant.ACCEPT, localVarAccept);
headers.put(HeaderConstant.CONTENT_TYPE, HeaderConstant.APPLICATION_JSON);

List<Pair> localVarQueryParams = new ArrayList<Pair>();
if (fields != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.FIELDS, fields));
if (expand != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.EXPAND, expand));


return client.buildCall(path, HttpMethod.GET, localVarQueryParams, null, null, headers, null, null);
}

@Override
public ApiResponse<StoreOrdersRes> execute() throws ApiException {
Call call = buildCall();
return client.execute(call);
}

@Override
public void executeAsync(ApiCallback<StoreOrdersRes> callback) throws ApiException {
Call call = buildCall();
client.executeAsync(call, callback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package mobi.appcent.medusa.store.model.request.order;

import com.squareup.okhttp.Call;
import mobi.appcent.medusa.store.*;
import mobi.appcent.medusa.store.common.HeaderConstant;
import mobi.appcent.medusa.store.common.HttpMethod;
import mobi.appcent.medusa.store.common.QueryParamConstant;
import mobi.appcent.medusa.store.common.UrlConstant;
import mobi.appcent.medusa.store.model.request.BaseRequest;
import mobi.appcent.medusa.store.model.response.ShippingAddress;
import mobi.appcent.medusa.store.model.response.StoreOrdersRes;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by erenalpaslan on 9.03.2023
*/
public class LookUpOrderByFiltersRequest extends BaseRequest<StoreOrdersRes> {

private final MedusaSdkClient client;
private final BigDecimal displayId;
private final String email;
private String fields;
private String expand;
private ShippingAddress shippingAddress;

public LookUpOrderByFiltersRequest(MedusaSdkClient client, BigDecimal displayId, String email) {
this.client = client;
this.displayId = displayId;
this.email = email;
}

public LookUpOrderByFiltersRequest fields(String fields) {
this.fields = fields;
return this;
}

public LookUpOrderByFiltersRequest expand(String expand) {
this.expand = expand;
return this;
}

public LookUpOrderByFiltersRequest expand(ShippingAddress shippingAddress) {
this.shippingAddress = shippingAddress;
return this;
}

@Override
protected Call buildCall() throws ApiException {
String path = UrlConstant.ORDER_PATH;
Map<String, String> headers = new HashMap<>();

final String[] localVarAccepts = { HeaderConstant.APPLICATION_JSON };
final String localVarAccept = client.selectHeaderAccept(localVarAccepts);

if (localVarAccept != null) headers.put(HeaderConstant.ACCEPT, localVarAccept);
headers.put(HeaderConstant.CONTENT_TYPE, HeaderConstant.APPLICATION_JSON);

List<Pair> localVarQueryParams = new ArrayList<Pair>();
if (displayId != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.DISPLAY_ID, displayId));
if (fields != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.FIELDS, fields));
if (expand != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.EXPAND, expand));
if (email != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.EMAIL, email));
if (shippingAddress != null)
localVarQueryParams.addAll(client.parameterToPair(QueryParamConstant.SHIPPING_ADDRESS, shippingAddress));


return client.buildCall(path, HttpMethod.GET, localVarQueryParams, null, null, headers, null, null);
}

@Override
public ApiResponse<StoreOrdersRes> execute() throws ApiException {
Call call = buildCall();
return client.execute(call);
}

@Override
public void executeAsync(ApiCallback<StoreOrdersRes> callback) throws ApiException {
Call call = buildCall();
client.executeAsync(call, callback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package mobi.appcent.medusa.store.model.request.order;

import com.squareup.okhttp.Call;
import mobi.appcent.medusa.store.*;
import mobi.appcent.medusa.store.common.HeaderConstant;
import mobi.appcent.medusa.store.common.HttpMethod;
import mobi.appcent.medusa.store.common.UrlConstant;
import mobi.appcent.medusa.store.model.request.BaseRequest;
import mobi.appcent.medusa.store.model.response.StorePostCustomersCustomerAcceptClaimReq;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by erenalpaslan on 9.03.2023
*/
public class VerifyOrderClaimRequest extends BaseRequest<Void> {

private final MedusaSdkClient client;
private StorePostCustomersCustomerAcceptClaimReq body;

public VerifyOrderClaimRequest(MedusaSdkClient client) {
this.client = client;
}

public VerifyOrderClaimRequest body(StorePostCustomersCustomerAcceptClaimReq body) {
this.body = body;
return this;
}

@Override
protected Call buildCall() throws ApiException {
String path = UrlConstant.ORDER_PATH + "/customer/confirm";
Map<String, String> headers = new HashMap<>();

final String[] localVarAccepts = { HeaderConstant.APPLICATION_JSON, HeaderConstant.TEXT_PLAIN };
final String localVarAccept = client.selectHeaderAccept(localVarAccepts);

if (localVarAccept != null) headers.put(HeaderConstant.ACCEPT, localVarAccept);
headers.put(HeaderConstant.CONTENT_TYPE, HeaderConstant.APPLICATION_JSON);

String[] localVarAuthNames = new String[] { "cookie_auth" };
return client.buildCall(path, HttpMethod.POST, null, null, body, headers, null, localVarAuthNames);
}

@Override
public ApiResponse<Void> execute() throws ApiException {
Call call = buildCall();
return client.execute(call);
}

@Override
public void executeAsync(ApiCallback<Void> callback) throws ApiException {
Call call = buildCall();
client.executeAsync(call, callback);
}
}
8 changes: 4 additions & 4 deletions src/test/java/mobi/appcent/medusa/store/api/OrderApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void getOrdersTest() throws Exception {
String fields = null;
String expand = null;
ShippingAddress shippingAddress = null;
StoreOrdersRes response = api.getOrders(displayId, email, fields, expand, shippingAddress);
StoreOrdersRes response = api.getOrder(displayId, email).execute().getData();

// TODO: test validations
}
Expand All @@ -61,7 +61,7 @@ public void getOrdersOrderTest() throws Exception {
String id = null;
String fields = null;
String expand = null;
StoreOrdersRes response = api.getOrdersOrder(id, fields, expand);
StoreOrdersRes response = api.getOrder(id).execute().getData();

// TODO: test validations
}
Expand All @@ -76,7 +76,7 @@ public void getOrdersOrderTest() throws Exception {
@Test
public void getOrdersOrderCartIdTest() throws Exception {
String cartId = null;
StoreOrdersRes response = api.getOrdersOrderCartId(cartId);
StoreOrdersRes response = api.getOrderByCartId(cartId).execute().getData();

// TODO: test validations
}
Expand All @@ -91,7 +91,7 @@ public void getOrdersOrderCartIdTest() throws Exception {
@Test
public void postOrdersCustomerOrderClaimsCustomerOrderClaimAcceptTest() throws Exception {
StorePostCustomersCustomerAcceptClaimReq body = null;
api.postOrdersCustomerOrderClaimsCustomerOrderClaimAccept(body);
api.verifyOrderClaim().execute();

// TODO: test validations
}
Expand Down

0 comments on commit 7f5feaa

Please sign in to comment.