Skip to content

Commit

Permalink
Coupon type to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Toraldo committed Oct 16, 2018
1 parent 4479085 commit 9ae079c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.cloudesire.platform.apiclient.query.CouponGeneratorQuery;
import com.cloudesire.platform.apiclient.query.CouponQuery;
import com.liberologico.cloudesire.cmw.model.dto.CouponDTO;
import com.liberologico.cloudesire.cmw.model.enums.CouponDestination;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;
import com.liberologico.cloudesire.cmw.model.patch.CouponPatchDTO;
import okhttp3.ResponseBody;
import retrofit2.Call;
Expand Down Expand Up @@ -37,9 +37,13 @@ public interface CouponApi
*/
@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,
Call<List<CouponDTO>> generate(
@Query( "type" ) CouponType 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 );

@POST( "coupon" )
Expand All @@ -50,13 +54,17 @@ Call<List<CouponDTO>> generate( @Query( "type" ) String type, @Query( "productVe
*/
@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,
Call<CouponDTO> generate(
@Query( "type" ) CouponType 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,
Call<CouponDTO> generate( @Query( "type" ) CouponType type, @Query( "productVersion" ) Integer productVersion,
@Query( "product" ) Integer product, @Query( "expirationDate" ) ISO8601DateTime expiration,
@Query( "days" ) Integer days, @Query( "plafond" ) BigDecimal plafond );

Expand Down Expand Up @@ -87,17 +95,31 @@ Call<CouponDTO> generate( @Query( "type" ) String type, @Query( "productVersion"
Call<CouponDTO> retrieveByHash( @Path( "hash" ) String hash );

@GET( "coupon" )
Call<List<CouponDTO>> getAll( @QueryMap Map<String, String> pageRequest, @Query( "type" ) String type,
Call<List<CouponDTO>> getAll( @QueryMap Map<String, String> pageRequest, @Query( "type" ) CouponType type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused );

@GET( "coupon" )
Call<List<CouponDTO>> getAll( @QueryMap Map<String, String> pageRequest, @Query( "type" ) CouponType type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused, @Query( "reusable" ) boolean reusable );

@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Call<ResponseBody> getCsv( @QueryMap Map<String, String> pageRequest, @Query( "type" ) String type,
Call<ResponseBody> getCsv( @QueryMap Map<String, String> pageRequest, @Query( "type" ) CouponType type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused );

@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Call<ResponseBody> getCsv( @QueryMap Map<String, String> pageRequest, @Query( "type" ) CouponType type,
@Query( "product" ) Integer product, @Query( "createdAfter" ) ISO8601Date createdAfter,
@Query( "unused" ) Boolean unused, @Query( "reusable" ) boolean reusable );

// TODO parameter object

@Streaming
@GET( "coupon" )
@Headers( { "Accept:text/csv" } )
Expand Down
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
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.liberologico.cloudesire.cmw.model.enums.CouponDestination;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;
import com.liberologico.cloudesire.common.Regexp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
Expand All @@ -23,12 +24,6 @@
@ApiModel( "A generated coupon" )
public class CouponDTO extends BaseEntityDTO
{
public static final String DISCOUNT = "discount";
public static final String EXTENDED_TRIAL = "extendedTrial";
public static final String FIXED_PRICE = "fixedPrice";
public static final String DISCOUNT_GENERATOR = "discountGenerator";
public static final String FIXED_PRICE_GENERATOR = "fixedPriceGenerator";

@ApiModelProperty( value = "Email address to notify customer of the coupon", readOnly = true )
@Email( regexp = Regexp.INTERNET_EMAIL )
private String emailCustomer;
Expand All @@ -49,7 +44,7 @@ public class CouponDTO extends BaseEntityDTO

@ApiModelProperty( value = "Coupon type", allowableValues = "bundle, discount, extendedTrial, fixedPrice", readOnly = true )
@NotNull
private String type;
private CouponType type;

@ApiModelProperty( value = "When the coupon has been created", readOnly = true )
@NotNull
Expand Down Expand Up @@ -186,12 +181,12 @@ public void setPercentage( BigDecimal percentage )
this.percentage = percentage;
}

public String getType()
public CouponType getType()
{
return type;
}

public void setType( String type )
public void setType( CouponType type )
{
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.liberologico.cloudesire.cmw.model.dto;

import com.liberologico.cloudesire.cmw.model.enums.CouponType;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
Expand Down Expand Up @@ -633,18 +634,21 @@ public void setVendorReport( MailConfiguration vendorReport )
this.vendorReport = vendorReport;
}

public String getCouponEmailSubject( String couponType, String language )
public String getCouponEmailSubject( CouponType couponType, String language )
{
return getCouponConfiguration( couponType ).getSubject( language );
}

public MailConfiguration getCouponConfiguration( String couponType )
public MailConfiguration getCouponConfiguration( CouponType couponType )
{
switch (couponType)
{
case "discount": return getDiscountCoupon();
case "fixedPrice": return getFixedPriceCoupon();
case "extendedTrial": return getExtendedTrialCoupon();
case DISCOUNT:
return getDiscountCoupon();
case FIXED_PRICE:
return getFixedPriceCoupon();
case EXTENDED_TRIAL:
return getExtendedTrialCoupon();
default: return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.liberologico.cloudesire.cmw.model.dto.DTO;
import com.liberologico.cloudesire.cmw.model.enums.CouponType;

import java.math.BigDecimal;
import java.util.Date;
Expand All @@ -12,7 +13,7 @@ public class CouponCsvDTO extends DTO
{
private String applicationName;

private String type;
private CouponType type;

private boolean reusable;

Expand Down Expand Up @@ -48,12 +49,12 @@ public void setApplicationName( String applicationName )
this.applicationName = applicationName;
}

public String getType()
public CouponType getType()
{
return type;
}

public void setType( String type )
public void setType( CouponType type )
{
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public enum CouponType
BUNDLE( "bundle" ),
DISCOUNT( "discount" ),
EXTENDED_TRIAL( "extendedTrial" ),
FIXED_PRICE( "fixedPrice" );
FIXED_PRICE( "fixedPrice" ),
DISCOUNT_GENERATOR( "discountGenerator" ),
FIXED_PRICE_GENERATOR( "fixedPriceGenerator" );

private final String toString;

Expand Down

0 comments on commit 9ae079c

Please sign in to comment.