working commit
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RecipefoliobackendApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RecipefoliobackendApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import com.wyattjmiller.home.recipefoliobackend.model.Recipe;
|
||||
|
||||
@RestController
|
||||
public class RecipeController {
|
||||
|
||||
private final RecipeRepository repository;
|
||||
|
||||
public RecipeController(RecipeRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@GetMapping("/recipe")
|
||||
List<Recipe> GetAllRecipes() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/recipe/{id}")
|
||||
Recipe GetOneRecipe(@PathVariable long id) {
|
||||
return repository.findById(id).get();
|
||||
}
|
||||
|
||||
@PostMapping("/recipe")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
Recipe PostRecipe(@RequestBody Recipe recipe) {
|
||||
return repository.save(recipe);
|
||||
}
|
||||
|
||||
@PutMapping("/recipe/{id}")
|
||||
Recipe PutRecipe(@RequestBody Recipe recipe, @PathVariable long id) {
|
||||
return repository.findById(id)
|
||||
.map(r -> {
|
||||
r.setName(recipe.getName());
|
||||
r.setDescription(recipe.getDescription());
|
||||
r.setIngredients(recipe.getIngredients());
|
||||
return repository.save(r);
|
||||
})
|
||||
.orElseGet(() -> {
|
||||
recipe.setId(id);
|
||||
return repository.save(recipe);
|
||||
});
|
||||
}
|
||||
|
||||
@DeleteMapping("/recipe/{id}")
|
||||
void DeleteRecipe(@PathVariable long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.controller;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import com.wyattjmiller.home.recipefoliobackend.model.Recipe;
|
||||
|
||||
public interface RecipeRepository extends JpaRepository<Recipe, Long> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class RootController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String GetRootPage() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("RecipeFolio Backend, a RESTful API server software\n");
|
||||
sb.append("Designed and developed by Miller Web Solutions, Wyatt J. Miller \nCopyright 2022");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Author {
|
||||
public @GeneratedValue @Id long Id;
|
||||
public String AuthorName;
|
||||
// public int user;
|
||||
public LocalDateTime CreatedTimestamp;
|
||||
|
||||
public Author() {
|
||||
|
||||
}
|
||||
|
||||
public Author(String authorName, LocalDateTime createdTimestamp) {
|
||||
this.AuthorName = authorName;
|
||||
this.CreatedTimestamp = createdTimestamp;
|
||||
}
|
||||
|
||||
public String GetAuthorName() {
|
||||
return this.AuthorName;
|
||||
}
|
||||
|
||||
public String GetCreatedTimestamp() {
|
||||
return this.CreatedTimestamp.toString();
|
||||
}
|
||||
|
||||
public void SetAuthorName(String authorName) {
|
||||
this.AuthorName = authorName;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Recipe {
|
||||
// properties
|
||||
private @Id @GeneratedValue Long Id;
|
||||
private String Name;
|
||||
private String Description;
|
||||
private String Ingredients;
|
||||
private LocalDateTime CreatedTimestamp;
|
||||
|
||||
// constructors
|
||||
public Recipe() {
|
||||
|
||||
}
|
||||
|
||||
public Recipe(String name, String description, String ingredients, LocalDateTime createdTimestamp) {
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.Ingredients = ingredients;
|
||||
this.CreatedTimestamp = createdTimestamp;
|
||||
}
|
||||
|
||||
// mehtods (fields)
|
||||
public Long getId() {
|
||||
return this.Id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.Name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.Description;
|
||||
}
|
||||
|
||||
public String getIngredients() {
|
||||
return this.Ingredients;
|
||||
}
|
||||
|
||||
public String getCreatedTimestamp() {
|
||||
return this.CreatedTimestamp.toString();
|
||||
}
|
||||
|
||||
public void setId(Long Id) {
|
||||
this.Id = Id;
|
||||
}
|
||||
|
||||
public void setName(String Name) {
|
||||
this.Name = Name;
|
||||
}
|
||||
|
||||
public void setDescription(String Description) {
|
||||
this.Description = Description;
|
||||
}
|
||||
|
||||
public void setIngredients(String Ingredients) {
|
||||
this.Ingredients = Ingredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) { return true; }
|
||||
if (!(o instanceof Recipe)) { return false; }
|
||||
Recipe recipe = (Recipe) o;
|
||||
return Objects.equals(this.Id, recipe.Id) && Objects.equals(this.Name, recipe.Name) &&
|
||||
Objects.equals(this.Description, recipe.Description) && Objects.equals(this.Ingredients, recipe.Ingredients) &&
|
||||
Objects.equals(this.CreatedTimestamp, recipe.CreatedTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.Id, this.Name, this.Description, this.Ingredients, this.CreatedTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Recipe{" + "id=" + this.Id + ", name=" + this.Name + ", description=" + this.Description + ", ingredients=" + this.Ingredients + ", created_timestamp=" + this.CreatedTimestamp + "}";
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
private @GeneratedValue @Id long Id;
|
||||
private String FirstName;
|
||||
private String LastName;
|
||||
private String Username;
|
||||
private String EmailAddress;
|
||||
private String Password;
|
||||
private LocalDateTime CreatedTimestamp;
|
||||
|
||||
public User() { }
|
||||
|
||||
public User(String firstName, String lastName, String username, String emailAddress, String password, LocalDateTime createdTimestamp) {
|
||||
this.FirstName = firstName;
|
||||
this.LastName = lastName;
|
||||
this.EmailAddress = emailAddress;
|
||||
this.Password = password;
|
||||
this.Username = username;
|
||||
this.CreatedTimestamp = createdTimestamp;
|
||||
}
|
||||
|
||||
public String GetFirstName() {
|
||||
return this.FirstName;
|
||||
}
|
||||
|
||||
public String GetLastName() {
|
||||
return this.LastName;
|
||||
}
|
||||
|
||||
public String GetUsername() {
|
||||
return this.Username;
|
||||
}
|
||||
|
||||
public String GetEmailAddress() {
|
||||
return this.EmailAddress;
|
||||
}
|
||||
|
||||
public String GetPassword() {
|
||||
return this.Password;
|
||||
}
|
||||
|
||||
public String GetCreatedTimestamp() {
|
||||
return this.CreatedTimestamp.toString();
|
||||
}
|
||||
|
||||
public void SetFirstName(String firstName) {
|
||||
this.FirstName = firstName;
|
||||
}
|
||||
|
||||
public void SetLastName(String lastName) {
|
||||
this.LastName = lastName;
|
||||
}
|
||||
|
||||
public void SetUsername(String username) {
|
||||
this.Username = username;
|
||||
}
|
||||
|
||||
public void SetEmailAddress(String emailAddress) {
|
||||
this.EmailAddress = emailAddress;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend.utils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.wyattjmiller.home.recipefoliobackend.controller.RecipeRepository;
|
||||
import com.wyattjmiller.home.recipefoliobackend.model.Recipe;
|
||||
|
||||
@Configuration
|
||||
class LoadDatabase {
|
||||
private static final Logger log = LoggerFactory.getLogger(LoadDatabase.class);
|
||||
|
||||
@Bean
|
||||
CommandLineRunner initDatabase(RecipeRepository repository) {
|
||||
return args -> {
|
||||
log.info("Preloading " + repository.save(new Recipe("Peanut Butter and Jelly Sandwhich", "The defacto sandwhich", "Peanut Butter, Jelly, and bread", LocalDateTime.now())));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
1
src/main/resources/application.properties
Normal file
1
src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.wyattjmiller.home.recipefoliobackend;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class RecipefoliobackendApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user