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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The frontend formats API constraint violations with field labels and displays JS

The list endpoint filters out DONE tickets whose completion timestamp is older than one day (verified by code inspection). This does not delete them, and the board only reloads the list on page load or manual refresh. Entering DONE sets the completion timestamp, editing a ticket that remains DONE preserves it, and leaving DONE clears it.

Backend domain guarantees and limitations, verified by code inspection: the ticket title setter requires a non-null checked `TicketTitle` before storing its text. The public ticket constructor initializes title and lifecycle state, while the no-argument constructor is protected for persistence. `Ticket.changeState` checks the proposed status/blocking combination before mutation, accepts a checked blocking note, clears notes when unblocking, and records, preserves, or clears completion time according to the transition. The resource supplies the current time. These operations protect ordinary domain callers as well as HTTP requests; they do not repair existing inconsistent database rows. The production migrations enforce nullability, text lengths, allowed status values, and project references, but do not enforce the relationships between blocking, status, and completion time.

## Stack

- Java 21 and Quarkus 3.40.1
Expand Down Expand Up @@ -68,10 +70,12 @@ All endpoints use the `/api/tickets` base path. Request and response bodies use
| PUT | `/api/tickets/{id}` | Update a ticket and return it with status 200 |
| DELETE | `/api/tickets/{id}` | Delete a ticket and return status 204 |

Individual reads, updates, and deletes return 404 when the ticket does not exist. Invalid request values return 400.
Individual reads, updates, and deletes explicitly return 404 when the ticket does not exist, verified by code inspection. Invalid request values are intended to return 400 through request parsing and API error handling.

Create requests require a nonblank `title` of at most 200 characters and a `status` of `TODO`, `DOING`, or `DONE`:

By code inspection, ticket creation and updates check required fields in request-record constructors and title/note contents in value records. The update request constructor also rejects blocked-with-DONE and blocked-without-note combinations. Project request constructors check nonblank names of at most 200 characters, independently of the entity setter. Ticket and project write endpoints explicitly reject null request bodies and no longer use Jakarta Validation. The request exception mapper includes constructor failures for ticket and project request records in its JSON-message handling; the runtime wrapping and resulting messages have not been verified during this refactor.

```json
{
"title": "Review ticket validation",
Expand Down Expand Up @@ -120,7 +124,9 @@ After ticket writes, the frontend reads `/api/tickets/{id}` to render the canoni
./mvnw --batch-mode verify -DargLine=
```

The API suite now has 28 tests: the original 16 ticket tests plus 12 project/assignment tests. New coverage includes empty-project listing and ordering, 200-character names, invalid and null requests, renaming an assigned project, missing-project JSON errors, empty-project deletion, protection of open and older DONE assignments, ticket creation with assigned/omitted/null projects, assignment/reassignment/unassignment, and rejected writes leaving stored data unchanged. All 28 API tests passed locally with Java 21 against H2 on 2026-10-18, and Maven verify completed successfully. The existing deletion assertions remain unchanged; the resource now returns its 409 response directly.
The current backend suite contains 29 API tests (17 ticket tests and 12 project/assignment tests) and eight plain JUnit ticket-domain tests. The request-construction refactor updates API assertions to check JSON `message` errors, adds null ticket-body coverage, and replaces the older-DONE fixture's timestamp setter with domain transitions. Direct entity tests cover valid construction, required construction values, null-title rejection, completion timing, blocking reasons, simultaneous unblocking/completion, and rejected transitions preserving state. These changes have been inspected but not compiled or executed; runtime constructor-error mapping remains unverified.

Before this refactor, all 28 API tests passed locally with Java 21 against H2 on 2026-10-18, and Maven verify completed successfully. That result does not verify the current changes. Existing coverage also includes project listing and ordering, maximum name lengths, invalid and null project requests, renaming assigned projects, missing-project errors, deletion protection for open and older DONE assignments, ticket assignment/reassignment/unassignment, and rejected writes preserving stored data.

Frontend browser checks are separate from Maven and use Node.js with an externally available Playwright installation and Chromium. No frontend package dependencies are added to the application. With Playwright available to Node:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package be.alexanderclaes.workboard;

