-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anupam Rai
committed
Aug 24, 2017
0 parents
commit 9ba243b
Showing
31 changed files
with
828 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>discussion-forum</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# discussion-forum |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package com.forum.main; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import com.forum.units.User; | ||
import com.forum.units.UserRole; | ||
|
||
import discusion.forum.activiy.UserActivity; | ||
import discussion.forum.units.service.UserService; | ||
|
||
public class UserInterface { | ||
public static User user; | ||
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
public static UserActivity userActivity; | ||
|
||
public static void main(String args[]) throws IOException { | ||
UserService.createUser("admin", "admin", "admin", UserRole.ADMIN); | ||
userActivity = new UserActivity(); | ||
while (true) { | ||
userActivity.loginActivity(); | ||
if (user == null) | ||
continue; | ||
System.out.println("Welcome " + user.getUsername()); | ||
menu(); | ||
} | ||
} | ||
|
||
public static void menu() throws NumberFormatException, IOException { | ||
while (true) { | ||
int menuIndex = 0; | ||
if (user.getUserRole() == UserRole.ADMIN) { | ||
System.out.println(++menuIndex + " Create new user"); | ||
} | ||
System.out.println(++menuIndex + " Ask a question"); | ||
System.out.println(++menuIndex + " See all questions"); | ||
System.out.println(++menuIndex + " Log Out"); | ||
System.out.println("\n Enter your choice"); | ||
if (!classifyMenuChoice(Integer.parseInt(br.readLine()))) | ||
break; | ||
|
||
} | ||
} | ||
|
||
public static boolean classifyMenuChoice(int choice) throws IOException { | ||
if (UserRole.ADMIN != UserInterface.user.getUserRole()) { | ||
choice++; | ||
} | ||
while (true) { | ||
switch (choice) { | ||
case 1: | ||
userActivity.createNewUser(); | ||
return true; | ||
case 2: | ||
userActivity.postNewQuestion(); | ||
return true; | ||
case 3: | ||
userActivity.seeAllQuestions(); | ||
return true; | ||
case 4: | ||
return false; | ||
default: | ||
System.out.println("Wrong choice. Try again"); | ||
} | ||
} | ||
} | ||
|
||
public static UserRole roleFromMenu() throws NumberFormatException, IOException { | ||
int menuIndex = 0; | ||
System.out.println(++menuIndex + UserRole.ADMIN.toString()); | ||
System.out.println(++menuIndex + UserRole.MODERATOR.toString()); | ||
System.out.println(++menuIndex + UserRole.USER.toString()); | ||
while (true) { | ||
System.out.println("\n Enter your choice"); | ||
int choice = Integer.parseInt(br.readLine()); | ||
switch (choice) { | ||
case 1: | ||
return UserRole.ADMIN; | ||
case 2: | ||
return UserRole.MODERATOR; | ||
case 3: | ||
return UserRole.USER; | ||
default: | ||
System.out.println("Wrong choice. Try again"); | ||
} | ||
} | ||
} | ||
|
||
public static void questionMenu() throws NumberFormatException, IOException { | ||
while (true) { | ||
int menuIndex = 0; | ||
System.out.println(++menuIndex + " Upvote a question"); | ||
System.out.println(++menuIndex + " Reply to a question"); | ||
System.out.println(++menuIndex + " See replies for a question"); | ||
System.out.println(++menuIndex + " Delete a question"); | ||
System.out.println(++menuIndex + " Return to main menu"); | ||
System.out.println("\n Enter your choice"); | ||
if (!processQuestionChoice(Integer.parseInt(br.readLine()))) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static boolean processQuestionChoice(int choice) throws NumberFormatException, IOException { | ||
while (true) { | ||
switch (choice) { | ||
case 1: | ||
userActivity.upvoteQuestion(); | ||
return true; | ||
case 2: | ||
userActivity.replyToQuestion(); | ||
return true; | ||
case 3: | ||
userActivity.seeAllReplies(); | ||
return true; | ||
case 4: | ||
userActivity.deleteQuestion(); | ||
return true; | ||
case 5: | ||
return false; | ||
default: | ||
System.out.println("Wrong choice. Try again"); | ||
} | ||
} | ||
} | ||
|
||
public static void replyMenu() throws NumberFormatException, IOException { | ||
while (true) { | ||
int menuIndex = 0; | ||
System.out.println(++menuIndex + " Upvote a reply"); | ||
System.out.println(++menuIndex + " Delete a reply"); | ||
System.out.println(++menuIndex + " Return to question menu"); | ||
System.out.println("\n Enter your choice"); | ||
if (!processReplyChoice(Integer.parseInt(br.readLine()))) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static boolean processReplyChoice(int choice) throws NumberFormatException, IOException { | ||
while (true) { | ||
switch (choice) { | ||
case 1: | ||
userActivity.upvoteReply(); | ||
return true; | ||
case 2: | ||
userActivity.deleteReply(); | ||
return true; | ||
case 3: | ||
return false; | ||
default: | ||
System.out.println("Wrong choice. Try again"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.forum.units; | ||
|
||
public class Question extends TimeStamp { | ||
|
||
private String title; | ||
private String message; | ||
private User user; | ||
private int upVoteCount = 0; | ||
private long id; | ||
private static Long lastEntry = 0L; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId() { | ||
lastEntry = lastEntry + 1L; | ||
this.id = lastEntry; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
public int getUpVoteCount() { | ||
return upVoteCount; | ||
} | ||
|
||
public void increaseUpVoteCount() { | ||
this.upVoteCount = this.upVoteCount + 1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.forum.units; | ||
|
||
public class Reply extends TimeStamp { | ||
private String message; | ||
private User user; | ||
private Question question; | ||
private long id; | ||
private static Long lastEntry = 0L; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId() { | ||
lastEntry = lastEntry + 1L; | ||
this.id = lastEntry; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
public Question getQuestion() { | ||
return question; | ||
} | ||
|
||
public void setQuestion(Question question) { | ||
this.question = question; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.forum.units; | ||
|
||
import java.util.Date; | ||
|
||
import com.forum.util.Utility; | ||
|
||
public abstract class TimeStamp { | ||
|
||
private Date created; | ||
|
||
public Date getCreated() { | ||
return created; | ||
} | ||
|
||
public void setCreated() { | ||
this.created = Utility.getCurrentDate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.forum.units; | ||
|
||
public class Upvote extends TimeStamp { | ||
private Question question; | ||
private Reply reply; | ||
private User user; | ||
private long id; | ||
private static Long lastEntry = 0L; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId() { | ||
lastEntry = lastEntry + 1L; | ||
this.id = lastEntry; | ||
} | ||
|
||
public Question getQuestion() { | ||
return question; | ||
} | ||
|
||
public void setQuestion(Question question) { | ||
this.question = question; | ||
} | ||
|
||
public Reply getReply() { | ||
return reply; | ||
} | ||
|
||
public void setReply(Reply reply) { | ||
this.reply = reply; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
} |
Oops, something went wrong.