Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e6f917c
Merge: ea70b2f 3c6b84b
Author: Robert Rachita <72192997+robertrachita@users.noreply.github.com>
Date:   Fri Mar 31 20:45:17 2023 +0200

    Merge branch 'developing'

commit 3c6b84b
Author: Robert Rachita <72192997+robertrachita@users.noreply.github.com>
Date:   Fri Mar 31 20:43:08 2023 +0200

    fixed merge conflits

    >plus fixed crash when no like was selected

    Co-Authored-By: stefanuntura <56734208+stefanuntura@users.noreply.github.com>

commit 2430f8b
Merge: 5de154f cfc046f
Author: Robert Rachita <72192997+robertrachita@users.noreply.github.com>
Date:   Fri Mar 31 20:35:55 2023 +0200

    Merge branch 'observorAndIterator' into merge_template

commit 5de154f
Merge: 2c6438b d87fa6f
Author: Robert Rachita <72192997+robertrachita@users.noreply.github.com>
Date:   Fri Mar 31 20:33:15 2023 +0200

    Merge branch 'decorator_final' into merge_template

commit 2c6438b
Author: Robert Rachita <72192997+robertrachita@users.noreply.github.com>
Date:   Fri Mar 31 19:09:40 2023 +0200

    Readme Update (#5)

commit cfc046f
Author: Stefan Untura <u_stefan@mail.com>
Date:   Fri Mar 31 18:56:13 2023 +0200

    Home and about improvements

commit e045386
Author: Stefan Untura <u_stefan@mail.com>
Date:   Fri Mar 31 18:45:58 2023 +0200

    Observer pattern functionality

commit eccdb70
Author: Stefan Untura <u_stefan@mail.com>
Date:   Fri Mar 31 18:03:46 2023 +0200

    Iterate over model and display posts list using iterator

commit d87fa6f
Author: christo_stevan <christostevan2501@gmail.com>
Date:   Fri Mar 31 18:03:28 2023 +0200

    adding comment works

commit ec210b3
Author: christo_stevan <christostevan2501@gmail.com>
Date:   Fri Mar 31 15:40:56 2023 +0200

    Implementation finished
  • Loading branch information
robertrachita committed Mar 31, 2023
1 parent 8432506 commit 679eabf
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 46 deletions.
11 changes: 10 additions & 1 deletion Controllers/CreatePostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace DesignPatterns_SocialMedia.Controllers
{
public class CreatePostController : Controller
public class CreatePostController : Controller, Subscriber
{
private readonly PostCreator textPostCreator = new TextPostCreator();
private readonly PostCreator imagePostCreator = new ImagePostCreator();
Expand All @@ -14,6 +14,7 @@ public class CreatePostController : Controller
private string? postTitle;
private string? postContent;
private string? postType;

Button createButton = new CreateButton();


Expand All @@ -27,6 +28,8 @@ public IActionResult CreatePost(string title, string content)
{
try
{
createButton.AddSubscriber(this);

ViewData["postTitle"] = Request.Form["postTitle"].First();
ViewData["postContent"] = Request.Form["postContent"].First();
ViewData["postType"] = Request.Form["postType"].First();
Expand Down Expand Up @@ -56,6 +59,8 @@ public IActionResult CreatePost(string title, string content)
return RedirectToAction("Index", "Home");
break;
}

createButton.NotifySubscribers();
return RedirectToAction("Posts", "Posts");
}
catch
Expand All @@ -80,5 +85,9 @@ private Post CreateVideoPost(int id, String content, String title)
return videoPostCreator.CreatePost(id, content, title);
}

public void Update()
{
JavaScriptHandler.javaScriptAlert = "ALERT!: Post created successfully!";
}
}
}
47 changes: 42 additions & 5 deletions Controllers/PostsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

