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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REST API for managing clients, technicians and service orders (help desk style),

## Live demo

- API: https://service-order-management-nxil.onrender.com
- Home page: https://service-order-management-nxil.onrender.com
- Swagger UI: https://service-order-management-nxil.onrender.com/swagger-ui.html

The demo runs on free tiers ([Render](https://render.com) for the API and [Neon](https://neon.com) for PostgreSQL), so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http,
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// The first matching rule wins, so the specific rules come before anyRequest().
.authorizeHttpRequests(auth -> auth
.requestMatchers(HttpMethod.GET, "/", "/index.html").permitAll()
.requestMatchers(HttpMethod.HEAD, "/", "/index.html").permitAll()
.requestMatchers("/auth/login", "/auth/refresh", "/auth/logout").permitAll()
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
.requestMatchers(HttpMethod.PUT, "/users/me/password").authenticated()
Expand Down
155 changes: 155 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Service Order Management API</title>
<meta name="description" content="REST API for managing clients, technicians and service orders, built with Spring Boot.">
<style>
:root {
--bg: #f6f7f9;
--surface: #ffffff;
--text: #1b2430;
--muted: #5b6675;
--border: #dfe3e8;
--accent: #2456d6;
--accent-text: #ffffff;
--chip: #eaf0ff;
--chip-text: #1b3f9e;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #10151c;
--surface: #182028;
--text: #e8edf3;
--muted: #9aa6b4;
--border: #2a3542;
--accent: #6e96ff;
--accent-text: #0d1522;
--chip: #1f2c45;
--chip-text: #b7ccff;
}
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.6;
}
main { max-width: 860px; margin: 0 auto; padding: 56px 20px 40px; }
h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.15; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 40px 0 14px; }
p { margin: 0 0 12px; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0 8px; }
.button {
display: inline-block;
padding: 10px 18px;
border-radius: 8px;
border: 1px solid var(--border);
background: var(--surface);
color: var(--text);
font-weight: 600;
text-decoration: none;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); }
.pill { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; list-style: none; }
.chips li { background: var(--chip); color: var(--chip-text); padding: 4px 12px; border-radius: 999px; font-size: .9rem; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; font-size: .95rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
a { color: var(--accent); }
footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; }
</style>
</head>
<body>
<main>
<h1>Service Order Management API</h1>
<p class="lead">
A REST API for managing clients, technicians and service orders, help desk style.
Built with Spring Boot, secured with JWT and covered by automated tests.
</p>

<div class="actions">
<a class="button primary" href="/swagger-ui.html">Try it in Swagger UI</a>
<a class="button" href="https://github.com/otaldoneto/Project-Help-Desk">View the source on GitHub</a>
</div>

<h2>What it does</h2>
<div class="grid">
<div class="card">
<h3>Service order lifecycle</h3>
<p>Orders move through enforced status transitions, and finishing one requires a root cause report.</p>
</div>
<div class="card">
<h3>Authentication and roles</h3>
<p>JWT access tokens, rotating refresh tokens, <code>ADMIN</code> and <code>USER</code> roles, and login rate limiting.</p>
</div>
<div class="card">
<h3>Audit trail</h3>
<p>Every order records who created it and who changed it last, and concurrent edits never overwrite each other silently.</p>
</div>
<div class="card">
<h3>PDF reports</h3>
<p>Download a report for any service order, and filter and paginate the list by status, priority, client, technician or title.</p>
</div>
</div>

<h2>Order lifecycle</h2>
<div class="flow" aria-label="Service order lifecycle">
<span class="pill">OPEN</span> assign &rarr;
<span class="pill">IN_PROGRESS</span> finish &rarr;
<span class="pill">FINISHED</span>
<span>(or cancel from <code>OPEN</code> / <code>IN_PROGRESS</code> to <span class="pill">CANCELED</span>)</span>
</div>

<h2>Main endpoints</h2>
<div class="table-wrap">
<table>
<thead><tr><th>Method and path</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>POST /auth/login</code></td><td>Log in and receive an access token and a refresh token</td></tr>
<tr><td><code>POST /auth/refresh</code></td><td>Exchange a refresh token for a new pair</td></tr>
<tr><td><code>GET /orders</code></td><td>List service orders with filters and pagination</td></tr>
<tr><td><code>POST /orders</code></td><td>Create a service order for a client</td></tr>
<tr><td><code>PUT /orders/{id}/assign/{technicianId}</code></td><td>Assign a technician</td></tr>
<tr><td><code>GET /orders/{id}/report</code></td><td>Download the order report as PDF</td></tr>
</tbody>
</table>
</div>
<p style="margin-top:12px;color:var(--muted);font-size:.95rem">
Every endpoint except login needs a token, so the interactive docs are the best place to start.
</p>

<h2>Built with</h2>
<ul class="chips">
<li>Java 25</li>
<li>Spring Boot</li>
<li>Spring Security</li>
<li>Spring Data JPA</li>
<li>PostgreSQL</li>
<li>Flyway</li>
<li>Docker</li>
<li>JUnit 5 and Mockito</li>
<li>GitHub Actions</li>
</ul>

<footer>
Hosted on free tiers (Render and Neon): after 15 minutes without traffic the API goes to sleep, and the first request
afterwards can take about a minute.
</footer>
</main>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.serviceorder.management.controllers;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithAnonymousUser;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WithAnonymousUser
class LandingPageTest extends ApiTestSupport {

@Test
@DisplayName("GET / should forward to the public landing page without a token")
void rootShouldForwardToTheLandingPage() throws Exception {
// MockMvc does not follow forwards, so the forward itself is what proves the welcome page is mapped and public
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("index.html"));
}

@Test
@DisplayName("GET /index.html should serve the landing page without a token")
void landingPageShouldBePublic() throws Exception {
mockMvc.perform(get("/index.html"))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
.andExpect(content().string(containsString("Service Order Management API")));
}

@Test
@DisplayName("HEAD / should also be public, for uptime checks and link previews")
void headRequestShouldBePublic() throws Exception {
mockMvc.perform(head("/index.html")).andExpect(status().isOk());
}

@Test
@DisplayName("Opening the landing page must not make the rest of the API public")
void apiShouldStayProtected() throws Exception {
mockMvc.perform(get("/clients")).andExpect(status().isUnauthorized());
mockMvc.perform(get("/orders")).andExpect(status().isUnauthorized());
mockMvc.perform(post("/")).andExpect(status().isUnauthorized());
}
}
Loading