import be.alexanderclaes.workboard.ticket.BlockedNote;
import be.alexanderclaes.workboard.ticket.CreateTicketRequest;
import be.alexanderclaes.workboard.ticket.TicketTitle;
import be.alexanderclaes.workboard.ticket.UpdateTicketRequest;
import be.alexanderclaes.workboard.project.CreateProjectRequest;
import be.alexanderclaes.workboard.project.UpdateProjectRequest;
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -22,7 +26,12 @@ public Response toResponse(WebApplicationException exception) {

Class<?> type = failure.getType().getRawClass();

if ((type == TicketTitle.class || type == BlockedNote.class)
if ((type == TicketTitle.class
|| type == BlockedNote.class
|| type == CreateTicketRequest.class
|| type == UpdateTicketRequest.class
|| type == CreateProjectRequest.class
|| type == UpdateProjectRequest.class)
&& failure.getCause() instanceof IllegalArgumentException reason) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package be.alexanderclaes.workboard.project;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
public record CreateProjectRequest(String name) {
public CreateProjectRequest {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Project name cannot be blank.");
}

public record CreateProjectRequest(
@NotBlank(message = "Project name cannot be blank.")
@Size(max = 200, message = "Project name cannot exceed 200 characters.")
String name
) {
if (name.length() > 200) {
throw new IllegalArgumentException(
"Project name cannot exceed 200 characters.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package be.alexanderclaes.workboard.project;

import be.alexanderclaes.workboard.ticket.Ticket;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
Expand Down Expand Up @@ -36,7 +33,16 @@ public List<ProjectResponse> getProjects() {

@POST
@Transactional
public Response create(@Valid @NotNull CreateProjectRequest request) {
public Response create(CreateProjectRequest request) {
if (request == null) {
throw new BadRequestException(
Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(Map.of("message", "Request body is required."))
.build()
);
}

Project project = new Project();
project.setName(request.name());

Expand All @@ -52,8 +58,17 @@ public Response create(@Valid @NotNull CreateProjectRequest request) {
@Transactional
public ProjectResponse update(
@PathParam("id") UUID id,
@Valid @NotNull UpdateProjectRequest request
UpdateProjectRequest request
) {
if (request == null) {
throw new BadRequestException(
Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(Map.of("message", "Request body is required."))
.build()
);
}

Project project = entityManager.find(Project.class, id);

if (project == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package be.alexanderclaes.workboard.project;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
public record UpdateProjectRequest(String name) {
public UpdateProjectRequest {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Project name cannot be blank.");
}

public record UpdateProjectRequest(
@NotBlank(message = "Project name cannot be blank.")
@Size(max = 200, message = "Project name cannot exceed 200 characters.")
String name
) {
if (name.length() > 200) {
throw new IllegalArgumentException(
"Project name cannot exceed 200 characters.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package be.alexanderclaes.workboard.ticket;

import jakarta.validation.constraints.NotNull;

import java.util.UUID;

public record CreateTicketRequest(
@NotNull TicketTitle title,
@NotNull TicketStatus status,
TicketTitle title,
TicketStatus status,
UUID projectId
) {
public CreateTicketRequest {
if (title == null) {
throw new IllegalArgumentException("Title is required.");
}

if (status == null) {
throw new IllegalArgumentException("Status is required.");
}
}
}
65 changes: 47 additions & 18 deletions src/main/java/be/alexanderclaes/workboard/ticket/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
import jakarta.persistence.*;

import java.time.Instant;
import java.util.Objects;
import java.util.UUID;

@Entity
public class Ticket {
protected Ticket() {
}

public Ticket(TicketTitle title, TicketStatus status, Instant now) {
setTitle(title);
changeState(status, false, null, now);
}

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
Expand All @@ -23,8 +32,8 @@ public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
public void setTitle(TicketTitle title) {
this.title = Objects.requireNonNull(title, "Title is required.").value();
}

@Enumerated(EnumType.STRING)
Expand All @@ -35,37 +44,21 @@ public TicketStatus getStatus() {
return status;
}

public void setStatus(TicketStatus status) {
this.status = status;
}

private boolean blocked;

public boolean isBlocked() {
return blocked;
}

public void setBlocked(boolean blocked) {
this.blocked = blocked;
}

@Column(length = 1000)
private String blockedNote;

public String getBlockedNote() {
return blockedNote;
}

public void setBlockedNote(String blockedNote) {
this.blockedNote = blockedNote;
}

private Instant completedAt;

public void setCompletedAt(Instant completedAt) {
this.completedAt = completedAt;
}

public Instant getCompletedAt() {
return completedAt;
}
Expand All @@ -81,4 +74,40 @@ public Project getProject() {
public void setProject(Project project) {
this.project = project;
}

public void changeState(
TicketStatus status,
boolean blocked,
BlockedNote blockedNote,
Instant now
) {
if (status == null) {
throw new IllegalArgumentException("Status is required.");
}

if (blocked && status == TicketStatus.DONE) {
throw new IllegalArgumentException(
"Unblock this ticket before moving it to DONE.");
}

if (blocked && blockedNote == null) {
throw new IllegalArgumentException(
"Please provide a reason for blocking this ticket.");
}

Objects.requireNonNull(now, "Current time is required.");

Instant nextCompletedAt = null;

if (status == TicketStatus.DONE) {
nextCompletedAt = this.status == TicketStatus.DONE
? this.completedAt
: now;
}

this.status = status;
this.blocked = blocked;
this.blockedNote = blocked ? blockedNote.value() : null;
this.completedAt = nextCompletedAt;
}
}
Loading