Refactor ContactRequest to separate date and time fields, add Flyway for database migrations, and initialize schema.

This commit is contained in:
2025-06-29 21:11:29 +09:00
parent a9d8a8cf43
commit e6ca52e72d
5 changed files with 66 additions and 13 deletions

View File

@@ -92,6 +92,10 @@
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency> <dependency>
<groupId>dev.rheinsw</groupId> <groupId>dev.rheinsw</groupId>

View File

@@ -11,7 +11,8 @@ import jakarta.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDateTime; import java.time.LocalDate;
import java.time.LocalTime;
/** /**
* @author Thatsaphorn Atchariyaphap * @author Thatsaphorn Atchariyaphap
@@ -51,7 +52,11 @@ public class ContactRequest {
@Column(name = "captcha_token", length = 1024) @Column(name = "captcha_token", length = 1024)
private String captchaToken; private String captchaToken;
private LocalDateTime submittedAt; @Column(name = "submitted_date")
private LocalDate submittedDate;
@Column(name = "submitted_time")
private LocalTime submittedTime;
public ContactRequest setName(String name) { public ContactRequest setName(String name) {
this.name = name; this.name = name;
@@ -88,8 +93,13 @@ public class ContactRequest {
return this; return this;
} }
public ContactRequest setSubmittedAt(LocalDateTime submittedAt) { public ContactRequest setSubmittedDate(LocalDate submittedDate) {
this.submittedAt = submittedAt; this.submittedDate = submittedDate;
return this;
}
public ContactRequest setSubmittedTime(LocalTime submittedTime) {
this.submittedTime = submittedTime;
return this; return this;
} }
} }

View File

@@ -15,7 +15,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.time.LocalDateTime; import java.time.LocalDate;
import java.time.LocalTime;
/** /**
* @author Thatsaphorn Atchariyaphap * @author Thatsaphorn Atchariyaphap
@@ -65,7 +66,8 @@ public class SubmitContactUseCaseImpl implements SubmitContactUseCase {
.setPhone(request.phone()) .setPhone(request.phone())
.setWebsite(request.website()) .setWebsite(request.website())
.setCaptchaToken(request.captcha()) .setCaptchaToken(request.captcha())
.setSubmittedAt(LocalDateTime.now()); .setSubmittedDate(LocalDate.now())
.setSubmittedTime(LocalTime.now());
contactRepository.save(message); contactRepository.save(message);

View File

@@ -9,13 +9,19 @@ spring:
username: ${DB_USERNAME} username: ${DB_USERNAME}
password: ${DB_PASSWORD} password: ${DB_PASSWORD}
flyway:
enabled: true
baseline-on-migrate: true
locations: classpath:db/migration
jpa: jpa:
hibernate: hibernate:
ddl-auto: none ddl-auto: none # ensure entities match the DB, but don't modify schema
show-sql: true show-sql: true
properties: properties:
hibernate: hibernate:
format_sql: true dialect: org.hibernate.dialect.PostgreSQLDialect
defer-datasource-initialization: true
mail: mail:
host: smtp.resend.com host: smtp.resend.com

View File

@@ -0,0 +1,31 @@
create table api_key
(
id bigint generated by default as identity
constraint pk_api_key
primary key,
key varchar(255) not null
constraint uc_api_key_key
unique,
type varchar(255) not null,
enabled boolean not null,
frontend_only boolean not null,
description text,
created_date date default CURRENT_DATE,
created_time time default CURRENT_TIME,
modified_date date,
modified_time time
);
CREATE TABLE contact_requests
(
id BIGSERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
message VARCHAR(1000),
company VARCHAR(100),
phone VARCHAR(20),
website VARCHAR(100),
captcha_token VARCHAR(1024),
submitted_date DATE,
submitted_time TIME
);