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

Coupon.type to enum #182

Merged
merged 7 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cloudesire.platform.apiclient;

import java.text.SimpleDateFormat;
import java.util.Date;

abstract class ClientDate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateRepresentation? AbstractDateDeserializer?

{
protected final Date date;

ClientDate( Date date )
{
this.date = date;
}

@Override
public String toString()
{
final SimpleDateFormat dateFormat = getDateFormat();
return dateFormat.format( date );
}

public abstract SimpleDateFormat getDateFormat();

public Date getDate()
{
return date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,18 @@
import java.text.SimpleDateFormat;
import java.util.Date;

public class ISO8601Date
{
private final Date date;
import static com.liberologico.cloudesire.common.DateFormats.DATE_PATTERN;

public final class ISO8601Date extends ClientDate
{
public ISO8601Date( Date date )
{
this.date = date;
super( date );
}

@Override
public String toString()
{
final SimpleDateFormat dateFormat = getDateFormat();
return dateFormat.format( date );
}

public SimpleDateFormat getDateFormat()
{
return new SimpleDateFormat( "yyyy-MM-dd" );
}

public Date getDate()
{
return date;
return new SimpleDateFormat( DATE_PATTERN );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.text.SimpleDateFormat;
import java.util.Date;

public class ISO8601DateTime extends ISO8601Date
import static com.liberologico.cloudesire.common.DateFormats.DATE_TIME_PATTERN;

public final class ISO8601DateTime extends ClientDate
{
public ISO8601DateTime( Date date )
{
Expand All @@ -13,6 +15,6 @@ public ISO8601DateTime( Date date )
@Override
public SimpleDateFormat getDateFormat()
{
return new SimpleDateFormat( "yyyy-MM-dd hh:mm" );
return new SimpleDateFormat( DATE_TIME_PATTERN );
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.cloudesire.platform.apiclient.api;

import com.cloudesire.platform.apiclient.ISO8601Date;
import com.cloudesire.platform.apiclient.ISO8601DateTime;
import com.cloudesire.platform.apiclient.query.CouponFetchQuery;
import com.cloudesire.platform.apiclient.query.CouponGeneratorQuery;
import com.cloudesire.platform.apiclient.query.CouponQuery;
import com.cloudesire.platform.apiclient.query.CouponTrialQuery;
import com.liberologico.cloudesire.cmw.model.dto.CouponDTO;
import com.liberologico.cloudesire.cmw.model.enums.CouponDestination;
import com.liberologico.cloudesire.cmw.model.patch.CouponPatchDTO;
import okhttp3.ResponseBody;
import retrofit2.Call;
Expand All @@ -20,86 +19,39 @@
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;

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

public interface CouponApi
{
@DELETE( "coupon/{id}" )
Call<Void> delete( @Path( "id" ) Integer id );

@POST( "coupon" )
Call<List<CouponDTO>> generate( @QueryMap CouponQuery query );

/**
* @deprecated by {@link #generate(CouponQuery)}
*/
@Deprecated
@POST( "coupon" )
Call<List<CouponDTO>> generate( @Query( "type" ) String type, @Query( "productVersion" ) Integer productVersion,
@Query( "product" ) Integer product, @Query( "expirationDate" ) ISO8601DateTime expiration,
@Query( "licenseOnly" ) Boolean licenseOnly, @Query( "number" ) BigDecimal number,
@Query( "howMany" ) Integer howMany );
Call<CouponDTO> generate( @QueryMap CouponTrialQuery query );

@POST( "coupon" )
Call<CouponDTO> generateGenerator( @QueryMap CouponGeneratorQuery query );

/**
* @deprecated by {@link #generateGenerator(CouponGeneratorQuery)}
*/
@Deprecated
@POST( "coupon" )
Call<CouponDTO> generate( @Query( "type" ) String type, @Query( "productVersion" ) Integer productVersion,
@Query( "product" ) Integer product, @Query( "expiration" ) ISO8601DateTime expiration,
@Query( "licenseOnly" ) Boolean licenseOnly, @Query( "code" ) String code,
@Query( "value" ) BigDecimal value );

@POST( "coupon" )
Call<CouponDTO> generate( @Query( "type" ) String type, @Query( "productVersion" ) Integer productVersion,
@Query( "product" ) Integer product, @Query( "expirationDate" ) ISO8601DateTime expiration,
@Query( "days" ) Integer days, @Query( "plafond" ) BigDecimal plafond );

@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body CouponPatchDTO actions );

@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body CouponPatchDTO actions, @Query( "language" ) String language );

/**
* @deprecated by {@link #partialUpdate(Integer, CouponPatchDTO)}
*/
@Deprecated
@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body Object actions );
@GET( "coupon" )
Call<List<CouponDTO>> getAll( @QueryMap CouponFetchQuery query );

/**
* @deprecated by {@link #partialUpdate(Integer, CouponPatchDTO, String)}
*/
@Deprecated
@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body Object actions, @Query( "language" ) String language );
@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Call<ResponseBody> getCsv( @QueryMap CouponFetchQuery query );

@GET( "coupon/{id}" )
Call<CouponDTO> get( @Path( "id" ) Integer id );

@GET( "coupon/hash={hash}" )
Call<CouponDTO> retrieveByHash( @Path( "hash" ) String hash );

@GET( "coupon" )
Call<List<CouponDTO>> getAll( @QueryMap Map<String, String> pageRequest, @Query( "type" ) String type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused );
@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body CouponPatchDTO actions );

@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Call<ResponseBody> getCsv( @QueryMap Map<String, String> pageRequest, @Query( "type" ) String type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused );
@PATCH( "coupon/{id}" )
Call<Void> partialUpdate( @Path( "id" ) Integer id, @Body CouponPatchDTO actions, @Query( "language" ) String language );

@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Call<ResponseBody> getCsv( @QueryMap Map<String, String> pageRequest );
@DELETE( "coupon/{id}" )
Call<Void> delete( @Path( "id" ) Integer id );
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

abstract class BaseQuery extends HashMap<String, Object>
{
@Override
public Object put( String key, Object value )
{
if ( value == null ) return super.remove( key );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔝

return super.put( key, value );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.cloudesire.platform.apiclient.query;

import com.cloudesire.platform.apiclient.ISO8601Date;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;

public class CouponFetchQuery extends PageRequestQuery
{
private static final String TYPE = "type";
private static final String PRODUCT = "product";
private static final String CREATED_AFTER = "createdAfter";
private static final String UNUSED = "unused";
private static final String REUSABLE = "reusable";

public CouponFetchQuery setType( CouponType type )
{
put( TYPE, type.toString() );
return this;
}

public CouponFetchQuery setProduct( Integer product )
{
put( PRODUCT, product );
return this;
}

public CouponFetchQuery setCreatedAfter( ISO8601Date creation )
{
put( CREATED_AFTER, creation );
return this;
}

public CouponFetchQuery setUnused( Boolean unused )
{
put( UNUSED, unused );
return this;
}

public CouponFetchQuery setReusable( Boolean reusable )
{
put( REUSABLE, reusable );
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cloudesire.platform.apiclient.ISO8601DateTime;
import com.liberologico.cloudesire.cmw.model.enums.CouponDestination;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;

import java.math.BigDecimal;

Expand All @@ -14,10 +15,11 @@ public class CouponGeneratorQuery extends BaseQuery
private static final String DESTINATION = "destination";
private static final String CODE = "code";
private static final String VALUE = "value";
private static final String REUSABLE = "reusable";

public CouponGeneratorQuery setType( String type )
public CouponGeneratorQuery setType( CouponType type )
{
put( TYPE, type );
put( TYPE, type.toString() );
return this;
}

Expand Down Expand Up @@ -57,4 +59,10 @@ public CouponGeneratorQuery setValue( BigDecimal value )
return this;
}

public CouponGeneratorQuery setReusable( Boolean reusable )
{
put( REUSABLE, String.valueOf( reusable ) );
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cloudesire.platform.apiclient.ISO8601DateTime;
import com.liberologico.cloudesire.cmw.model.enums.CouponDestination;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;

import java.math.BigDecimal;

Expand All @@ -15,9 +16,9 @@ public class CouponQuery extends BaseQuery
private static final String NUMBER = "number";
private static final String HOW_MANY = "howMany";

public CouponQuery setType( String type )
public CouponQuery setType( CouponType type )
{
put( TYPE, type );
put( TYPE, type.toString() );
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.cloudesire.platform.apiclient.query;

import com.cloudesire.platform.apiclient.ISO8601DateTime;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;

import java.math.BigDecimal;

public class CouponTrialQuery extends BaseQuery
{
private static final String TYPE = "type";
private static final String PRODUCT_VERSION = "productVersion";
private static final String PRODUCT = "product";
private static final String EXPIRATION_DATE = "expirationDate";
private static final String DAYS = "days";
private static final String PLAFOND = "plafond";

public CouponTrialQuery()
{
put( TYPE, CouponType.EXTENDED_TRIAL.toString() );
}

public CouponTrialQuery setProductVersion( Integer productVersion )
{
put( PRODUCT_VERSION, productVersion );
return this;
}

public CouponTrialQuery setProduct( Integer product )
{
put( PRODUCT, product );
return this;
}

public CouponTrialQuery setExpiration( ISO8601DateTime expiration )
{
put( EXPIRATION_DATE, expiration );
return this;
}

public CouponTrialQuery setDays( Integer days )
{
put( DAYS, days );
return this;
}

public CouponTrialQuery setPlafond( BigDecimal number )
{
put( PLAFOND, number );
return this;
}

}
Loading