Skip to content

Commit

Permalink
add ulid identifier to user profile
Browse files Browse the repository at this point in the history
Took 26 minutes
  • Loading branch information
gribanoveu committed Jan 19, 2024
1 parent cdc4b4a commit 907a6e7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<log-viewer-spring-boot.version>1.0.7</log-viewer-spring-boot.version>
<logback-gelf.version>5.0.1</logback-gelf.version>
<springdoc-openapi-starter-webmvc-ui.version>2.3.0</springdoc-openapi-starter-webmvc-ui.version>
<ulidj.version>1.0.4</ulidj.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -85,6 +86,11 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.azam.ulidj</groupId>
<artifactId>ulidj</artifactId>
<version>${ulidj.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.github.gribanoveu.cuddle.exeptions.CredentialEx;
import com.github.gribanoveu.cuddle.utils.JsonUtils;
import com.github.gribanoveu.cuddle.utils.emails.EmailTemplates;
import io.azam.ulidj.ULID;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,6 +30,7 @@
import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ThreadLocalRandom;

/**
* @author Evgeny Gribanov
Expand All @@ -51,6 +53,7 @@ public ResponseEntity<StatusResponse> registerUser(RegisterDto request) {
if (userService.userExistByEmail(request.email())) throw new CredentialEx(ResponseCode.USER_ALREADY_EXIST);

var user = new User();
user.setUlid(ULID.random(ThreadLocalRandom.current()));
user.setEmail(request.email());
user.setBirthDate(LocalDate.parse(request.birthDate(), DateTimeFormatter.ISO_LOCAL_DATE)); // yyyy-MM-dd
user.setPassword(passwordEncoder.encode(request.password()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class User {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "ulid", unique = true)
private String ulid;

@Version
private Long version;

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/migration/V1_2__add_ulid_to_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE users ADD ulid VARCHAR(32) NOT NULL;
14 changes: 7 additions & 7 deletions src/main/resources/db/migration/V2_0__add_users_data.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
INSERT INTO users
(version, email, password, birth_date, registration_date, ban_expiration, restriction_reason, role,
(ulid, version, email, password, birth_date, registration_date, ban_expiration, restriction_reason, role,
account_non_expired, account_non_locked, credentials_non_expired, enabled)

VALUES
(0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
'2001-01-01', '2023-01-01 00:00:00.000000', null, null,
'ADMIN', true, true, true, true),
('01HMH22HRX6G0T2E2S18FSXT0C', 0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
'2001-01-01', '2023-01-01 00:00:00.000000', null, null,
'ADMIN', true, true, true, true),

(0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
('01HMH246DQH0X9P4G4D1QQC5DW', 0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
'2001-01-01', '2023-01-01 00:00:00.000000', null, null,
'MODERATOR', true, true, true, true),

(0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
'2001-01-01', '2023-01-01 00:00:00.000000', null, null,
('01HMH24PM7S8E6XCN50PMWQBDQ', 0, '[email protected]', '$2a$12$FyLK5s44fub5XpaTRVtiHuPqUJXQplJD261p2jd7AmlDzrSsINH8i',
'2001-01-01', '2023-01-01 00:00:00.000000', null, null,
'USER', true, true, true, true);

0 comments on commit 907a6e7

Please sign in to comment.