Skip to content

Commit

Permalink
Merge pull request #31 from SirNoob97/testcontainers
Browse files Browse the repository at this point in the history
DB init script #29
  • Loading branch information
kgotlelelo-cmd committed Sep 23, 2021
2 parents 355cf18 + 4a55e1b commit 0a1fcc5
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResponseEntity<List<Post>> getClientPosts(@PathVariable Long id) {
return ResponseEntity.ok(service.getClientPosts(id));
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping
public Client register(@RequestBody Client newClient){
return service.saveClient(newClient);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Post {
private Long likes;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", nullable = false)
@JoinColumn(name = "client_id")
@JsonIgnore
private Client client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ClientService {
@Autowired
PostRepository postRepo;

// refactor this logic or use dto
//get all clients in the database
public List<Client> getAllClients(){
return clientRepo.findAll();
Expand Down Expand Up @@ -59,6 +60,7 @@ public Optional<Client> findClientByUsername(String username){
}


// refactor this logic or use dto
//post a status
//need fixing
public Client addPost(Client newClient,Long id){
Expand Down
2 changes: 1 addition & 1 deletion cruise-ms-domain/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
ddl-auto: update
ddl-auto: none
show-sql: true
datasource:
url: jdbc:postgresql://${POSTGRES_HOSTNAME:localhost}:${POSTGRES_PORT:5432}/${POSTGRES_DB:cruise}
Expand Down
167 changes: 167 additions & 0 deletions postgres/docker-entrypoint-initdb.d/cruise.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 12.8
-- Dumped by pg_dump version 12.8

--------------------------------------------------------------------------
-- Uncomment if the POSTGRES_DB is not set before creating the container--
--------------------------------------------------------------------------
--SET statement_timeout = 0;
--SET lock_timeout = 0;
--SET idle_in_transaction_session_timeout = 0;
--SET client_encoding = 'UTF8';
--SET standard_conforming_strings = on;
--SELECT pg_catalog.set_config('search_path', '', false);
--SET check_function_bodies = false;
--SET xmloption = content;
--SET client_min_messages = warning;
--SET row_security = off;
--
----
---- Name: cruise; Type: DATABASE; Schema: -; Owner: -
----
--
--CREATE DATABASE cruise WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8';
--
--
--\connect cruise

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: clients; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.clients (
client_id bigint NOT NULL,
bio character varying(255),
date_of_birth timestamp without time zone,
email character varying(255) NOT NULL,
first_name character varying(65) NOT NULL,
gender integer,
second_name character varying(65) NOT NULL,
username character varying(65) NOT NULL
);


--
-- Name: clients_client_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.clients ALTER COLUMN client_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.clients_client_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);


--
-- Name: posts; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.posts (
post_id bigint NOT NULL,
body character varying(255),
likes bigint DEFAULT 0,
client_id bigint NOT NULL
);


--
-- Name: posts_post_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.posts ALTER COLUMN post_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.posts_post_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);


--
-- Data for Name: clients; Type: TABLE DATA; Schema: public; Owner: -
--

INSERT INTO public.clients OVERRIDING SYSTEM VALUE VALUES (1, 'Have a lovely day', '2021-09-22 19:36:36.026391', 'kmasenam@student.wethinkcode.co.za', 'kgotlelelo', 0, 'masenamela', 'code bender');
INSERT INTO public.clients OVERRIDING SYSTEM VALUE VALUES (2, 'another one', '2021-09-22 19:36:36.043624', 'kgotlelelomasenamela74@gmail.com', 'John', 0, 'Doe', 'Don');


--
-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: -
--

INSERT INTO public.posts OVERRIDING SYSTEM VALUE VALUES (1, 'hello world', 0, 1);
INSERT INTO public.posts OVERRIDING SYSTEM VALUE VALUES (2, 'a post', 0, 2);


--
-- Name: clients_client_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--

SELECT pg_catalog.setval('public.clients_client_id_seq', 1, false);


--
-- Name: posts_post_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--

SELECT pg_catalog.setval('public.posts_post_id_seq', 1, false);


--
-- Name: clients clients_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clients
ADD CONSTRAINT clients_pkey PRIMARY KEY (client_id);


--
-- Name: clients email_unq; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clients
ADD CONSTRAINT email_unq UNIQUE (email);


--
-- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.posts
ADD CONSTRAINT posts_pkey PRIMARY KEY (post_id);


--
-- Name: posts clients_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.posts
ADD CONSTRAINT clients_fkey FOREIGN KEY (client_id) REFERENCES public.clients(client_id);


--
-- PostgreSQL database dump complete
--

0 comments on commit 0a1fcc5

Please sign in to comment.