-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29 basic admin section for creating/deleting/list the promo code
- Loading branch information
Showing
12 changed files
with
362 additions
and
11 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/alfio/controller/api/PromoCodeApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* This file is part of alf.io. | ||
* | ||
* alf.io is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* alf.io is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with alf.io. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package alfio.controller.api; | ||
|
||
import static org.springframework.web.bind.annotation.RequestMethod.*; | ||
|
||
import java.time.ZoneId; | ||
import java.util.List; | ||
import java.util.TimeZone; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import alfio.manager.EventManager; | ||
import alfio.model.Event; | ||
import alfio.model.PromoCode; | ||
import alfio.model.modification.PromoCodeModification; | ||
import alfio.model.modification.PromoCodeWithFormattedTime; | ||
import alfio.repository.EventRepository; | ||
import alfio.repository.PromoCodeRepository; | ||
|
||
@RestController | ||
@RequestMapping("/admin/api") | ||
public class PromoCodeApiController { | ||
|
||
private final EventRepository eventRepository; | ||
private final PromoCodeRepository promoCodeRepository; | ||
private final EventManager eventManager; | ||
|
||
@Autowired | ||
public PromoCodeApiController(EventRepository eventRepository, PromoCodeRepository promoCodeRepository, EventManager eventManager) { | ||
this.eventRepository = eventRepository; | ||
this.promoCodeRepository = promoCodeRepository; | ||
this.eventManager = eventManager; | ||
} | ||
|
||
@RequestMapping(value = "/events/{eventId}/promo-code", method = POST) | ||
public void addPromoCode(@PathVariable("eventId") int eventId, @RequestBody PromoCodeModification promoCode) { | ||
Event event = eventRepository.findById(eventId); | ||
ZoneId zoneId = TimeZone.getTimeZone(event.getTimeZone()).toZoneId(); | ||
|
||
eventManager.addPromoCode(promoCode.getPromoCode(), eventId, promoCode.getStart().toZonedDateTime(zoneId), | ||
promoCode.getEnd().toZonedDateTime(zoneId), promoCode.getDiscountAmount(), promoCode.getDiscountType()); | ||
} | ||
|
||
@RequestMapping(value = "/events/{eventId}/promo-code", method = GET) | ||
public List<PromoCodeWithFormattedTime> listPromoCodeInEvent(@PathVariable("eventId") int eventId) { | ||
return eventManager.findPromoCodesInEvent(eventId); | ||
} | ||
|
||
@RequestMapping(value = "/events/{eventId}/promo-code/{promoCodeName}", method = DELETE) | ||
public void removePromoCode(@PathVariable("eventId") int eventId, @PathVariable("promoCodeName") String promoCodeName) { | ||
PromoCode promoCode = promoCodeRepository.findPromoCodeInEvent(eventId, promoCodeName); | ||
eventManager.deletePromoCode(promoCode.getId()); | ||
} | ||
|
||
@RequestMapping(value = "/events/{eventId}/promo-code/{promoCodeName}", method = POST) | ||
public void updatePromoCode(@PathVariable("eventId") int eventId, @RequestBody PromoCodeModification promoCode) { | ||
//FIXME complete. Will be used to disable and/or change validity date | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/alfio/model/modification/PromoCodeModification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* This file is part of alf.io. | ||
* | ||
* alf.io is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* alf.io is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with alf.io. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package alfio.model.modification; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Getter; | ||
import alfio.model.PromoCode.DiscountType; | ||
|
||
@Getter | ||
public class PromoCodeModification { | ||
|
||
private final String promoCode; | ||
private final DateTimeModification start; | ||
private final DateTimeModification end; | ||
private final int discountAmount; | ||
private final DiscountType discountType; | ||
|
||
@JsonCreator | ||
public PromoCodeModification(@JsonProperty("promoCode") String promoCode, | ||
@JsonProperty("start") DateTimeModification start, | ||
@JsonProperty("end") DateTimeModification end, | ||
@JsonProperty("discountAmount") int discountAmount, | ||
@JsonProperty("discountType") DiscountType discountType) { | ||
this.promoCode = promoCode; | ||
this.start = start; | ||
this.end = end; | ||
this.discountAmount = discountAmount; | ||
this.discountType = discountType; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/alfio/model/modification/PromoCodeWithFormattedTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* This file is part of alf.io. | ||
* | ||
* alf.io is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* alf.io is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with alf.io. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package alfio.model.modification; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import lombok.experimental.Delegate; | ||
import alfio.model.PromoCode; | ||
|
||
public class PromoCodeWithFormattedTime { | ||
|
||
@JsonIgnore | ||
@Delegate | ||
private final PromoCode promo; | ||
|
||
@JsonIgnore | ||
private final ZoneId eventZoneId; | ||
|
||
public PromoCodeWithFormattedTime(PromoCode promo, ZoneId eventZoneId) { | ||
this.promo = promo; | ||
this.eventZoneId = eventZoneId; | ||
} | ||
|
||
public boolean isExpired() { | ||
return ZonedDateTime.now(eventZoneId).isAfter(getUtcEnd().withZoneSameInstant(eventZoneId)); | ||
} | ||
|
||
public String getFormattedStart() { | ||
return getUtcStart().withZoneSameInstant(eventZoneId).format(EventWithStatistics.JSON_DATE_FORMATTER); | ||
} | ||
|
||
public String getFormattedEnd() { | ||
return getUtcEnd().withZoneSameInstant(eventZoneId).format(EventWithStatistics.JSON_DATE_FORMATTER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
INSERT INTO organization(name, description, email) VALUES ('demo', 'demo organization', '[email protected]'); | ||
|
||
insert into event(description, short_name, website_url, website_t_c_url, location, latitude, longitude, start_ts, end_ts, regular_price_cts, currency, available_seats, vat_included, vat, allowed_payment_proxies, private_key, org_id, time_zone, image_url) | ||
values('event desc', 'eventname', 'http://localhost:8080', 'http://localhost:8080', 'demo location', '0', '0', '2015-01-10 05:00:00' , '2015-01-11 04:59:00' , 1000, 'CHF', 440, 'true', 8, 'STRIPE', 'alfio-uberall', 0, 'America/New_York', 'http://localhost:8080/resources/images/sample-logo.png'); | ||
values('event desc', 'eventname', 'http://localhost:8080', 'http://localhost:8080', 'demo location', '0', '0', '2015-10-10 04:00:00' , '2015-10-11 03:59:00' , 1000, 'CHF', 440, 'true', 8, 'STRIPE', 'alfio-uberall', 0, 'America/New_York', 'http://localhost:8080/resources/images/sample-logo.png'); | ||
|
||
insert into ticket_category(inception, expiration, name, description, max_tickets, price_cts, access_restricted, tc_status, event_id) values | ||
('2014-01-10 00:00:00', '2015-10-10 00:00:00', 'Normal', 'Very good category', 2, 0, false, 'ACTIVE', 0), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...bapp/resources/angular-templates/admin/partials/event/fragment/edit-promo-code-modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<div class="modal-header"> | ||
<h3>Insert new promo code</h3> | ||
</div> | ||
<form name="promoCodeForm" data-ng-submit="update(promoCodeForm, promocode, event)" novalidate data-error-sensitive> | ||
<div class="modal-body"> | ||
<div class="col-sm-12 col-md-8 col-md-offset-2"> | ||
<div class="form-group"> | ||
<label for="promoCode">Promo code name</label> | ||
<input type="text" id="promoCode" data-ng-model="promocode.promoCode" class="form-control to-uppercase" required minlength="7"/> | ||
<field-error data-form-obj="promocode" data-field-obj="promocode.promoCode" data-show-existing-errors="showExistingErrors"></field-error> | ||
</div> | ||
|
||
|
||
<div class="form-group"> | ||
<label for="date">Validity range</label> | ||
<input type="text" data-date-range data-start-model="promocode.start" data-end-model="promocode.end" data-ng-model="promocode.dateString" name="date" id="date" class="form-control" required /> | ||
<field-error data-form-obj="promocode" data-field-obj="promocode.dateString" data-show-existing-errors="showExistingErrors"></field-error> | ||
</div> | ||
|
||
|
||
<div class="form-group"> | ||
<label class="control-label">Discount type</label> | ||
<div> | ||
<div class="radio-inline"> | ||
<label> | ||
<input type="radio" name="discountType" data-ng-model="promocode.discountType" data-ng-value="'FIXED_AMOUNT'" required> | ||
Fixed amount | ||
</label> | ||
</div> | ||
<div class="radio-inline"> | ||
<label> | ||
<input type="radio" name="discountType" data-ng-model="promocode.discountType" data-ng-value="'PERCENTAGE'" required> | ||
Percentage | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="promoCode">Discount amount</label> | ||
<div class="input-group"> | ||
<input type="number" id="discountAmount" data-ng-model="promocode.discountAmount" class="form-control" min="0"/> | ||
<div class="input-group-addon"> | ||
<span data-ng-if="promocode.discountType === 'PERCENTAGE'">%</span> | ||
<span data-ng-if="promocode.discountType === 'FIXED_AMOUNT'">{{event.currency}}</span> | ||
</div> | ||
</div> | ||
<field-error data-form-obj="discountAmount" data-field-obj="promocode.discountAmount" data-show-existing-errors="showExistingErrors"></field-error> | ||
</div> | ||
</div> | ||
|
||
<div class="clearfix"></div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<control-buttons data-form-obj="promoCodeForm"></control-buttons> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.