Add asset creation form handling and update asset interface
Some checks failed
Build / build (push) Failing after 8s

This commit is contained in:
2025-06-07 19:30:42 +02:00
parent a9889511d1
commit 1c65630565
3 changed files with 24 additions and 1 deletions

View File

@@ -2,10 +2,14 @@ package be.seeseepuff.pcinv.controllers;
import be.seeseepuff.pcinv.services.AssetService; import be.seeseepuff.pcinv.services.AssetService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/** /**
* Controller for handling web requests related to assets. * Controller for handling web requests related to assets.
@@ -51,4 +55,21 @@ public class WebController {
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type)); model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
return "create_asset"; return "create_asset";
} }
/**
* Handles the form submission for creating an asset.
*
* @param model The model to add attributes to.
* @param type The type of asset to create.
* @return The view name for creating the asset.
*/
@PostMapping(
value = "/create/{type}",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
)
public String createTypePost(Model model, @PathVariable String type, @RequestBody MultiValueMap<String, String> formData) {
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(type));
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
return "create_asset";
}
} }

View File

@@ -4,4 +4,6 @@ public interface Asset {
long getId(); long getId();
GenericAsset getAsset(); GenericAsset getAsset();
void setAsset(GenericAsset asset);
} }

View File

@@ -1,7 +1,7 @@
<body th:replace="~{fragments :: base(title='Select type to create', content=~{::content})}"> <body th:replace="~{fragments :: base(title='Select type to create', content=~{::content})}">
<div th:fragment="content"> <div th:fragment="content">
Create a <span th:text="${descriptor.displayName}"></span> Create a <span th:text="${descriptor.displayName}"></span>
<form th:action="'/asset/'+${descriptor.getType()}" method="post"> <form th:action="'/create/'+${descriptor.getType()}" method="post">
<div th:each="d : ${descriptors}"> <div th:each="d : ${descriptors}">
<h2 th:text="${d.displayName}"></h2> <h2 th:text="${d.displayName}"></h2>
<table border="1"> <table border="1">