Commit e69b5996 authored by Khalid Ali's avatar Khalid Ali

Rename entity and finalize Flyway DB setup script.

parent 1ada726d
......@@ -24,7 +24,7 @@ apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.satrung.developer'
group = 'com.gmu.bookshare'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
......
package com.gmu.bookshare.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -8,24 +9,18 @@ import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "bid", schema = "bookshare_schema")
public class Bid {
public Bid(Date time, double price, int flagged, Long userId) {
this.time = time;
this.price = price;
this.flagged = flagged;
this.userId = userId;
}
@Id
@GeneratedValue
@Column(name = "id", updatable = false)
private Long id;
@Column(name = "time")
private Date time;
@Column(name = "createDate")
private Date createDate;
@Column(name = "price")
private double price;
......@@ -35,4 +30,7 @@ public class Bid {
@Column(name = "userId")
private Long userId;
@Column(name = "listingId")
private Long listingId;
}
package com.gmu.bookshare.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -8,25 +9,11 @@ import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "listing", schema = "bookshare_schema")
public class Listing {
public Listing(String course, int isbn, int condition, boolean accessCode, double price, byte[] image,
String description, Date time, Long[] bid_id, Long owner, String title) {
this.course = course;
this.isbn = isbn;
this.condition = condition;
this.accessCode = accessCode;
this.price = price;
this.image = image;
this.description = description;
this.time = time;
this.bid_id = bid_id;
this.owner = owner;
this.title = title;
}
@Id
@GeneratedValue
@Column(name = "id", updatable = false)
......@@ -53,8 +40,8 @@ public class Listing {
@Column(name = "description")
private String description;
@Column(name = "time")
private Date time;
@Column(name = "createDate")
private Date createDate;
@Column(name = "bid_id")
private Long[] bid_id;
......
package com.gmu.bookshare.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -7,23 +8,19 @@ import javax.persistence.*;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "user", schema = "bookshare_schema")
public class User {
public User(Long[] ownerListings, Long[] biddingListings) {
this.ownerListings = ownerListings;
this.biddingListings = biddingListings;
}
@Table(name = "user")
public class ShareUser {
@Id
@GeneratedValue
@Column(name = "id", updatable = false)
private Long id;
@Column(name = "ownerListings")
private Long[] ownerListings;
@Column(name = "email")
private String email;
@Column(name = "biddingListings")
private Long[] biddingListings;
@Column(name = "name")
private String name;
}
package com.gmu.bookshare.persistence;
import com.gmu.bookshare.entity.User;
import com.gmu.bookshare.entity.ShareUser;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Long> {
public interface ShareUserRepository extends CrudRepository<ShareUser, Long> {
}
package com.gmu.bookshare.service;
import com.gmu.bookshare.persistence.UserRepository;
import com.gmu.bookshare.persistence.ShareUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
public class ShareUserService {
private final UserRepository userRepository;
private final ShareUserRepository shareUserRepository;
@Autowired
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
public ShareUserService(ShareUserRepository shareUserRepository) {
this.shareUserRepository = shareUserRepository;
}
}
......@@ -2,7 +2,7 @@ package com.gmu.bookshare.web;
import com.gmu.bookshare.service.BidService;
import com.gmu.bookshare.service.ListingService;
import com.gmu.bookshare.service.UserService;
import com.gmu.bookshare.service.ShareUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -11,12 +11,12 @@ public class BookshareApiController {
private final ListingService listingService;
private final BidService bidService;
private final UserService userService;
private final ShareUserService shareUserService;
@Autowired
public BookshareApiController(ListingService listingService, BidService bidService, UserService userService) {
public BookshareApiController(ListingService listingService, BidService bidService, ShareUserService shareUserService) {
this.listingService = listingService;
this.bidService = bidService;
this.userService = userService;
this.shareUserService = shareUserService;
}
}
create table BEER (
/*
CockroachDB Data Transfer
*/
DROP TABLE IF EXISTS ShareUser;
create table ShareUser (
id SERIAL PRIMARY KEY,
email varchar(255),
name varchar(255)
);
DROP TABLE IF EXISTS Bid;
CREATE TABLE Bid (
id SERIAL PRIMARY KEY,
NAME varchar(100) not null
createDate DATE,
price DECIMAL(5,2),
flagged INTEGER,
userId bigint REFERENCES ShareUser(id)
);
CREATE SEQUENCE hibernate_sequence INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;
DROP TABLE IF EXISTS Listing;
CREATE TABLE Listing (
id SERIAL PRIMARY KEY,
course varchar(100),
isbn INTEGER,
condition INTEGER,
accessCode INTEGER,
price DECIMAL(5,2),
image bytea,
description varchar(1000),
createDate DATE,
bid_id bigint REFERENCES Bid(id),
userId bigint REFERENCES ShareUser(id),
title varchar(255)
);
insert into BEER (NAME) values ('Kentucky Brunch Brand Stout');
insert into BEER (NAME) values ('Marshmallow Handjee');
insert into BEER (NAME) values ('Barrel-Aged Abraxas');
insert into BEER (NAME) values ('Hunahpus Imperial Stout');
insert into BEER (NAME) values ('King Julius');
insert into BEER (NAME) values ('Heady Topper');
insert into BEER (NAME) values ('Budweiser');
insert into BEER (NAME) values ('Coors Light');
insert into BEER (NAME) values ('PBR');
CREATE INDEX ON Bid (id);
ALTER TABLE Bid ADD CONSTRAINT listingId FOREIGN KEY (id) REFERENCES Listing
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment