Skip to content

Commit

Permalink
Merge pull request #2 from davidsholoye/navigation
Browse files Browse the repository at this point in the history
Navigation
  • Loading branch information
NatalieJClark authored Nov 14, 2023
2 parents a924737 + b4418a9 commit 6fd6da6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/posts").hasRole("USER")
.antMatchers("/users").permitAll()
.and().formLogin();
.and().formLogin().loginPage("/login");
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ public class HomeController {
public RedirectView index() {
return new RedirectView("/posts");
}

@RequestMapping("/login")
public String login() {
return "login";
}
}

4 changes: 4 additions & 0 deletions src/main/java/com/makersacademy/acebook/model/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.makersacademy.acebook.model;

public class Comment {
}
18 changes: 16 additions & 2 deletions src/main/java/com/makersacademy/acebook/model/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import lombok.Data;

import java.sql.Timestamp;

@Data
@Entity
@Table(name = "POSTS")
Expand All @@ -18,12 +20,24 @@ public class Post {
private Long id;
private String content;

private Timestamp timestamp;

private Long userId;

public Post() {}

public Post(String content) {
public Post(String content, Timestamp timestamp, Long userId) {
this.content = content;
this.timestamp = timestamp;
this.userId = userId;
}
public String getContent() { return this.content; }
public String getContent() {return this.content;}
public void setContent(String content) { this.content = content; }

public Timestamp getTimestamp() {return this.timestamp;}
public void setTimestamp(Timestamp timestamp) { this.timestamp = timestamp; }

public Long getUserId() {return this.userId;}
public void setUserId(Long userId) { this.userId = userId; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE posts
ALTER COLUMN user_id
TYPE bigint;
32 changes: 32 additions & 0 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
<head>
<title tiles:fragment="title">Messages : Create</title>
</head>
<body>
<div tiles:fragment="content">
<form name="f" th:action="@{/login}" method="post">
<fieldset>
<legend>Please Login</legend>
<div th:if="${param.error}" class="alert alert-error">
Invalid username and password.
</div>
<div th:if="${param.logout}" class="alert alert-success">
You have been logged out.
</div>
<label for="username">Username</label>
<input type="text" id="username" name="username"/>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
<div class="form-actions">
<button type="submit" class="btn">Log in</button>
</div>
</fieldset>
</form>
<form name="f" th:action="@{/users/new}" method="get">
<div>
<button type="submit" class="btn">Sign up</button>
</div>
</form>
</div>
</body>
</html>
11 changes: 10 additions & 1 deletion src/test/java/com/makersacademy/acebook/model/PostTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

import org.junit.Test;

import java.sql.Timestamp;

public class PostTest {

private Post post = new Post("hello");
Timestamp timestamp = Timestamp.valueOf("2007-09-23 10:10:10.0");;

private Post post = new Post("hello", timestamp, 1L);

@Test
public void postHasContent() {
assertThat(post.getContent(), containsString("hello"));
}

// @Test
// public void postHasContent() {
// assertThat(post.getContent(), containsString("hello"));
// }
//
}

0 comments on commit 6fd6da6

Please sign in to comment.