Skip to content

Commit

Permalink
chore: lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Oct 2, 2024
1 parent 7a808ee commit 31bb432
Show file tree
Hide file tree
Showing 6 changed files with 74,539 additions and 172 deletions.
124 changes: 33 additions & 91 deletions src/Social.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
pragma solidity 0.8.18;

import "./interfaces/ISocial.sol";
import {
Social__InValidCharacterId,
Social__InValidPostId,
Social__InValidCommentId
} from "./Error.sol";
import {Social__InValidCharacterId, Social__InValidPostId, Social__InValidCommentId} from "./Error.sol";

/**
* @title Social Contract
Expand Down Expand Up @@ -97,12 +93,7 @@ contract Social is ISocial {
* @param postId The id of the post
* @param commentId The id of the comment
*/
event CommentCreated(
address indexed owner,
uint256 indexed characterId,
uint256 indexed postId,
uint256 commentId
);
event CommentCreated(address indexed owner, uint256 indexed characterId, uint256 indexed postId, uint256 commentId);

/*
* @dev This event is emitted when a comment is updated
Expand All @@ -111,12 +102,7 @@ contract Social is ISocial {
* @param postId The id of the post
* @param commentId The id of the comment
*/
event CommentUpdated(
address indexed owner,
uint256 indexed characterId,
uint256 indexed postId,
uint256 commentId
);
event CommentUpdated(address indexed owner, uint256 indexed characterId, uint256 indexed postId, uint256 commentId);

/*
* @dev This event is emitted when a comment is deleted
Expand All @@ -125,12 +111,7 @@ contract Social is ISocial {
* @param postId The id of the post
* @param commentId The id of the comment
*/
event CommentDeleted(
address indexed owner,
uint256 indexed characterId,
uint256 indexed postId,
uint256 commentId
);
event CommentDeleted(address indexed owner, uint256 indexed characterId, uint256 indexed postId, uint256 commentId);

modifier validCharacterId(uint256 characterId) {
if (characterId <= 0) revert Social__InValidCharacterId(characterId);
Expand All @@ -155,14 +136,8 @@ contract Social is ISocial {
string calldata avatarUrl
) external override returns (uint256 characterId) {
characterId = ++_characterIdIndex;
_characters[characterId] = Character({
owner: msg.sender,
id: characterId,
handle: handle,
name: name,
bio: bio,
avatarUrl: avatarUrl
});
_characters[characterId] =
Character({owner: msg.sender, id: characterId, handle: handle, name: name, bio: bio, avatarUrl: avatarUrl});
emit CharacterCreated(msg.sender, characterId);
}

Expand All @@ -189,71 +164,56 @@ contract Social is ISocial {
}

/// @inheritdoc ISocial
function createPost(
uint256 characterId,
string calldata title,
string calldata content
) external override validCharacterId(characterId) returns (uint256 postId) {
function createPost(uint256 characterId, string calldata title, string calldata content)
external
override
validCharacterId(characterId)
returns (uint256 postId)
{
postId = ++_postIdIndex[characterId];
_posts[characterId][postId] = Post({
characterId: characterId,
id: postId,
title: title,
content: content
});
_posts[characterId][postId] = Post({characterId: characterId, id: postId, title: title, content: content});
emit PostCreated(msg.sender, characterId, postId);
}

/// @inheritdoc ISocial
function updatePost(
uint256 characterId,
uint256 postId,
string calldata title,
string calldata content
) external override validCharacterId(characterId) validPostId(postId) {
function updatePost(uint256 characterId, uint256 postId, string calldata title, string calldata content)
external
override
validCharacterId(characterId)
validPostId(postId)
{
Post storage post = _posts[characterId][postId];
post.title = title;
post.content = content;
emit PostUpdated(msg.sender, characterId, postId);
}

/// @inheritdoc ISocial
function deletePost(
uint256 characterId,
uint256 postId
) external override validCharacterId(characterId) validPostId(postId) {
function deletePost(uint256 characterId, uint256 postId)
external
override
validCharacterId(characterId)
validPostId(postId)
{
delete _posts[characterId][postId];
emit PostDeleted(msg.sender, characterId, postId);
}

/// @inheritdoc ISocial
function createComment(
uint256 characterId,
uint256 postId,
string calldata content
)
function createComment(uint256 characterId, uint256 postId, string calldata content)
external
override
validCharacterId(characterId)
validPostId(postId)
returns (uint256 commentId)
{
commentId = ++_commentIdIndex[characterId][postId];
_comments[characterId][postId][commentId] = Comment({
postId: postId,
id: commentId,
content: content
});
_comments[characterId][postId][commentId] = Comment({postId: postId, id: commentId, content: content});
emit CommentCreated(msg.sender, characterId, postId, commentId);
}

/// @inheritdoc ISocial
function updateComment(
uint256 characterId,
uint256 postId,
uint256 commentId,
string calldata content
)
function updateComment(uint256 characterId, uint256 postId, uint256 commentId, string calldata content)
external
override
validCharacterId(characterId)
Expand All @@ -266,11 +226,7 @@ contract Social is ISocial {
}

/// @inheritdoc ISocial
function deleteComment(
uint256 characterId,
uint256 postId,
uint256 commentId
)
function deleteComment(uint256 characterId, uint256 postId, uint256 commentId)
external
override
validCharacterId(characterId)
Expand All @@ -282,19 +238,12 @@ contract Social is ISocial {
}

/// @inheritdoc ISocial
function getCharacter(
uint256 characterId
)
function getCharacter(uint256 characterId)
external
view
override
validCharacterId(characterId)
returns (
string memory handle,
string memory name,
string memory bio,
string memory avatarUrl
)
returns (string memory handle, string memory name, string memory bio, string memory avatarUrl)
{
Character storage character = _characters[characterId];
handle = character.handle;
Expand All @@ -304,10 +253,7 @@ contract Social is ISocial {
}

/// @inheritdoc ISocial
function getPost(
uint256 characterId,
uint256 postId
)
function getPost(uint256 characterId, uint256 postId)
external
view
override
Expand All @@ -321,11 +267,7 @@ contract Social is ISocial {
}

/// @inheritdoc ISocial
function getComment(
uint256 characterId,
uint256 postId,
uint256 commentId
)
function getComment(uint256 characterId, uint256 postId, uint256 commentId)
external
view
override
Expand Down
Loading

0 comments on commit 31bb432

Please sign in to comment.