Compare commits

..

8 Commits

Author SHA1 Message Date
Julien LEICHER
9f260f7424
add comments controller 2020-12-22 11:02:10 +01:00
Julien LEICHER
40f8d4b1dc
minor changes 2020-12-21 18:18:06 +01:00
YuukanOO
7a38bed6b9 add authentication in swagger ui 2020-12-21 16:47:43 +01:00
Julien LEICHER
e4bbb14640
add bearer authentication! 2020-12-21 12:24:13 +01:00
Julien LEICHER
b20901cff6
add needed routes in LinksController 2020-12-21 11:10:32 +01:00
YuukanOO
9627e4825a generate swagger.json on build 2020-12-18 15:06:24 +01:00
YuukanOO
6528f83028 add NSwag documentation 2020-12-18 14:50:07 +01:00
YuukanOO
b5c6292230 add empty web project! 2020-12-18 12:27:02 +01:00
16 changed files with 164 additions and 303 deletions

View File

@ -7,7 +7,6 @@ namespace HN.Application
public Guid Id { get; set; } public Guid Id { get; set; }
public string Content { get; set; } public string Content { get; set; }
public DateTime CreatedAt { get; set; } public DateTime CreatedAt { get; set; }
public string CreatedByName { get; set; }
public int UpVotes { get; set; } public int UpVotes { get; set; }
public int DownVotes { get; set; } public int DownVotes { get; set; }

View File

@ -18,13 +18,11 @@ namespace HN.Application
public Task<CommentDto[]> Handle(GetLinkCommentsQuery request, CancellationToken cancellationToken) public Task<CommentDto[]> Handle(GetLinkCommentsQuery request, CancellationToken cancellationToken)
{ {
var comments = from comment in _context.Comments var comments = from comment in _context.Comments
join user in _context.Users on comment.CreatedBy equals user.Id
where comment.LinkId == request.LinkId where comment.LinkId == request.LinkId
select new CommentDto select new CommentDto
{ {
Id = comment.Id, Id = comment.Id,
CreatedAt = comment.CreatedAt, CreatedAt = comment.CreatedAt,
CreatedByName = user.UserName,
Content = comment.Content, Content = comment.Content,
UpVotes = comment.Votes.Count(c => c.Type == VoteType.Up), UpVotes = comment.Votes.Count(c => c.Type == VoteType.Up),
DownVotes = comment.Votes.Count(c => c.Type == VoteType.Down) DownVotes = comment.Votes.Count(c => c.Type == VoteType.Down)

View File

@ -12,7 +12,6 @@ namespace Website.Models
[Required] [Required]
[Compare(nameof(Password))] [Compare(nameof(Password))]
[Display(Name = "Password confirmation")]
public string PasswordConfirm { get; set; } public string PasswordConfirm { get; set; }
} }
} }

View File

@ -98,7 +98,7 @@ namespace Website
{ {
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Links}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
} }

View File

@ -1,20 +1,13 @@
@model LoginViewModel @model LoginViewModel
@{
ViewData["Title"] = "Login";
}
<form class="form" asp-action="Login" method="post"> <form asp-action="Login" method="post">
<div class="field"> <label asp-for="@Model.Username"></label>
<label asp-for="@Model.Username"></label> <input asp-for="@Model.Username" />
<input asp-for="@Model.Username" /> <span asp-validation-for="@Model.Username"></span>
<span asp-validation-for="@Model.Username"></span>
</div>
<div class="field"> <label asp-for="@Model.Password"></label>
<label asp-for="@Model.Password"></label> <input type="password" asp-for="@Model.Password" />
<input type="password" asp-for="@Model.Password" /> <span asp-validation-for="@Model.Password"></span>
<span asp-validation-for="@Model.Password"></span>
</div>
<button type="submit">Sign in</button> <button type="submit">Sign in</button>
</form> </form>

View File

