Skip to content

Commit 8de547f

Browse files
Kawabanasamoshyn
andauthored
ZPI-72 feat: implement user entity
Co-authored-by: asamoshyn <aliaksei.samoshyn@dataart.com>
1 parent 968309f commit 8de547f

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.zpi.watchout.data.entity
2+
3+
import jakarta.persistence.Column
4+
import jakarta.persistence.Entity
5+
import jakarta.persistence.Table
6+
import jakarta.validation.constraints.Email
7+
import jakarta.validation.constraints.Max
8+
import jakarta.validation.constraints.Min
9+
import org.zpi.watchout.data.AbstractEntity
10+
11+
@Entity
12+
@Table(name = "users", schema = "watchout")
13+
class User(
14+
@Column(name = "name")
15+
val name : String,
16+
@Column(name = "last_name")
17+
val lastName : String,
18+
@Email
19+
@Column(name = "email", unique = true)
20+
val email : String,
21+
@Column(name = "phone_number", unique = true)
22+
val phoneNumber : String,
23+
@Min(-100)
24+
@Max(100)
25+
@Column(name="reputation")
26+
val reputation : Double,
27+
) : AbstractEntity()
28+
{
29+
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.zpi.watchout.data.repos
2+
3+
import org.springframework.data.jpa.repository.JpaRepository
4+
import org.springframework.stereotype.Repository
5+
import org.zpi.watchout.data.entity.User
6+
7+
@Repository
8+
interface UserRepository : JpaRepository<User, Long> {
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE IF NOT EXISTS watchout.users (
2+
id BIGSERIAL PRIMARY KEY,
3+
name VARCHAR(255) NOT NULL,
4+
last_name VARCHAR(255) NOT NULL,
5+
email VARCHAR(255) UNIQUE NOT NULL,
6+
phone_number VARCHAR(50) UNIQUE NOT NULL,
7+
reputation DOUBLE PRECISION NOT NULL,
8+
created_at TIMESTAMP NOT NULL DEFAULT now(),
9+
updated_at TIMESTAMP DEFAULT now()
10+
);
11+
12+
INSERT INTO watchout.users (name, last_name, email, phone_number, reputation)
13+
VALUES
14+
('Alice', 'Smith', 'alice.smith@example.com', '+1-555-0001', 0.0),
15+
('Bob', 'Johnson', 'bob.johnson@example.com', '+1-555-0002', -100),
16+
('Charlie', 'Brown', 'charlie.brown@example.com', '+1-555-0003', -50),
17+
('Diana', 'Prince', 'diana.prince@example.com', '+1-555-0004', 50),
18+
('Evan', 'Taylor', 'evan.taylor@example.com', '+1-555-0005', 100);

0 commit comments

Comments
 (0)