namespace DesignPatterns_SocialMedia.Controllers
{
public class PostsController : Controller
public class PostsController : Controller, Subscriber
{
private readonly ILogger<HomeController> _logger;

private EditButton editButton = new EditButton();

public PostsController(ILogger<HomeController> logger)
{
_logger = logger;
Expand All @@ -28,13 +30,43 @@ public ActionResult ViewPost(int id)
}

[HttpPost]
public ActionResult ViewPost(int id, int value)
public ActionResult ViewPost(int id, int content)
{
editButton.AddSubscriber(this);

Post post = getPostById(id);

var value = Request.Form["selectLike"].First() as String;
LikeDecorator like = new LikeDecorator();
post.AddLike(like);
post.AddComment(value.ToString());

switch(value)
{
case "2":
like = new SuperLikeDecorator();
break;
case "3":
like = new DislikeDecorator();
break;
default:
break;
}

editButton.NotifySubscribers();

post.AddLike(like);

return RedirectToAction("Posts", "Posts");
}

[HttpPost]
public ActionResult addComment()
{
var ID = Request.Form["PostId"].First() as String;
var id = int.Parse(ID);
Post post = getPostById(id);
string comment = Request.Form["postComment"].First() as String;
post.AddComment(comment);
editButton.NotifySubscribers();

return RedirectToAction("Posts", "Posts");
}
Expand All @@ -50,5 +82,10 @@ private Post getPostById(int id)
}
return null;
}

public void Update()
{
JavaScriptHandler.javaScriptAlert = "ALERT: Post edited successfuly!";
}
}
}
}
8 changes: 6 additions & 2 deletions Iterator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace DesignPatterns_SocialMedia
using DesignPatterns_SocialMedia.Models;

namespace DesignPatterns_SocialMedia
{
public interface Iterator
{
public Boolean hasNext();
public Object next();

public Boolean isLast();
public Post next();
}
}
7 changes: 7 additions & 0 deletions JavaScriptHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DesignPatterns_SocialMedia
{
public static class JavaScriptHandler
{
public static string javaScriptAlert = "";
}
}
8 changes: 4 additions & 4 deletions Models/CreatedPosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public static class CreatedPosts

static CreatedPosts()
{
posts.Add(CreateTextPost(1, "This is the content", "This is the title"));
posts.Add(CreateTextPost(2, "This is the content again", "Text Post"));
posts.Add(CreateImagePost(3, "https://i.redd.it/5gnz9r0fcaqa1.jpg", "Image Post"));
posts.Add(CreateVideoPost(4, "https://vimeo.com/810735707", "Video Post"));
posts.Add(CreateTextPost(0, "This is the content", "This is the title"));
posts.Add(CreateTextPost(1, "This is the content again", "Text Post"));
posts.Add(CreateImagePost(2, "https://i.redd.it/5gnz9r0fcaqa1.jpg", "Image Post"));
posts.Add(CreateVideoPost(3, "https://vimeo.com/810735707", "Video Post"));
}

