Skip to content

Commit

Permalink
DB - Step 1 - EXPAND - DB schema and access queries become forwards a…
Browse files Browse the repository at this point in the history
…nd backwards compatible.
  • Loading branch information
chrissimon-au committed May 22, 2023
1 parent 41f1760 commit 63e1f5a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package au.chrissimon.safecontractchangesdemo;

import jakarta.persistence.Embeddable;

@Embeddable
public class FullName {
private String firstName;
public String getFirstName() {
return firstName;
}
private String lastName;
public String getLastName() {
return lastName;
}
public FullName() {
super();
}

public static FullName fromDto(FullNameDto fullNameDto) {
return new FullName(fullNameDto.getFirstName(), fullNameDto.getLastName());
}

public FullNameDto asDto() {
return new FullNameDto(firstName, lastName);
}

public FullName(String firstName, String lastName) {
super();
this.firstName = firstName;
this.lastName = lastName;
}

public FullNameDto toResponse() {
return new FullNameDto(getFirstName(), getLastName());
}

public String toString() {
return (getFirstName() + " " + getLastName()).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
public class Name {
private @Id UUID id;
private String name;
private FullName fullName;

public FullName getFullName() {
return fullName;
}

public UUID getId() {
return id;
Expand All @@ -25,12 +30,16 @@ public Name() {
public Name(FullNameDto fullName) {
super();
this.id = UUID.randomUUID();
this.name = (fullName.getFirstName() + " " + fullName.getLastName()).trim();
this.fullName = FullName.fromDto(fullName);
this.name = this.fullName.toString();
}

public NameResponse toResponse() {
String[] names = name.split("\\s", 2);
String lastName = names.length > 1 ? names[1] : "";
return new NameResponse(id, new FullNameDto(names[0], lastName));
if (fullName == null || fullName.getFirstName() == null || fullName.getLastName() == null) {
String[] names = name.split("\\s", 2);
String lastName = names.length > 1 ? names[1] : "";
return new NameResponse(id, new FullNameDto(names[0], lastName));
}
return new NameResponse(id, fullName.asDto());
}
}
20 changes: 20 additions & 0 deletions server/src/main/resources/db/changelog/02_add_fullname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
databaseChangeLog:
- changeSet:
id: 2
author: Chris Simon
changes:
- addColumn:
tableName: name
columns:
- column:
name: first_name
type: varchar(255)
constraints:
nullable: true
unique: false
- column:
name: last_name
type: varchar(255)
constraints:
nullable: true
unique: false
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
databaseChangeLog:
- include:
file: db/changelog/01_initial_schema.yml
file: db/changelog/01_initial_schema.yml
- include:
file: db/changelog/02_add_fullname.yml

0 comments on commit 63e1f5a

Please sign in to comment.