Fix backend user contract and add User-Employee-Customer linkage
- Add active field to User entity and users table - Add userId linkage to Employee and Customer entities with unique constraints and FKs - Add repository methods findByUserId and findAllByEmail - Create UserBusinessLinkageService for shared employee/customer creation logic - Create AuthenticationHelper utility for resolving authenticated users - Update UserService to persist all user fields and create linked business entities - Update AuthController register to set active and create linked customer - Update DataInitializer to be idempotent and use shared linkage service - Update Postman collection user endpoints with fullName, email, and active
This commit is contained in:
@@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS storeLocation (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS employee (
|
||||
employeeId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NULL,
|
||||
firstName VARCHAR(50) NOT NULL,
|
||||
lastName VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(100) NOT NULL,
|
||||
@@ -19,7 +20,8 @@ CREATE TABLE IF NOT EXISTS employee (
|
||||
role VARCHAR(50) NOT NULL,
|
||||
isActive BOOLEAN DEFAULT TRUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uk_employee_user_id UNIQUE (user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS employeeStore (
|
||||
@@ -32,12 +34,14 @@ CREATE TABLE IF NOT EXISTS employeeStore (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS customer (
|
||||
customerId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NULL,
|
||||
firstName VARCHAR(50) NOT NULL,
|
||||
lastName VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(100) NOT NULL,
|
||||
phone VARCHAR(20) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uk_customer_user_id UNIQUE (user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS pet (
|
||||
@@ -201,6 +205,7 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
fullName VARCHAR(100),
|
||||
avatarUrl VARCHAR(255),
|
||||
role VARCHAR(20) NOT NULL,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
@@ -239,3 +244,7 @@ CREATE TABLE IF NOT EXISTS message (
|
||||
FOREIGN KEY (conversationId) REFERENCES conversation(id),
|
||||
FOREIGN KEY (senderId) REFERENCES users(id)
|
||||
);
|
||||
|
||||
-- Add foreign keys for user_id linkage
|
||||
ALTER TABLE employee ADD CONSTRAINT fk_employee_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
|
||||
ALTER TABLE customer ADD CONSTRAINT fk_customer_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
|
||||
|
||||
Reference in New Issue
Block a user