public static Post GetPostByID(int id)
Expand Down
10 changes: 10 additions & 0 deletions Models/EditButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DesignPatterns_SocialMedia.Models
{
public class EditButton : Button
{
public override void Click()
{
NotifySubscribers();
}
}
}
12 changes: 11 additions & 1 deletion PostContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public class PostContainer : IterableCollection
{
private List<Post> posts { get; set; }

public PostContainer(List<Post> listOfPosts) {
posts = listOfPosts;
}

public Iterator createIterator()
{
if (posts == null) return null;
Expand Down Expand Up @@ -35,8 +39,14 @@ public Boolean hasNext()
return position < copyOfPosts.Count;
}

public Object next()
public Boolean isLast()
{
return position == copyOfPosts.Count;
}

public Post next()
{
if (this.isLast()) return copyOfPosts[position];
if (this.hasNext()) return copyOfPosts[position++];

return null;
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# Design-Patterns
# Design-Patterns

## Introduction
This document serves as a start document and project planning for the practical group assignment, part of the “Design Patterns”course. The scope of the course is to enable students to understand various design patterns.Design patterns are a toolkit of solutions to common problems in software design. It specifically concerns with communication between objects. This group project will be created in accordance and requirementsof the “OIDP -Design Patterns” Module book version 5.0 of 2022.

## Application description
The group intends to create a Social Media Platform. Such a platform will allow users to create posts and comments, and to like said posts. Additionally, it can notify users of new posts, comments,or reactions to already existing posts. The application will be presented as a web application and will be written in C# ASP.NET.

## Features
- Creating a post via GUI
- Displaying a list of posts
- Liking a post (self-created or another users)
- Commenting on a post (self-created or another users)

## Technology& Patterns Applied
The project will make use of different threading methods and techniques, as part of the course and required in implementing some of the features. These are as follows:
- GitHub
- C# ASP.NET
- Iterator - For iterating over the list of possible posts, comments and for filteringthem by different criteria (for instance date or length of the post). This will be manually implemented.
- Factory - For creating and managing the different types of objects (posts, comments, likes etc). The Factory pattern helps to encapsulate the creation and initialization of complex objects, and to provide a consistent interface for users to interact with them.
- Observer - For notifying users of new posts, comments, and likes. The Observer pattern helps to decouple the different components of the social media platform, and to provide a flexible and extensible architecture for handling user interactions and updates.Another use caseis analytics –
- Template - Different posts (image/text/video/hybrid)
- MVC - Forseparation of Concerns and Logic, and to ease the GUI interaction from a coding point of view.

The code can be found in the following public GitHub repository.The software used is Visual Studio 2022, and Figma for the UML.

## Group
The “Group” chapter provides an overview into the team responsible for the application development.

Christopher Sulistiyo - christopher.sulistiyo@student.nhlstenden.com - 4850025
Stefan Untura - stefan.untura@student.nhlstenden.com - 4839161
Robert Răchită - robert.rachita@student.nhlstenden.com - 4859367
9 changes: 1 addition & 8 deletions Views/CreatePost/CreatePost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
}
<h1>@ViewData["Title"]</h1>

<script>
document.getElementById("CreateButton").addEventListener("click", function () {
alert("Creating post...");
});
</script>


<form asp-controller="CreatePost" asp-action="CreatePost" method="post">
@Html.TextBox("postTitle")
@Html.TextBox("postContent")
Expand All @@ -18,4 +11,4 @@
</form>

<p>@ViewData["postTitle"]</p>
<p>@ViewData["postContent"]</p>
<p>@ViewData["postContent"]</p>
14 changes: 13 additions & 1 deletion Views/Home/About.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
}
<h1>@ViewData["Title"]</h1>

<p>replace later with readme.</p>
<h2>Introduction</h2>
<p>This document serves as a start document and project planning for the practical group assignment, part of the “Design Patterns”course. The scope of the course is to enable students to understand various design patterns.Design patterns are a toolkit of solutions to common problems in software design. It specifically concerns with communication between objects. This group project will be created in accordance and requirementsof the “OIDP -Design Patterns” Module book version 5.0 of 2022.</p>

<h2>Application description</h2>
<p>The group intends to create a Social Media Platform. Such a platform will allow users to create posts and comments, and to like said posts. Additionally, it can notify users of new posts, comments,or reactions to already existing posts. The application will be presented as a web application and will be written in C# ASP.NET.</p>

<h2>Features</h2>
<ul>
<li>Creating a post via GUI</li>
<li>Displaying a list of posts</li>
<li>Liking a post (self-created or another users)</li>
<li>Commenting on a post (self-created or another users)</li>
</ul>
6 changes: 5 additions & 1 deletion Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<h1 class="display-4">Welcome</h1><br/><br/>
<div class="tenor-gif-embed" data-postid="24427194" data-share-method="host" data-aspect-ratio="1.14695" data-width="100%">
<a href="https://tenor.com/view/127hater-spongebob-gif-24427194">127hater Spongebob GIF</a>from <a href="https://tenor.com/search/127hater-gifs">127hater GIFs</a>
</div>
<script type="text/javascript" async src="https://tenor.com/embed.js"></script>
</div>
51 changes: 34 additions & 17 deletions Views/Posts/Posts.cshtml
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
@{
ViewData["Title"] = "View Posts";
}
<script type="text/javascript" src="~/js/jquery.js"></script>
<h1>@ViewData["Title"]</h1>
<h1>@JavaScriptHandler.javaScriptAlert</h1>

