Skip to content

Commit

Permalink
add event registration count (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Psalmuel01 authored Nov 27, 2024
1 parent 8c9ee1f commit 2584ac7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/events/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub mod Events {
paid_events: Map<
(ContractAddress, u256), u256
>, // map<(attendeeAddress, event_id), amount_paid>
registered_attendees: Map<u256, u256> // map<event_id, registered_attendees_count>
registered_attendees: Map<u256, u256>, // map<event_id, registered_attendees_count>
attendee_event_registration_counts: Map<u256, u256>, // map<event_id, registration_count>
}

// event
Expand Down Expand Up @@ -189,6 +190,10 @@ pub mod Events {
// update event attendees count.
self.registered_attendees.write(event_id, self.registered_attendees.read(event_id) + 1);

// Update registered attendees count
let current_count = self.attendee_event_registration_counts.read(event_id);
self.attendee_event_registration_counts.write(event_id, current_count + 1);

self
.emit(
RegisteredForEvent {
Expand Down Expand Up @@ -290,14 +295,20 @@ pub mod Events {
attendee_event_details
}


fn attendees_registered(self: @ContractState, event_id: u256) -> u256 {
let caller = get_caller_address();
let event_owner = self.event_owners.read(event_id);
assert(caller == event_owner, NOT_OWNER);
self.registered_attendees.read(event_id)
}

fn event_registration_count(self: @ContractState, event_id: u256) -> u256 {
let caller = get_caller_address();
let event_owner = self.event_owners.read(event_id);
assert(caller == event_owner, NOT_OWNER);
self.attendee_event_registration_counts.read(event_id)
}

fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable.upgrade(new_class_hash);
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/IEvent.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub trait IEvent<TContractState> {
fn event_owner(self: @TContractState, event_id: u256) -> ContractAddress;
fn attendee_event_details(self: @TContractState, event_id: u256) -> EventRegistration;
fn attendees_registered(self: @TContractState, event_id: u256) -> u256;
fn event_registration_count(self: @TContractState, event_id: u256) -> u256;

fn upgrade(ref self: TContractState, new_class_hash: ClassHash);
}

0 comments on commit 2584ac7

Please sign in to comment.