-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement scheduling and event module
- Loading branch information
Showing
68 changed files
with
1,545 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/app/teamwize/api/auth/domain/event/OrganizationCreatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package app.teamwize.api.auth.domain.event; | ||
|
||
import app.teamwize.api.event.model.EventPayload; | ||
import app.teamwize.api.event.model.EventType; | ||
|
||
import java.util.Map; | ||
|
||
public record OrganizationCreatedEvent(UserEventPayload user, | ||
OrganizationEventPayload organization) implements EventPayload { | ||
@Override | ||
public EventType name() { | ||
return EventType.ORGANIZATION_CREATED; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> payload() { | ||
return Map.of( | ||
"organization", organization, | ||
"user", user | ||
); | ||
} | ||
|
||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/app/teamwize/api/auth/domain/event/OrganizationEventPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.teamwize.api.auth.domain.event; | ||
|
||
import app.teamwize.api.organization.domain.entity.Organization; | ||
|
||
public record OrganizationEventPayload(Long id, String name) { | ||
public OrganizationEventPayload(Organization organization) { | ||
this(organization.getId(), organization.getName()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/app/teamwize/api/auth/domain/event/UserEventPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package app.teamwize.api.auth.domain.event; | ||
|
||
import app.teamwize.api.user.domain.UserRole; | ||
import app.teamwize.api.user.domain.entity.User; | ||
|
||
public record UserEventPayload( | ||
Long id, | ||
UserRole role, | ||
String email, | ||
String password, | ||
String phone, | ||
String firstName, | ||
String lastName, | ||
String country, | ||
String timezone) { | ||
|
||
public UserEventPayload(User user) { | ||
this(user.getId(), | ||
user.getRole(), | ||
user.getEmail(), | ||
user.getPassword(), | ||
user.getPhone(), | ||
user.getFirstName(), | ||
user.getLastName(), | ||
user.getCountry(), | ||
user.getTimezone() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/app/teamwize/api/base/domain/model/Paged.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package app.teamwize.api.base.domain.model; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import lombok.With; | ||
|
||
import java.util.List; | ||
|
||
@With | ||
public record Paged<T>( | ||
@Nonnull | ||
List<T> contents, | ||
@Nonnull | ||
Integer pageNumber, | ||
@Nonnull | ||
Integer pageSize, | ||
@Nonnull | ||
Integer totalPages, | ||
@Nonnull | ||
Long totalContents) { | ||
|
||
|
||
public Paged(List<T> contents, Integer pageNumber, Integer pageSize, Long totalContents) { | ||
this(contents, pageNumber, pageSize, | ||
(int) Math.ceil((double) totalContents / pageSize), // Calculate totalPages | ||
totalContents); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/app/teamwize/api/base/domain/model/Pagination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package app.teamwize.api.base.domain.model; | ||
|
||
public record Pagination(Integer pageNumber,Integer pageSize) { | ||
} |
35 changes: 17 additions & 18 deletions
35
src/main/java/app/teamwize/api/base/domain/model/response/PagedResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
package app.teamwize.api.base.domain.model.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PagedResponse<T> { | ||
@Nonnull | ||
List<T> contents; | ||
import java.util.List; | ||
|
||
@Nonnull | ||
Integer pageNumber; | ||
@Nonnull | ||
Integer pageSize; | ||
@Nonnull | ||
Integer totalPages; | ||
@Nonnull | ||
Long totalContents; | ||
public record PagedResponse<T>( | ||
@Nonnull | ||
List<T> contents, | ||
@Nonnull | ||
Integer pageNumber, | ||
@Nonnull | ||
Integer pageSize, | ||
@Nonnull | ||
Integer totalPages, | ||
@Nonnull | ||
Long totalContents) { | ||
|
||
public PagedResponse(List<T> contents, Integer pageNumber, Integer pageSize, Long totalContents) { | ||
this(contents, pageNumber, pageSize, | ||
(int) Math.ceil((double) totalContents / pageSize), // Calculate totalPages | ||
totalContents); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/app/teamwize/api/base/jpa/HibernateJacksonMapperSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package app.teamwize.api.base.jpa; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import io.hypersistence.utils.hibernate.type.util.ObjectMapperSupplier; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
|
||
public class HibernateJacksonMapperSupplier implements ObjectMapperSupplier { | ||
|
||
@Override | ||
public ObjectMapper get() { | ||
var timeModule = new JavaTimeModule(); | ||
|
||
return Jackson2ObjectMapperBuilder.json() | ||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
.failOnUnknownProperties(false) | ||
.failOnEmptyBeans(false) | ||
.modules(timeModule) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.teamwize.api.base.util; | ||
|
||
public class StringUtils { | ||
public static String toSnakeCase(String className) { | ||
return className.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/app/teamwize/api/event/entity/EventEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package app.teamwize.api.event.entity; | ||
|
||
import app.teamwize.api.base.domain.entity.BaseAuditEntity; | ||
import app.teamwize.api.event.model.EventStatus; | ||
import app.teamwize.api.event.model.EventType; | ||
import app.teamwize.api.organization.domain.entity.Organization; | ||
import io.hypersistence.utils.hibernate.type.json.JsonType; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.Type; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "events") | ||
public class EventEntity extends BaseAuditEntity { | ||
@Id | ||
@GeneratedValue(generator = "event_id_seq_gen") | ||
@SequenceGenerator(name = "event_id_seq_gen", sequenceName = "event_id_seq", allocationSize = 10) | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private EventType type; | ||
|
||
@Type(JsonType.class) | ||
private Map<String, Object> params; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private EventStatus status; | ||
|
||
private Byte maxAttempts; | ||
|
||
private Instant scheduledAt; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "organization_id") | ||
private Organization organization; | ||
|
||
@OneToMany(mappedBy = "event") | ||
private List<EventExecutionEntity> executions; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/app/teamwize/api/event/entity/EventExecutionEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package app.teamwize.api.event.entity; | ||
|
||
import app.teamwize.api.base.domain.entity.BaseAuditEntity; | ||
import app.teamwize.api.event.model.EventExecutionStatus; | ||
import app.teamwize.api.event.model.EventExitCode; | ||
import io.hypersistence.utils.hibernate.type.json.JsonType; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.Type; | ||
|
||
import java.util.Map; | ||
|
||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "event_executions") | ||
public class EventExecutionEntity extends BaseAuditEntity { | ||
@Id | ||
@GeneratedValue(generator = "event_execution_id_seq_gen") | ||
@SequenceGenerator(name = "event_execution_id_seq_gen", sequenceName = "event_execution_id_seq", allocationSize = 10) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "event_id") | ||
private EventEntity event; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private EventExecutionStatus status; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private EventExitCode exitCode; | ||
|
||
private Integer attempts; | ||
|
||
private String handler; | ||
|
||
@Type(JsonType.class) | ||
@Column(columnDefinition = "jsonb") | ||
private Map<String, Object> metadata; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/app/teamwize/api/event/exception/EventNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.teamwize.api.event.exception; | ||
|
||
import app.teamwize.api.base.exception.BaseException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class EventNotFoundException extends BaseException { | ||
|
||
private final Long id; | ||
|
||
} |
Oops, something went wrong.