modified config, database seed connects to PG, imported sql scripts from previous version
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Recipin API
|
||||||
|
|
||||||
|
This is my reworked REST API for my built-from-scratch recipe-sharing platform.
|
||||||
|
|
||||||
|
I am rebuilding this API using Spring Boot connected to a PostgreSQL database.
|
||||||
20
pom.xml
20
pom.xml
@@ -17,28 +17,30 @@
|
|||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.javax.persistence</groupId>
|
||||||
|
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||||
|
<version>1.0.0.Final</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javax.persistence</groupId>
|
|
||||||
<artifactId>persistence-api</artifactId>
|
|
||||||
<version>1.0.2</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/.DS_Store
vendored
Normal file
BIN
src/main/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/java/.DS_Store
vendored
Normal file
BIN
src/main/java/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/java/com/.DS_Store
vendored
Normal file
BIN
src/main/java/com/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/java/com/innocuoussymmetry/.DS_Store
vendored
Normal file
BIN
src/main/java/com/innocuoussymmetry/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/java/com/innocuoussymmetry/recipin/.DS_Store
vendored
Normal file
BIN
src/main/java/com/innocuoussymmetry/recipin/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,9 +1,17 @@
|
|||||||
package com.innocuoussymmetry.recipin;
|
package com.innocuoussymmetry.recipin;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@ComponentScan(basePackages = {"com.innocuoussymmetry.recipin"})
|
||||||
|
@EntityScan(basePackages = {"com.innocuoussymmetry.recipin"})
|
||||||
public class RecipinApplication {
|
public class RecipinApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.innocuoussymmetry.recipin.controllers;
|
||||||
|
|
||||||
|
import com.innocuoussymmetry.recipin.models.User;
|
||||||
|
import com.innocuoussymmetry.recipin.repositories.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UserController(UserRepository userRepository) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Iterable<User> getAllUsers() {
|
||||||
|
return userRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public User getUserById(Integer id) {
|
||||||
|
Optional<User> maybe = userRepository.findById(id);
|
||||||
|
if (maybe.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return maybe.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
abstract class AppList extends DBEntity {
|
abstract class AppList {
|
||||||
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
private Integer ownerId;
|
private Integer ownerId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
abstract class DBEntity {
|
|
||||||
@Id
|
|
||||||
@Column(name="id")
|
|
||||||
@GeneratedValue
|
|
||||||
private Integer id;
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Table(name="friendships")
|
@Table(name="friendships")
|
||||||
public class Friendship extends DBEntity {
|
public class Friendship {
|
||||||
|
@Id
|
||||||
|
@Column(name="name")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="senderid")
|
@Column(name="senderid")
|
||||||
private Integer senderId;
|
private Integer senderId;
|
||||||
@Column(name="targetid")
|
@Column(name="targetid")
|
||||||
|
|||||||
@@ -1,28 +1,18 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Table(name="grocerylist")
|
@Table(name="grocerylist")
|
||||||
class GroceryList extends AppList {
|
class GroceryList extends AppList {
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="name")
|
@Column(name="name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name="ownerid")
|
@Column(name="ownerid")
|
||||||
private Integer ownerId;
|
private Integer ownerId;
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getOwnerId() {
|
|
||||||
return ownerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwnerId(Integer ownerId) {
|
|
||||||
this.ownerId = ownerId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Table(name="ingredient")
|
@Table(name="ingredient")
|
||||||
public class Ingredient extends DBEntity {
|
public class Ingredient {
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="name")
|
@Column(name="name")
|
||||||
private String name;
|
private String name;
|
||||||
@Column(name="description")
|
@Column(name="description")
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@Table(name="recipe")
|
@Table(name="recipe")
|
||||||
public class Recipe extends DBEntity {
|
public class Recipe {
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="name")
|
@Column(name="name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name="preptime")
|
@Column(name="preptime")
|
||||||
private String prepTime;
|
private String prepTime;
|
||||||
|
|
||||||
@Column(name="authoruserid")
|
@Column(name="authoruserid")
|
||||||
private Integer authorUserId;
|
private Integer authorUserId;
|
||||||
|
|
||||||
@Column(name="description")
|
@Column(name="description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Column(name="ingredientnames")
|
@Column(name="ingredientnames")
|
||||||
private List<String> ingredientNames;
|
private List<String> ingredientNames;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Table(name="recipelist")
|
@Table(name="recipelist")
|
||||||
public class RecipeList extends AppList {
|
public class RecipeList extends AppList {
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="ismainlist")
|
@Column(name="ismainlist")
|
||||||
private boolean isMainRecipeList;
|
private boolean isMainRecipeList;
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,30 @@
|
|||||||
package com.innocuoussymmetry.recipin.models;
|
package com.innocuoussymmetry.recipin.models;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Table(name="users")
|
@Table(name="users")
|
||||||
public class User extends DBEntity {
|
public class User {
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
@Column(name="firstname")
|
@Column(name="firstname")
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name="lastname")
|
@Column(name="lastname")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
@Column(name="handle")
|
@Column(name="handle")
|
||||||
private String handle;
|
private String handle;
|
||||||
|
|
||||||
@Column(name="email")
|
@Column(name="email")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Column(name="isadmin")
|
@Column(name="isadmin")
|
||||||
private boolean isAdmin;
|
private boolean isAdmin;
|
||||||
|
|
||||||
@Column(name="password")
|
@Column(name="password")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|||||||
BIN
src/main/java/com/innocuoussymmetry/recipin/repositories/.DS_Store
vendored
Normal file
BIN
src/main/java/com/innocuoussymmetry/recipin/repositories/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -0,0 +1,103 @@
|
|||||||
|
package com.innocuoussymmetry.recipin.repositories;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:/resources/app.properties")
|
||||||
|
public class DBSeed {
|
||||||
|
private String constring;
|
||||||
|
private Connection conn;
|
||||||
|
|
||||||
|
public DBSeed(String constring) {
|
||||||
|
this.constring = constring;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void connect() {
|
||||||
|
try {
|
||||||
|
this.conn = DriverManager.getConnection(constring);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disconnect() {
|
||||||
|
try {
|
||||||
|
if (this.conn.isClosed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void seed() {
|
||||||
|
this.connect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement statement = conn.createStatement();
|
||||||
|
|
||||||
|
String[] orderedPaths = {
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createappusers.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createingredient.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcollection.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/creategrocerylist.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcuisine.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcourse.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createrecipe.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createrecipecomments.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcmp_recipeingredient.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcmp_recipecollection.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcmp_usersubscriptions.sql",
|
||||||
|
"src/main/java/com/innocuoussymmetry/recipin/repositories/sql/create/createcmp_userfriendships.sql",
|
||||||
|
};
|
||||||
|
File[] pathObjects = new File[orderedPaths.length];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (String path : orderedPaths) {
|
||||||
|
pathObjects[i] = new File(path);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < orderedPaths.length) {
|
||||||
|
String statementBody = "";
|
||||||
|
|
||||||
|
FileReader fr = new FileReader(pathObjects[i]);
|
||||||
|
BufferedReader br = new BufferedReader(fr);
|
||||||
|
var lines = br.lines().toArray();
|
||||||
|
|
||||||
|
for (var line : lines) {
|
||||||
|
statementBody += line + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.execute(statementBody);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new DBSeed("jdbc:postgresql://localhost:5432/recipinV2?username=postgres&password=postgres").seed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.innocuoussymmetry.recipin.repositories;
|
||||||
|
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.sql.*;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class DataSourceConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSource getDataSource() {
|
||||||
|
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
|
||||||
|
dataSourceBuilder.driverClassName("org.postgresql.Driver");
|
||||||
|
dataSourceBuilder.url("jdbc:postgresql://localhost:5432/recipinV2?username=postgres&password=postgres");
|
||||||
|
dataSourceBuilder.username("postgres");
|
||||||
|
dataSourceBuilder.password("postgres");
|
||||||
|
return dataSourceBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.innocuoussymmetry.recipin.repositories;
|
||||||
|
|
||||||
|
import com.innocuoussymmetry.recipin.models.*;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||||
|
}
|
||||||
BIN
src/main/java/com/innocuoussymmetry/recipin/repositories/sql/.DS_Store
vendored
Normal file
BIN
src/main/java/com/innocuoussymmetry/recipin/repositories/sql/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS appusers (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
firstname varchar NOT NULL,
|
||||||
|
lastname varchar NOT NULL,
|
||||||
|
handle varchar NOT NULL UNIQUE,
|
||||||
|
email varchar NOT NULL UNIQUE,
|
||||||
|
password varchar NOT NULL,
|
||||||
|
active boolean NOT NULL,
|
||||||
|
isadmin boolean NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS cmp_recipecollection (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
recipeid int REFERENCES recipe (id),
|
||||||
|
collectionid int REFERENCES collection (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS cmp_recipeingredient (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
quantity decimal NOT NULL,
|
||||||
|
unit varchar NOT NULL,
|
||||||
|
ingredientid int REFERENCES ingredient (id),
|
||||||
|
recipeid int REFERENCES recipe (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS cmp_userfriendships (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
active boolean NOT NULL,
|
||||||
|
pending boolean NOT NULL,
|
||||||
|
dateterminated varchar,
|
||||||
|
senderid int REFERENCES appusers (id),
|
||||||
|
targetid int REFERENCES appusers (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS cmp_usersubscriptions (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
collectionid int REFERENCES collection (id),
|
||||||
|
usermemberid int REFERENCES appusers (id),
|
||||||
|
active boolean NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS collection (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
active boolean NOT NULL,
|
||||||
|
ismaincollection boolean NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL,
|
||||||
|
ownerid int REFERENCES appusers (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS course (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL,
|
||||||
|
active boolean NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS cuisine (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL,
|
||||||
|
active boolean NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS grocerylist (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
active boolean NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL,
|
||||||
|
ownerid int REFERENCES appusers (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ingredient (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
description varchar,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
createdbyid int REFERENCES appusers (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS recipe (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
preptime varchar NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
datemodified varchar NOT NULL,
|
||||||
|
description varchar,
|
||||||
|
authoruserid int REFERENCES appusers (id),
|
||||||
|
cuisineid int REFERENCES cuisine (id),
|
||||||
|
courseid int REFERENCES course (id)
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS recipecomments (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
commentbody varchar NOT NULL,
|
||||||
|
datecreated varchar NOT NULL,
|
||||||
|
recipeid int REFERENCES recipe (id) NOT NULL,
|
||||||
|
authorid int REFERENCES appusers (id) NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- SELECT * FROM cmp_usersubscriptions
|
||||||
|
-- WHERE usermemberid = $1
|
||||||
|
-- AND collectionid = $2;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
SELECT
|
||||||
|
recipin.cmp_userfriendships.id,
|
||||||
|
recipin.cmp_userfriendships.datecreated,
|
||||||
|
recipin.appusers.id,
|
||||||
|
recipin.appusers.firstname,
|
||||||
|
recipin.appusers.lastname,
|
||||||
|
recipin.appusers.handle,
|
||||||
|
recipin.appusers.email
|
||||||
|
FROM recipin.cmp_userfriendships
|
||||||
|
INNER JOIN recipin.appusers
|
||||||
|
ON recipin.appusers.id = recipin.cmp_userfriendships.targetid
|
||||||
|
WHERE senderid = $1 OR targetid = $1
|
||||||
|
AND cmp_userfriendships.active = true;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
-- TO DO
|
||||||
|
-- run a query that selects:
|
||||||
|
-- 1) all recipes from a user's own collection
|
||||||
|
-- 2) all recipes from user's subscribed collections
|
||||||
|
-- 3) all matching a given user id
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
SELECT * FROM recipin.recipe
|
||||||
|
WHERE authoruserid = $1
|
||||||
|
OR authoruserid IN (
|
||||||
|
SELECT targetid FROM recipin.cmp_userfriendships
|
||||||
|
WHERE senderid = $1
|
||||||
|
UNION
|
||||||
|
SELECT senderid FROM recipin.cmp_userfriendships
|
||||||
|
WHERE targetid =$ 1
|
||||||
|
);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
SELECT * FROM recipin.recipe
|
||||||
|
WHERE authorid = $1;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
SELECT
|
||||||
|
recipin.cmp_userfriendships.id,
|
||||||
|
recipin.cmp_userfriendships.datecreated,
|
||||||
|
recipin.appusers.id,
|
||||||
|
recipin.appusers.firstname,
|
||||||
|
recipin.appusers.lastname,
|
||||||
|
recipin.appusers.handle,
|
||||||
|
recipin.appusers.email
|
||||||
|
FROM recipin.cmp_userfriendships
|
||||||
|
INNER JOIN recipin.appusers
|
||||||
|
ON recipin.appusers.id = recipin.cmp_userfriendships.senderid
|
||||||
|
WHERE recipin.cmp_userfriendships.id = $1
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
recipin.cmp_userfriendships.id,
|
||||||
|
recipin.cmp_userfriendships.datecreated,
|
||||||
|
recipin.appusers.id,
|
||||||
|
recipin.appusers.firstname,
|
||||||
|
recipin.appusers.lastname,
|
||||||
|
recipin.appusers.handle,
|
||||||
|
recipin.appusers.email
|
||||||
|
FROM recipin.cmp_userfriendships
|
||||||
|
INNER JOIN recipin.appusers
|
||||||
|
ON recipin.appusers.id = recipin.cmp_userfriendships.targetid
|
||||||
|
WHERE recipin.cmp_userfriendships.id = $1;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
SELECT
|
||||||
|
recipin.cmp_usersubscriptions.collectionid as collectionid,
|
||||||
|
recipin.collection.ownerid as ownerid,
|
||||||
|
recipin.cmp_usersubscriptions.usermemberid as memberid,
|
||||||
|
recipin.collection.name as collectionname,
|
||||||
|
recipin.appusers.firstname as owner_first,
|
||||||
|
recipin.appusers.lastname as owner_last
|
||||||
|
FROM recipin.collection
|
||||||
|
INNER JOIN recipin.appusers
|
||||||
|
ON recipin.collection.ownerid = recipin.appusers.id
|
||||||
|
INNER JOIN recipin.cmp_usersubscriptions
|
||||||
|
ON recipin.collection.id = recipin.cmp_usersubscriptions.collectionid
|
||||||
|
WHERE recipin.cmp_usersubscriptions.usermemberid = $1;
|
||||||
@@ -1 +1,2 @@
|
|||||||
|
spring.datasource.url="jdbc:postgresql://localhost:5432/recipinV2?username=postgres&password=postgres"
|
||||||
|
spring.datasource.driver-class-name="org.postgresql"
|
||||||
|
|||||||
Reference in New Issue
Block a user