<script type="text/javascript">
@JavaScriptHandler.javaScriptAlert;
</script>

<p>posts go here</p>

@model List<Post>

@foreach (Post post in Model)
{
@{
PostContainer postContainer = new PostContainer(Model);

Iterator postIterator = postContainer.createIterator();

Post post;

while (postIterator.hasNext())
{
post = postIterator.next();

<div class="post">
<p>Post number: @post.GetId()</p>
<h2>@post.GetTitle()</h2>
@if (post is ImagePost imagePost)
<p>Post number: @post.GetId()</p>
<h2>@post.GetTitle()</h2>
@if (post is ImagePost imagePost)
{
<img src="@imagePost.GetContent()" alt="image post" />
<img src="@imagePost.GetContent()" alt="image post" />
}
else if (post is TextPost textPost)
{
<p>@post.GetContent()</p>
<p>@post.GetContent()</p>
}
else if (post is VideoPost videoPost)
{
<iframe width="560" height="315" src="@videoPost.GetContent()" frameborder="0" allowfullscreen></iframe>
<iframe width="560" height="315" src="@videoPost.GetContent()" frameborder="0" allowfullscreen></iframe>
}
else
{
<p>Incorrect type post or source.</p>
<p>Incorrect type post or source.</p>
}
<p>@post.GetDateOfCreation()</p>
<div class="actions">
<button onclick="likePost(@post.GetId()">Like (@post.GetLikes())</button>
<button onclick="showComments(@post.GetId())">Comments (@post.GetComments().Count)</button>
@Html.ActionLink("Edit this post", "ViewPost", new {id = post.GetId()})
</div>
<p>@post.GetDateOfCreation()</p>
<div class="actions">
<button onclick="likePost(@post.GetId()">Like (@post.GetLikes())</button>
<button onclick="showComments(@post.GetId())">Comments (@post.GetComments().Count)</button>
@Html.ActionLink("Edit this post", "ViewPost", new {id = post.GetId()})
</div>
</div>
}
}
}



16 changes: 11 additions & 5 deletions Views/Posts/ViewPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ViewData["Title"] = "View";
}


<h1>View</h1>

<h4>Post</h4>
Expand All @@ -20,14 +21,19 @@

<form asp-action="ViewPost" asp-controller="Posts" method="post" >
<input type="hidden" value="@Model.GetId()" />
<img src="~/Image/Like.png" width="30" height="30">
<img src="~/Image/Superlike.png" width="30" height="30">
<img src="~/Image/Dislike.png" width="30" height="30">
@Html.RadioButton("selectLike", 1, true) <img src="~/Image/Like.png" width="30" height="30">
@Html.RadioButton("selectLike", 2) <img src="~/Image/Superlike.png" width="30" height="30">
@Html.RadioButton("selectLike", 3) <img src="~/Image/Dislike.png" width="30" height="30">
<button type="submit">Submit</button>
</form>

<p> @Model.GetId() </p>
<p>@Model.GetLikes() </p>
<form asp-action="addComment" asp-controller="Posts" method="post">
@Html.Hidden("PostId", Model.GetId())
<div class="comment-box comment-content">
@Html.TextBox("postComment")
</div>
<button type="submit">Post comment</button>
</form>


<div>
Expand Down
5 changes: 5 additions & 0 deletions wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ body {
background-color: #f9f9f9;
}

.comment-content {
margin-bottom: 10px;
line-height: 1.5;
}

.post {
border: 1px solid #ccc;
margin-bottom: 10px;
Expand Down

0 comments on commit 679eabf

Please sign in to comment.