@ -1,27 +1,17 @@
@model RegisterViewModel @model RegisterViewModel
@{
ViewData["Title"] = "Register";
}
<form class="form" asp-action="Register" method="post"> <form asp-action="Register" method="post">
<label asp-for="@Model.Username"></label>
<input asp-for="@Model.Username" />
<span asp-validation-for="@Model.Username"></span>
<div class="field"> <label asp-for="@Model.Password"></label>
<label asp-for="@Model.Username"></label> <input type="password" asp-for="@Model.Password" />
<input asp-for="@Model.Username" /> <span asp-validation-for="@Model.Password"></span>
<span asp-validation-for="@Model.Username"></span>
</div>
<div class="field"> <label asp-for="@Model.PasswordConfirm"></label>
<label asp-for="@Model.Password"></label> <input type="password" asp-for="@Model.PasswordConfirm" />
<input type="password" asp-for="@Model.Password" /> <span asp-validation-for="@Model.PasswordConfirm"></span>
<span asp-validation-for="@Model.Password"></span>
</div>
<div class="field">
<label asp-for="@Model.PasswordConfirm"></label>
<input type="password" asp-for="@Model.PasswordConfirm" />
<span asp-validation-for="@Model.PasswordConfirm"></span>
</div>
<button type="submit">Register</button> <button type="submit">Register</button>
</form> </form>

View File

@ -3,16 +3,15 @@
ViewData["Title"] = "Post a new link"; ViewData["Title"] = "Post a new link";
} }
<form class="form" method="post"> <form method="post">
@* @Html.LabelFor(m => m.Url) <div>
@* @Html.LabelFor(m => m.Url)
@Html.EditorFor(m => m.Url) @Html.EditorFor(m => m.Url)
@Html.ValidationMessageFor(m => m.Url) *@ @Html.ValidationMessageFor(m => m.Url) *@
<div class="field">
<label asp-for="@Model.Url"></label> <label asp-for="@Model.Url"></label>
<input asp-for="@Model.Url" /> <input asp-for="@Model.Url" />
<span asp-validation-for="@Model.Url"></span> <span asp-validation-for="@Model.Url"></span>
</div> </div>
<button type="submit">Post!</button> <button type="submit">Post!</button>
</form> </form>

View File

