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

feature: add upvote and downvote function #112

Merged
merged 5 commits into from
Sep 14, 2024

Conversation

codeWhizperer
Copy link
Collaborator

No description provided.

@@ -56,7 +56,9 @@ pub struct Publication {
content_URI: ByteArray,
pub_Type: PublicationType,
root_profile_address: ContractAddress,
root_pub_id: u256
root_pub_id: u256,
upvote: Upvote,
Copy link
Collaborator

Choose a reason for hiding this comment

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

upvote and downvote should be represented by a u256, and should increase by 1 for each upvote or downvote

@@ -146,3 +146,23 @@ pub struct QuoteParams {
pointed_pub_id: u256,
reference_pub_type: PublicationType
}
#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Upvote {
Copy link
Collaborator

Choose a reason for hiding this comment

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

these were meant to be the emitted events on upvote

block_timestamp: u64,
}
#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Downvote {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this was meant to be the emitted event on downvote

let publication = self.get_publication(profile_address, pub_id);
let caller = get_caller_address();
let has_upvoted = self.vote_status.read((caller, pub_id));
let mut vote_current_count = self.vote_count.read(pub_id) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's not store upvotes in storage. rather simply increment the upvote item within the Publication struct, and you can always just retrieve that

@@ -66,13 +71,18 @@ pub mod PublicationComponent {
}

#[derive(Drop, starknet::Event)]
pub struct QuoteCreated {
quoteParams: QuoteParams,
pub struct UpvoteCreated {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename event to Upvoted

publication_id: u256,
transaction_executor: ContractAddress,
block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct DownvoteCreated {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename event to Downvoted

@@ -266,7 +338,24 @@ pub mod PublicationComponent {
) -> PublicationType {
self._get_publication_type(profile_address, pub_id_assigned)
}
/// @notice retrieves a post vote_count
/// @param pub_id the ID of the publication whose count is to be retrieved
fn get_vote_count(self: @ComponentState<TContractState>, pub_id: u256) -> u256 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's have two functions to retrieve both the upvote and downvote counts. This should simply just return the value of the upvote and downvote struct items in the publication struct

@Darlington02 Darlington02 marked this pull request as ready for review September 14, 2024 10:50
@Darlington02 Darlington02 merged commit 09c5afd into main Sep 14, 2024
4 checks passed
@Darlington02 Darlington02 deleted the feature/new_publication_features branch September 14, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants