Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: ubuntu-latest
env:
SPRING_BASE_COMMONS_VERSION: 1.1.0
SPRING_BASE_COMMONS_VERSION: 2.0.0
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APP_NAME=app.jar
ENV DEPS_FILE=deps.info

# Change this when there is an update
ENV SPRING_BASE_COMMONS_VERSION=1.1.0
ENV SPRING_BASE_COMMONS_VERSION=2.0.0

# Clone the spring-base-commons repository
RUN git clone --depth 1 --branch ${SPRING_BASE_COMMONS_VERSION} https://github.com/vulinh64/spring-base-commons.git
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

The project uses the external dependency [spring-base-commons](https://github.com/vulinh64/spring-base-commons).

* For Windows, run [this script](/create-data-classes.cmd)
* For Windows, run [this script](./create-data-classes.cmd)

* For Linux, run [this script](/create-data-classes.sh)
* For Linux, run [this script](./create-data-classes.sh)

* Run `chmod +x ./create-data-classes.sh` if you don't have permission to execute the shell file.

Expand All @@ -59,38 +59,40 @@ Check if your `pom.xml` contains these lines in the `<dependencies>` section:

This project uses `spring-base-commons` as an external dependency (see above). If you want to change the version, check the following locations:

* [`pom.xml` file](pom.xml) - find the property `spring-base-commons.version`.
* [`pom.xml` file](./pom.xml) - find the property `spring-base-commons.version`.

* Environment variable `SPRING_BASE_COMMONS_VERSION` in:

* [Dockerfile](/Dockerfile)
* [Dockerfile](./Dockerfile)

* [create-data-classes.cmd](/create-data-classes.cmd) (Windows)
* [create-data-classes.cmd](./create-data-classes.cmd) (Windows)

* [create-data-classes.sh](/create-data-classes.sh) (Linux)
* [create-data-classes.sh](./create-data-classes.sh) (Linux)

* [GitHub Actions workflows](/.github/workflows/unit-test.yml) (the variable is `${{ env.SPRING_BASE_COMMONS_VERSION }}`)
* [GitHub Actions workflows](./.github/workflows/unit-test.yml) (the variable is `${{ env.SPRING_BASE_COMMONS_VERSION }}`)

### Specifying Environment Variables

The `SPRING_PROFILES_ACTIVE` variable is optional, but you can set it to `development` for local development.

You can either specify these environment variables in a `.env` file or set them directly in Run Configurations.

An example `.env` file can be copied from [this file](/.env-example).
An example `.env` file can be copied from [this file](./.env-example).

### Running the Required Containers

You can run [this script (Windows only)](/initialize-postgres-keycloak-rabbitmq.cmd) or [this script (Linux only)](/initialize-postgres-keycloak-rabbitmq.sh), and it will start the required containers for local development: PostgreSQL and Keycloak.
You can run [this script (Windows only)](./initialize-postgres-keycloak-rabbitmq.cmd) or [this script (Linux only)](./initialize-postgres-keycloak-rabbitmq.sh), and it will start the required containers for local development: PostgreSQL and Keycloak.

> Both scripts have already handled the external dependency for you. See the [Required External Dependency](#required-external-dependency) section for more information.

## Running the Compose Stack

You can run [this script (Windows only)](/run-docker-compose-stack.cmd), and it will build the service image and start the containers for you.
You can run [this script (Windows only)](./run-docker-compose-stack.cmd), or [this script (Linux only)](./run-docker-compose-stack.sh) and it will build the service image and start the containers for you.

> Again, both scripts have already handled the external dependency for you.

If you want to make use of host OS to build the images (to speed up the build process), run [this script (Windows only)](./run-docker-compose-stack-jar.cmd) or [this script (Linux only)](./run-docker-compose-stack-jar.sh) instead.

# Additional Notes

## Virtual Threads
Expand Down
2 changes: 1 addition & 1 deletion create-data-classes.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

SET SPRING_BASE_COMMONS_VERSION=1.1.0
SET SPRING_BASE_COMMONS_VERSION=2.0.0

IF EXIST .\build\spring-base-commons rmdir /s /q .\build\spring-base-commons

Expand Down
2 changes: 1 addition & 1 deletion create-data-classes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

SPRING_BASE_COMMONS_VERSION=1.1.0
SPRING_BASE_COMMONS_VERSION=2.0.0

if [ -d "./build/spring-base-commons" ]; then
rm -rf ./build/spring-base-commons
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-admin-client -->
<keycloak-admin-client.version>26.0.7</keycloak-admin-client.version>

<spring-base-commons.version>1.1.0</spring-base-commons.version>
<spring-base-commons.version>2.0.0</spring-base-commons.version>
</properties>

<dependencies>
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/vulinh/data/base/BaseRepository.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/com/vulinh/data/base/DateTimeAuditable.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/vulinh/data/base/EntityDTOMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.vulinh.data.base;

public interface EntityDTOMapper<E extends AbstractIdentifiable<?>, D> {
public interface EntityDTOMapper<E extends AbstractEntity<?>, D> {

D toDto(E entity);
}
13 changes: 0 additions & 13 deletions src/main/java/com/vulinh/data/base/Identifiable.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/com/vulinh/data/base/RecordDateTimeAuditable.java

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/java/com/vulinh/data/base/RecordIdentifiable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.vulinh.data.base;

import module java.base;

@FunctionalInterface
public interface RecordIdentifiable<I> extends Identifiable<I> {
public interface RecordIdentifiable<I extends Serializable> extends Identifiable<I> {

@Override
default I getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.vulinh.data.base;

import module java.base;

public interface RecordInstantDateTimeAuditable extends InstantDateTimeAuditable {

Instant createdDateTime();

Instant updatedDateTime();

@Override
default Instant getCreatedDateTime() {
return createdDateTime();
}

@Override
default Instant getUpdatedDateTime() {
return updatedDateTime();
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/vulinh/data/base/UuidIdentifiable.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/java/com/vulinh/data/base/UuidJpaEntity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.vulinh.data.dto.projection;

import com.vulinh.data.base.UuidIdentifiable;
import module java.base;

public interface CategoryProjection extends UuidIdentifiable {
import com.vulinh.data.base.Identifiable;

public interface CategoryProjection extends Identifiable<UUID> {

String getDisplayName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record PostRevisionProjection(
UUID authorId,
UUID categoryId,
String tags,
Instant revisionCreatedDate,
Instant revisionCreatedDateTime,
UUID revisionCreatedBy)
implements UUIDRevisionId, Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import module java.base;

import com.vulinh.data.base.DateTimeAuditable;
import com.vulinh.data.base.UuidIdentifiable;
import com.vulinh.data.base.Identifiable;
import com.vulinh.data.base.InstantDateTimeAuditable;

public interface PrefetchPostProjection extends UuidIdentifiable, DateTimeAuditable {
public interface PrefetchPostProjection extends InstantDateTimeAuditable, Identifiable<UUID> {

String getTitle();

Expand All @@ -18,8 +18,8 @@ public interface PrefetchPostProjection extends UuidIdentifiable, DateTimeAudita
CategoryProjection getCategory();

@Override
Instant getCreatedDate();
Instant getCreatedDateTime();

@Override
Instant getUpdatedDate();
Instant getUpdatedDateTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.vulinh.data.base.RecordDateTimeAuditable;
import com.vulinh.data.base.RecordInstantDateTimeAuditable;
import com.vulinh.data.base.RecordUuidIdentifiable;
import com.vulinh.data.dto.response.data.TagData;
import lombok.Builder;
Expand All @@ -15,12 +15,13 @@
@Builder
public record BasicPostResponse(
UUID id,
Long revisionNumber,
String title,
String excerpt,
String slug,
Instant createdDate,
Instant updatedDate,
Instant createdDateTime,
Instant updatedDateTime,
UUID authorId,
CategoryResponse category,
Collection<TagData> tags)
implements RecordUuidIdentifiable, RecordDateTimeAuditable {}
implements RecordUuidIdentifiable, RecordInstantDateTimeAuditable {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record PostRevisionResponse(
UUID authorId,
UUID categoryId,
String tags,
Instant revisionCreatedDate,
Instant revisionCreatedDateTime,
UUID revisionCreatedBy)
implements UUIDRevisionId, Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import module java.base;

import com.vulinh.data.base.RecordDateTimeAuditable;
import com.vulinh.data.base.RecordInstantDateTimeAuditable;
import com.vulinh.data.base.RecordUuidIdentifiable;
import lombok.Builder;
import lombok.With;

@With
@Builder
public record SingleCommentResponse(
UUID id,
String content,
Instant createdDate,
Instant updatedDate,
Boolean isEdited)
implements RecordUuidIdentifiable, RecordDateTimeAuditable {}
UUID id, String content, Instant createdDateTime, Instant updatedDateTime, Boolean isEdited)
implements RecordUuidIdentifiable, RecordInstantDateTimeAuditable {}
4 changes: 2 additions & 2 deletions src/main/java/com/vulinh/data/entity/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import module java.base;

import com.vulinh.annotation.UUIDAsIdIfNullGenerator;
import com.vulinh.data.base.UuidJpaEntity;
import com.vulinh.data.base.AbstractEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
Expand All @@ -15,7 +15,7 @@
@Setter
@ToString
@Builder
public class Category extends UuidJpaEntity {
public class Category extends AbstractEntity<UUID> {

@Serial private static final long serialVersionUID = 106688923162808538L;

Expand Down
17 changes: 6 additions & 11 deletions src/main/java/com/vulinh/data/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import module java.base;

import com.vulinh.data.base.DateTimeAuditable;
import com.vulinh.data.base.UuidJpaEntity;
import com.vulinh.data.base.AbstractTimestampAuditableEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.UuidGenerator;
import org.hibernate.annotations.UuidGenerator.Style;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
Expand All @@ -22,7 +20,7 @@
@ToString
@Builder
@With
public class Comment extends UuidJpaEntity implements DateTimeAuditable {
public class Comment extends AbstractTimestampAuditableEntity<UUID> {

@Serial private static final long serialVersionUID = 8024056047258352378L;

Expand All @@ -32,14 +30,11 @@ public class Comment extends UuidJpaEntity implements DateTimeAuditable {

String content;

@CreatedDate Instant createdDate;

@LastModifiedDate Instant updatedDate;

// So that mapping on Post works
@Column(name = "post_id")
UUID postId;

@CreatedBy
UUID createdBy;
@CreatedBy UUID createdBy;

@LastModifiedBy UUID updatedBy;
}
Loading