@ -3,9 +3,10 @@
ViewData["Title"] = "Latest Links"; ViewData["Title"] = "Latest Links";
} }
<a class="mb" asp-action="Create" title="New post">Share a link with the world!</a> <a asp-action="Create" title="New post">Post a new super duber link</a>
<ul class="links"> <p>Here are the links</p>
<ul>
@foreach (var link in Model) @foreach (var link in Model)
{ {
<li> <li>

View File

@ -1,22 +1,14 @@
@model ShowLinkViewModel @model ShowLinkViewModel
@{
ViewData["Title"] = "Viewing";
}
<partial name="_LinkItem" model="@Model.Link" /> <partial name="_LinkItem" model="@Model.Link" />
@if (Model.Comments.Length == 0) @if(Model.Comments.Length == 0) {
{ <p>No comments yet</p>
<p class="no-comment-yet">No comments yet</p> } else {
} <ul>
else @foreach (var comment in Model.Comments)
{
<ul class="comments">
@foreach (var comment in Model.Comments)
{ {
<li> <li><partial name="_CommentItem" model="@comment" /></li>
<partial name="_CommentItem" model="@comment" />
</li>
} }
</ul> </ul>
} }

View File

@ -1,2 +1,2 @@
<a asp-action="Register" asp-controller="Accounts">Register</a> or <a asp-action="Login" asp-controller="Accounts">Sign <a asp-action="Register" asp-controller="Accounts">Register</a>
in</a> <a asp-action="Login" asp-controller="Accounts">Sign in</a>

View File

@ -1,6 +1,4 @@
<div class="loggedin-panel"> <p>Connected as @User.Identity.Name</p>
<p>Connected as <strong>@User.Identity.Name</strong></p> <form asp-action="Logout" asp-controller="Accounts" method="post">
<form asp-action="Logout" asp-controller="Accounts" method="post"> <button type="submit">Sign out</button>
<button class="loggedin-panel__out" type="submit">Sign out</button> </form>
</form>
</div>

View File

@ -1,21 +1,16 @@
@model HN.Application.CommentLinkCommand @model HN.Application.CommentLinkCommand
<div> <div>
<h3 class="add-a-comment">Add a comment</h3> <h2>Add a comment</h2>
@if (User.Identity.IsAuthenticated) @if(User.Identity.IsAuthenticated) {
{ <form asp-action="Create" asp-controller="Comments" method="post">
<form class="form" asp-action="Create" asp-controller="Comments" method="post"> <input type="hidden" asp-for="@Model.LinkId" />
<div class="field"> <textarea asp-for="@Model.Content"></textarea>
<input type="hidden" asp-for="@Model.LinkId" /> <span asp-validation-for="@Model.Content"></span>
<textarea asp-for="@Model.Content"></textarea>
<span asp-validation-for="@Model.Content"></span>
</div>
<button type="submit">Post a comment</button> <button type="submit">Post a comment</button>
</form> </form>
} } else {
else
{
<p>Only logged in users can comment.</p> <p>Only logged in users can comment.</p>
} }
</div> </div>

View File

@ -1,21 +1,14 @@
@model HN.Application.CommentDto @model HN.Application.CommentDto
<article class="comment"> <span>@Model.Content</span>
<p>@Model.Content</p> <div>
<ul class="comment__actions"> 👍: @Model.UpVotes / 👎: @Model.DownVotes
<li>posted at @Model.CreatedAt.ToLocalTime() by <strong>@Model.CreatedByName</strong></li> </div>
<li>
<strong>@Model.UpVotes</strong> 👍 / <strong>@Model.DownVotes</strong> 👎 @if (User.Identity.IsAuthenticated) {
</li> <form asp-action="Vote" asp-controller="Comments" asp-route-id="@Model.Id" method="post">
@if (User.Identity.IsAuthenticated) <input type="hidden" name="redirectTo" value="@Context.Request.Path" />
{ <input type="submit" name="type" value="up" />
<li> <input type="submit" name="type" value="down" />
<form class="votable" asp-controller="Comments" asp-action="Vote" asp-route-id="@Model.Id" method="post"> </form>
<input type="hidden" name="redirectTo" value="@Context.Request.Path" /> }
vote&nbsp;<input type="submit" name="type" value="up" />&nbsp;or&nbsp;<input type="submit" name="type"
value="down" />
</form>
</li>
}
</ul>
</article>

View File

@ -1,31 +1,51 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Website</title> <title>@ViewData["Title"] - Website</title>
<link rel="stylesheet" asp-append-version="true" href="~/css/site.css" /> <link rel="stylesheet" asp-append-version="true" href="~/css/site.css" />
</head> </head>
<body> <body>
<header class="topnav"> <header>
<div class="logo"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<a class="logo__link" href="/" title="back home">hn-dotnet</a> <div class="container">
</div> <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Website</a>
<div class="topnav__account"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
<vc:login /> aria-expanded="false" aria-label="Toggle navigation">
</div> <span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Links" asp-action="Index">Links</a>
</li>
</ul>
</div>
<vc:login />
</div>
</nav>
</header> </header>
<div class="container">
<main class="main-content">
<partial name="_FlashMessage" /> <partial name="_FlashMessage" />
<h1 class="main-content__title">@ViewData["Title"]</h1> <main role="main" class="pb-3">
@RenderBody() @RenderBody()
</main> </main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2020 - Website - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/js/site.js" asp-append-version="true"></script> <script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false) @await RenderSectionAsync("Scripts", required: false)
</body> </body>
</html> </html>

View File

@ -1,26 +1,11 @@
@model HN.Application.LinkDto @model HN.Application.LinkDto
<article class="link"> <a asp-action="Show" asp-controller="Links" asp-route-id="@Model.Id">@Model.Url - created at @Model.CreatedAt.ToLocalTime() by @Model.CreatedByName (👍: @Model.UpVotes / 👎: @Model.DownVotes)</a>
<h2>
<a class="link_title" href="@Model.Url" rel="nofollow">@Model.Url</a>
</h2>
<ul class="link__actions"> @if(User.Identity.IsAuthenticated) {
<li><a asp-action="Show" asp-controller="Links" asp-route-id="@Model.Id">🔍 view</a></li> <form asp-controller="Links" asp-action="Vote" asp-route-id="@Model.Id" asp-route-url="@Model.Url" method="post">
<li>posted at @Model.CreatedAt.ToLocalTime() by <strong>@Model.CreatedByName</strong></li> <input type="hidden" name="redirectTo" value="@Context.Request.Path" />
<li> <input type="submit" name="type" value="up" />
<strong>@Model.UpVotes</strong> 👍 / <strong>@Model.DownVotes</strong> 👎 <input type="submit" name="type" value="down" />
</li> </form>
@if (User.Identity.IsAuthenticated) }
{
<li>
<form class="votable" asp-controller="Links" asp-action="Vote" asp-route-id="@Model.Id" asp-route-url="@Model.Url"
method="post">
<input type="hidden" name="redirectTo" value="@Context.Request.Path" />
vote&nbsp;<input type="submit" name="type" value="up" />&nbsp;or&nbsp;<input type="submit" name="type"
value="down" />
</form>
</li>
}
</ul>
</article>

View File

@ -1,172 +1,71 @@
* { /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
margin: 0; for details on configuring this project to bundle and minify static web assets. */
padding: 0;
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
/* Provide sufficient contrast against white background */
a {
color: #0366d6;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
/* Sticky footer styles
-------------------------------------------------- */
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
} }
body { body {
background-color: #efefef; /* Margin bottom by footer height */
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, margin-bottom: 60px;
"Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1em;
line-height: 1.4;
} }
.footer {
a { position: absolute;
color: darkblue; bottom: 0;
}
.mb {
display: block;
margin-bottom: 1rem;
}
.topnav {
background-color: orangered;
color: rgba(255, 255, 255, 0.87);
display: flex;
justify-content: space-between;
padding: 1rem;
}
.topnav a {
color: white;
font-weight: bold;
text-decoration: none;
}
.loggedin-panel {
display: flex;
align-items: center;
}
.loggedin-panel__out {
background-color: transparent;
border: none;
color: white;
cursor: pointer;
font: inherit;
font-weight: bold;
margin-left: 1rem;
appearance: none;
}
.main-content {
margin: 2rem auto;
max-width: 900px;
width: 100%; width: 100%;
} white-space: nowrap;
line-height: 60px; /* Vertically center the text there */
.main-content__title {
font-size: 2rem;
font-weight: bolder;
color: gray;
}
.links,
.comments {
list-style-type: none;
}
.link,
.form {
background-color: white;
padding: 1rem;
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.12);
margin-bottom: 1rem;
}
.link_title {
color: rgba(0, 0, 0, 0.87);
font-size: 1.25rem;
font-weight: bold;
text-decoration: none;
}
.link_title:hover,
.link_title:focus {
text-decoration: underline;
}
.link__actions,
.comment__actions {
align-items: center;
color: rgba(0, 0, 0, 0.54);
display: flex;
list-style-type: none;
}
.link__actions li + li,
.comment__actions li + li {
margin-left: 1rem;
}
.link__actions a,
.comment__actions a {
text-decoration: none;
}
.link__actions a:hover,
.link__actions a:focus,
.comment__actions a:hover,
.comment__actions a:focus {
text-decoration: underline;
}
label,
input,
.field-validation-error {
display: block;
}
label {
font-weight: bold;
}
.field-validation-error {
color: orangered;
}
.field {
margin-bottom: 1rem;
}
.message {
background-color: bisque;
padding: 1rem;
margin-bottom: 1rem;
}
.votable {
align-items: center;
display: flex;
}
.no-comment-yet {
color: rgba(0, 0, 0, 0.72);
font-style: italic;
margin: 2rem 0;
}
.add-a-comment {
color: gray;
font-size: 1.25rem;
}
textarea {
color: inherit;
font: inherit;
width: 100%;
min-height: 100px;
}
.comments {
padding-left: 1rem;
}
.comment {
background-color: #fafafa;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.12);
padding: 1rem;
margin-bottom: 1rem;
} }