forked from makersacademy/acebook-java-template
-
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
1 parent
95500d8
commit b539b7f
Showing
6 changed files
with
95 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/makersacademy/acebook/controller/UsersController.java
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,28 @@ | ||
package com.makersacademy.acebook.controller; | ||
|
||
import com.makersacademy.acebook.model.User; | ||
import com.makersacademy.acebook.repository.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.servlet.view.RedirectView; | ||
|
||
@Controller | ||
public class UsersController { | ||
|
||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@GetMapping("/users/new") | ||
public String signup() { | ||
return "users/new"; | ||
} | ||
|
||
@PostMapping("/users") | ||
public RedirectView signup(@ModelAttribute User user) { | ||
userRepository.save(user); | ||
return new RedirectView("/posts"); | ||
} | ||
} |
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,30 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.persistence.GenerationType; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
@Entity | ||
@Table(name = "USERS") | ||
public class User { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String username; | ||
private String email; | ||
private String password; | ||
|
||
public User() {} | ||
|
||
public User(String username, String email, String password) { | ||
this.username = username; | ||
this.email = email; | ||
this.password = password; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/makersacademy/acebook/repository/UserRepository.java
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,8 @@ | ||
package com.makersacademy.acebook.repository; | ||
|
||
import com.makersacademy.acebook.model.User; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface UserRepository extends CrudRepository<User, Long> { | ||
|
||
} |
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,8 @@ | ||
DROP TABLE IF EXISTS users; | ||
|
||
CREATE TABLE users ( | ||
id bigserial PRIMARY KEY, | ||
username varchar(100) NOT NULL, | ||
email varchar(100) NOT NULL, | ||
password varchar(100) NOT NULL | ||
); |
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Signup</title> | ||
</head> | ||
<body> | ||
<form action="/users" method="POST"> | ||
<label>Username</label><br> | ||
<input required="true" type="text" name="username"><br> | ||
<label>Email</label><br> | ||
<input required="true" type="text" name="email"><br> | ||
<label>Password</label><br> | ||
<input required="true" type="password" name="password"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |