Skip to content
Open
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
12 changes: 3 additions & 9 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
Expand All @@ -8,9 +9,6 @@
</parent>
<artifactId>app</artifactId>
<description>quarkus-demo-app-backend</description>
<!--
https://code.quarkus.io/?g=org.example&a=demo&e=resteasy-reactive-jsonb&e=spring-data-jpa&e=flyway&e=jdbc-postgresql&e=smallrye-jwt
-->
<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -95,12 +93,10 @@
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<scope>provided</scope>
<version>${querydsl.version}</version>
<classifier>jakarta</classifier>
<scope>provided</scope>
</dependency>

<!-- Test -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down Expand Up @@ -207,7 +203,6 @@
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<!--suppress UnresolvedMavenProperty -->
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
Expand All @@ -225,7 +220,6 @@
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<!--suppress UnresolvedMavenProperty -->
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
Expand Down
58 changes: 58 additions & 0 deletions backend/src/main/java/org/example/app/task/common/TaskItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.example.app.task.common;

import org.example.app.general.common.ApplicationEntity;

import java.time.LocalDateTime;

public interface TaskItem extends ApplicationEntity {

/**
* @return the title of this task item. Gives a brief summary to describe what to do or buy.
*/
String getTitle();

/**
* @param title new value of {@link #getTitle()}.
*/
void setTitle(String title);

/**
* @return {@code true} if this task is completed (done), {@code false} otherwise.
*/
boolean isCompleted();

/**
* @param completed new value of {@link #isCompleted()}.
*/
void setCompleted(boolean completed);

/**
* @return {@code true} if this task is starred (marked as favorite), {@code false} otherwise.
*/
boolean isStarred();

/**
* @param starred new value of {@link #isStarred()}.
*/
void setStarred(boolean starred);

/**
* @return the deadline as until this task shall be {@link #isCompleted() completed}.
*/
LocalDateTime getDeadline();

/**
* @param deadline the new value of {@link #getDeadline()}.
*/
void setDeadline(LocalDateTime deadline);

/**
* @return the {@link TaskList#getId() primary key} of the owning {@link TaskList}.
*/
Long getTaskListId();

/**
* @param taskListId the new value of {@link #getTaskListId()}.
*/
void setTaskListId(Long taskListId);
}
18 changes: 18 additions & 0 deletions backend/src/main/java/org/example/app/task/common/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.example.app.task.common;

import org.example.app.general.common.ApplicationEntity;

