Skip to content

Commit a271e7a

Browse files
authored
Merge pull request #486 from FromDoppler/dow-111-add-thirdpartyappid-for-dynamic-promo-codes
[DOW-111] Add thirdpartyappid for dynamic promo codes
2 parents 22a527a + 56f2156 commit a271e7a

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

Doppler.HtmlEditorApi/ApiModels/PromoCode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public record PromoCode(
1717
decimal minPrice,
1818
int maxUses,
1919
string categories,
20-
string prefix
20+
string prefix,
21+
string store
2122
) : IValidatableObject
2223
{
2324
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { yield break; }

Doppler.HtmlEditorApi/Controllers/CampaignsController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ public async Task<Results<NotFound<ProblemDetails>, CreatedAtRoute<ResourceCreat
207207
MaxUses: promoCode.maxUses,
208208
Categories: promoCode.categories,
209209
CampaignId: campaignId,
210-
Prefix: promoCode.prefix
210+
Prefix: promoCode.prefix,
211+
Store: promoCode.store
211212
);
212213

213214
var result = await _promoCodeRepository.CreatePromoCode(promoCodeModel);
@@ -230,7 +231,8 @@ public async Task<IActionResult> UpdatePromoCode(string accountName, int campaig
230231
MaxUses: promoCode.maxUses,
231232
Categories: promoCode.categories,
232233
CampaignId: campaignId,
233-
Prefix: promoCode.prefix
234+
Prefix: promoCode.prefix,
235+
Store: promoCode.store
234236
);
235237

236238
var updateResult = await _promoCodeRepository.UpdatePromoCode(promoCodeModel);

Doppler.HtmlEditorApi/Domain/PromoCodeModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public record PromoCodeModel(
1212
int MaxUses,
1313
string Categories,
1414
int CampaignId,
15-
string Prefix
15+
string Prefix,
16+
string Store
1617
);

Doppler.HtmlEditorApi/Repositories.DopplerDb/DopplerPromoCodeRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public async Task<int> CreatePromoCode(PromoCodeModel promoCodeModel)
2626
MaxUses: promoCodeModel.MaxUses,
2727
Categories: promoCodeModel.Categories,
2828
IdCampaign: promoCodeModel.CampaignId,
29-
Prefix: promoCodeModel.Prefix
29+
Prefix: promoCodeModel.Prefix,
30+
ThirdPartyApp: promoCodeModel.Store
3031
);
3132

3233
var result = await _dbContext.ExecuteAsync(insertPromoCodeDbQuery);
@@ -48,7 +49,8 @@ public async Task<bool> UpdatePromoCode(PromoCodeModel promoCodeModel)
4849
ExpireDays: promoCodeModel.ExpireDays,
4950
MaxUses: promoCodeModel.MaxUses,
5051
Categories: promoCodeModel.Categories,
51-
Prefix: promoCodeModel.Prefix
52+
Prefix: promoCodeModel.Prefix,
53+
ThirdPartyApp: promoCodeModel.Store
5254
);
5355

5456
var result = await _dbContext.ExecuteAsync(updatePromoCodeDbQuery);

Doppler.HtmlEditorApi/Repositories.DopplerDb/Queries/InsertPromoCodeDbQuery.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ public record InsertPromoCodeDbQuery(
1313
int MaxUses,
1414
string? Categories,
1515
int IdCampaign,
16-
string Prefix
16+
string Prefix,
17+
string ThirdPartyApp
1718
) : ISingleItemDbQuery<InsertPromoCodeDbQuery.Result>
1819
{
1920
public string GenerateSqlQuery() => @"
21+
DECLARE @IdThirdPartyApp INT;
22+
SELECT @IdThirdPartyApp = IdThirdPartyApp FROM ThirdPartyApp WHERE Name = @ThirdPartyApp;
23+
2024
INSERT INTO DynamicContentPromoCode (
2125
Type,
2226
Value,
@@ -28,7 +32,8 @@ INSERT INTO DynamicContentPromoCode (
2832
MaxUses,
2933
Categories,
3034
IdCampaign,
31-
Prefix
35+
Prefix,
36+
IdThirdPartyApp
3237
) VALUES (
3338
@Type,
3439
@Value,
@@ -40,7 +45,8 @@ INSERT INTO DynamicContentPromoCode (
4045
@MaxUses,
4146
@Categories,
4247
@IdCampaign,
43-
@Prefix
48+
@Prefix,
49+
ISNULL(@IdThirdPartyApp, 3)
4450
)
4551
4652
SELECT @@Identity AS IdDynamicContentPromoCode";

Doppler.HtmlEditorApi/Repositories.DopplerDb/Queries/UpdatePromoCodeDbQuery.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ public record UpdatePromoCodeDbQuery(
1414
int ExpireDays,
1515
int MaxUses,
1616
string? Categories,
17-
string Prefix
17+
string Prefix,
18+
string ThirdPartyApp
1819
) : IExecutableDbQuery
1920
{
2021
public string GenerateSqlQuery() => @"
22+
DECLARE @IdThirdPartyApp INT;
23+
SELECT @IdThirdPartyApp = IdThirdPartyApp FROM ThirdPartyApp WHERE Name = @ThirdPartyApp;
24+
2125
UPDATE DynamicContentPromoCode
2226
SET Type = @Type,
2327
Value = @Value,
@@ -28,6 +32,7 @@ UPDATE DynamicContentPromoCode
2832
ExpireDays = @ExpireDays,
2933
MaxUses = @MaxUses,
3034
Categories = @Categories,
31-
Prefix = @Prefix
35+
Prefix = @Prefix,
36+
IdThirdPartyApp = ISNULL(@IdThirdPartyApp, IdThirdPartyApp)
3237
WHERE IdDynamicContentPromoCode = @Id AND IdCampaign = @IdCampaign";
3338
}

cspell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
"FIRSTNAME",
4545
"LASTNAME"
4646
]
47+
},
48+
{
49+
"filename": "**/Repositories.DopplerDb/Queries/*.cs",
50+
"ignoreWords": ["ISNULL"]
4751
}
4852
]
4953
}

0 commit comments

Comments
 (0)