Adding api
This commit is contained in:
@@ -28,6 +28,7 @@ dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
runtimeOnly("org.postgresql:postgresql")
|
||||
|
||||
15
src/main/java/be/seeseepuff/pcinv/PcinvConfig.java
Normal file
15
src/main/java/be/seeseepuff/pcinv/PcinvConfig.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package be.seeseepuff.pcinv;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class PcinvConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package be.seeseepuff.pcinv.controllers;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.AssetDescriptor;
|
||||
import be.seeseepuff.pcinv.models.Asset;
|
||||
import be.seeseepuff.pcinv.services.AssetService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api")
|
||||
@RestController
|
||||
public class ApiController {
|
||||
private final AssetService assetService;
|
||||
|
||||
@Operation(summary = "Lists all types of assets available in the system.")
|
||||
@GetMapping("/assetTypes")
|
||||
public List<String> assets() {
|
||||
return assetService.getAssetDescriptors().getAssets().stream()
|
||||
.map(AssetDescriptor::getType)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Operation(summary = "Lists all information of a specific asset.")
|
||||
@GetMapping("/asset/{qr}")
|
||||
public Asset getAsset(
|
||||
@PathVariable @Parameter(name = "qr", description = "The QR number of the asset") long qr
|
||||
) {
|
||||
return assetService.getAssetByQr(qr);
|
||||
}
|
||||
|
||||
@Operation(summary = "Adds a work log entry to an asset.")
|
||||
@PostMapping("/asset/worklog")
|
||||
public String addWorkLogEntry(
|
||||
@RequestBody Entry entry
|
||||
) {
|
||||
var qr = entry.qr;
|
||||
var asset = assetService.getAssetByQr(qr);
|
||||
if (asset == null) {
|
||||
throw new IllegalArgumentException("Asset with QR code " + qr + " not found.");
|
||||
}
|
||||
if (entry.entry == null || entry.entry.isBlank()) {
|
||||
throw new IllegalArgumentException("Work log entry comment cannot be empty.");
|
||||
}
|
||||
assetService.addWorkLogEntry(asset, entry.entry);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
@Parameter(name = "qr", description = "The QR number of the asset")
|
||||
public long qr;
|
||||
@Parameter(name = "entry", description = "The work log entry text")
|
||||
public String entry;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import be.seeseepuff.pcinv.meta.AssetInfo;
|
||||
import be.seeseepuff.pcinv.meta.Description;
|
||||
import be.seeseepuff.pcinv.meta.HideInOverview;
|
||||
import be.seeseepuff.pcinv.meta.Property;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -21,6 +22,7 @@ public class ChassisAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -21,6 +22,7 @@ public class CpuAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
@OneToOne(orphanRemoval = true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -21,6 +22,7 @@ public class CustomAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
@OneToOne(orphanRemoval = true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class DisplayAdapterAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class FloppyDriveAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -27,7 +28,9 @@ public class GenericAsset
|
||||
{
|
||||
public static final String TYPE = "asset";
|
||||
|
||||
@Id @GeneratedValue
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The QR code attached to the asset, used for identification.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -21,6 +22,7 @@ public class HddAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
@OneToOne(orphanRemoval = true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class MotherboardAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class NICAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class OpticalDriveAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class PowerSupplyAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -21,6 +22,7 @@ public class RamAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
@OneToOne(orphanRemoval = true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,6 +19,7 @@ public class SoundAdapterAsset implements Asset
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
/// The generic asset associated with this RAM.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package be.seeseepuff.pcinv.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
@@ -18,8 +20,10 @@ import java.time.ZonedDateTime;
|
||||
public class WorkLogEntry {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@JsonIgnore
|
||||
private long id;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToOne(optional = false)
|
||||
private GenericAsset asset;
|
||||
|
||||
@@ -27,5 +31,6 @@ public class WorkLogEntry {
|
||||
private String comment;
|
||||
|
||||
/// The date and time when the work log entry was created.
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private ZonedDateTime date;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user