-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostController.java
More file actions
40 lines (33 loc) · 1.18 KB
/
PostController.java
File metadata and controls
40 lines (33 loc) · 1.18 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
package controllers;
import interfaces.IPostService;
import models.Post;
import models.User;
import java.util.List;
public class PostController {
private IPostService postService;
// Dependency Injection
public PostController(IPostService service) {
this.postService = service;
}
public void createNewPost(String content, User author) {
if(content.isEmpty()) {
System.out.println("Error: Post content cannot be empty.");
return;
}
postService.createPost(content, author);
}
// New Function: Display the Timeline
public void showAllPosts() {
System.out.println("\n--- Timeline (News Feed) ---");
// Fetch data from Service Layer
List<Post> allPosts = postService.getAllPosts();
if (allPosts.isEmpty()) {
System.out.println("No posts available to display.");
} else {
for (Post p : allPosts) {
System.out.println("@" + p.getAuthor().getFullName() + ": " + p.getContent());
System.out.println("-----------------------------");
}
}
}
}