-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.cpp
More file actions
93 lines (74 loc) · 2.21 KB
/
Copy pathpost.cpp
File metadata and controls
93 lines (74 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// post.cpp
#include "post.h"
#include "user.h"
int post::nextPostId = 1;
post::post() : likesCount(0), postName(""), postDescription(""), owner(nullptr), postId(NULL) {}
user* post::getOwner() const {
return owner;
}
int post::getLikesCount() const {
return likesCount;
}
int post::getPostId() const {
return postId;
}
string post::getPostName() const {
return postName;
}
string post::getPostDescription() const {
return postDescription;
}
void post::setPostName(const string& newName) {
postName = newName;
}
void post::setPostDescription(const string& newDescription) {
postDescription = newDescription;
}
post::post(user* receiveOwner, const string receiveName, const string receiveDescription)
: likesCount(0), postId(nextPostId++), postName(receiveName), postDescription(receiveDescription) {
owner = receiveOwner;
receiveOwner->createPost(this);
}
void post::likePost(user* receiveUser) {
usersThatLiked.insert(receiveUser);
likesCount++;
}
void post::removeLike(user* receiveUser) {
if (usersThatLiked.search(receiveUser)) {
usersThatLiked.remove(receiveUser);
likesCount--;
}
}
bool post::isOwner(user* receiveOwner) {
return (owner == receiveOwner);
}
void post::editName(user* receiveOwner, string receivePostName) {
if (isOwner(receiveOwner)) {
postName = receivePostName;
}
}
void post::editDescription(user* receiveOwner, string receivePostDescription) {
if (isOwner(receiveOwner)) {
postDescription = receivePostDescription;
}
}
void post::displayUsersThatLiked() {
if (likesCount == 0) {
cout << "No users have liked this post." << endl;
}
else {
listNode<user*>* tempTraversingPointer = usersThatLiked.getHead();
while (tempTraversingPointer) {
cout << tempTraversingPointer->data->getUserName() << endl;
tempTraversingPointer = tempTraversingPointer->next;
}
}
}
void post::display() {
cout << "Post ID: " << postId << endl;
cout << "Post Name: " << postName << endl;
cout << "Post Description: " << postDescription << endl;
cout << "Likes: " << likesCount << endl;
cout << "Liked By Users: ";
displayUsersThatLiked();
}