public interface TaskList extends ApplicationEntity {

/**
* @return the title of this {@link TaskList}. Gives a brief summary to describe this list of tasks (e.g. "Shopping
* list", "Packing list" or "Things to buy at construction market").
*/
String getTitle();

/**
* @param title new value of {@link #getTitle()}.
*/
void setTitle(String title);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.example.app.task.dataaccess;

import jakarta.persistence.*;
import org.example.app.general.dataaccess.ApplicationPersistenceEntity;
import org.example.app.task.common.TaskItem;

import java.time.LocalDateTime;

@Entity
@Table(name = "task_item")
public class TaskItemEntity extends ApplicationPersistenceEntity implements TaskItem {

@Column
private String title;

@Column
private boolean completed;

@Column
private boolean starred;

@JoinColumn(name = "LIST_ID")
@ManyToOne(fetch = FetchType.LAZY)
private TaskListEntity taskListEntity;

@Column
private LocalDateTime deadline;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@Override
public boolean isCompleted() {
return completed;
}
@Override
public void setCompleted(boolean completed) {
this.completed = completed;
}
@Override
public boolean isStarred() {
return starred;
}
@Override
public void setStarred(boolean starred) {
this.starred = starred;
}
@Override
public LocalDateTime getDeadline() {
return deadline;
}
@Override
public void setDeadline(LocalDateTime deadline) {
this.deadline = deadline;
}

@Override
public Long getTaskListId() {

if (this.taskListEntity == null) {
return null;
}
return this.taskListEntity.getId();
}

@Override
public void setTaskListId(Long taskListId) {

if (taskListId == null) {
this.taskListEntity = null;
} else {
TaskListEntity taskListEntity = new TaskListEntity();
taskListEntity.setId(taskListId);
taskListEntity.setVersion(Integer.valueOf(0));
this.taskListEntity = taskListEntity;
}
}

public TaskListEntity getTaskListEntity() {
return taskListEntity;
}

public void setTaskListEntity(TaskListEntity taskListEntity) {
this.taskListEntity = taskListEntity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.app.task.dataaccess;

import org.springframework.data.jpa.repository.JpaRepository;

public interface TaskItemRepository extends JpaRepository<TaskItemEntity, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.example.app.task.dataaccess;

import jakarta.persistence.*;
import org.example.app.general.dataaccess.ApplicationPersistenceEntity;
import org.example.app.task.common.TaskList;

import java.util.List;

@Entity
@Table(name = "task_list")
public class TaskListEntity extends ApplicationPersistenceEntity implements TaskList {

@Column
private String title;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "taskListEntity")
List<TaskItemEntity> taskItemEntities;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}

/**
* @return the {@link List} of {@link TaskItemEntity task-items} in this task-list.
*/
public List<TaskItemEntity> getItems() {

return this.taskItemEntities;
}

/**
* @param taskItems the new value of {@link #getItems()}.
*/
public void setItems(List<TaskItemEntity> taskItems) {

this.taskItemEntities = taskItems;
}

public List<TaskItemEntity> getTaskItemEntities() {
return taskItemEntities;
}

public void setTaskItemEntities(List<TaskItemEntity> taskItemEntities) {
this.taskItemEntities = taskItemEntities;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.example.app.task.dataaccess;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TaskListRepository extends JpaRepository<TaskListEntity, Long> {

@Query("SELECT list FROM TaskListEntity list JOIN list.taskItemEntities items WHERE items.completed = true")
List<TaskListEntity> findByCompleted();

}
68 changes: 68 additions & 0 deletions backend/src/main/java/org/example/app/task/logic/TaskItemEto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.example.app.task.logic;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.example.app.general.common.AbstractEto;
import org.example.app.task.common.TaskItem;
import org.example.app.task.dataaccess.TaskListEntity;

import java.time.LocalDateTime;
@Schema(name = "TaskItem", description = "Object that represents a task item")
public class TaskItemEto extends AbstractEto implements TaskItem {
@NotBlank(message = "A task item must always have a title")
@Schema(required = true, example = "Buy eggs", description = "The task title or description")
private String title;
@Schema(required = false, description = "Until when the task must be completed")
private boolean completed;
@Schema(required = false, description = "Until when the task must be completed")
private boolean starred;

@Min(value = 1, message = "A task item must always be associated with a task list")
@NotNull(message = "A task item must always be associated with a task list")
@Schema(required = true, example = "1", description = "The id of the task list to which this item belongs")
private Long taskListId;
@Schema(required = false, description = "Until when the task must be completed")
private LocalDateTime deadline;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@Override
public boolean isCompleted() {
return completed;
}
@Override
public void setCompleted(boolean completed) {
this.completed = completed;
}
@Override
public boolean isStarred() {
return starred;
}
@Override
public void setStarred(boolean starred) {
this.starred = starred;
}
@Override
public LocalDateTime getDeadline() {
return deadline;
}
@Override
public void setDeadline(LocalDateTime deadline) {
this.deadline = deadline;
}
@Override
public Long getTaskListId() {
return taskListId;
}
@Override
public void setTaskListId(Long id) {
this.taskListId = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.example.app.task.logic;

import org.example.app.task.dataaccess.TaskItemEntity;
import org.mapstruct.Mapper;

import java.util.ArrayList;
import java.util.List;

@Mapper(componentModel = "cdi")
public interface TaskItemMapper {

default List<TaskItemEto> toEtos(List<TaskItemEntity> items) {
List<TaskItemEto> result = new ArrayList<>();
for (TaskItemEntity item : items) {
result.add(toEto(item));
}

return result;
}

TaskItemEto toEto(TaskItemEntity item);

TaskItemEntity toEntity(TaskItemEto item);
}
Loading