Added settings, updated build system for quasar.
This commit is contained in:
parent
c0c036d223
commit
f1bc3c7b0a
|
@ -13,19 +13,21 @@ module build_system;
|
||||||
import dsh;
|
import dsh;
|
||||||
|
|
||||||
const DIST = "./src/main/resources/app";
|
const DIST = "./src/main/resources/app";
|
||||||
|
const DIST_ORIGIN = "./quasar-app/dist/spa";
|
||||||
|
const APP_BUILD = "quasar build -m spa";
|
||||||
|
|
||||||
void main(string[] args) {
|
void main(string[] args) {
|
||||||
print("Building RailSignalAPI");
|
print("Building RailSignalAPI");
|
||||||
chdir("railsignal-app");
|
chdir("quasar-app");
|
||||||
print("Building app...");
|
print("Building app...");
|
||||||
runOrQuit("npm run build");
|
runOrQuit(APP_BUILD);
|
||||||
print("Copying dist to %s", DIST);
|
print("Copying dist from %s to %s", DIST_ORIGIN, DIST);
|
||||||
chdir("..");
|
chdir("..");
|
||||||
removeIfExists(DIST);
|
removeIfExists(DIST);
|
||||||
mkdir(DIST);
|
mkdir(DIST);
|
||||||
copyDir("railsignal-app/dist", DIST);
|
copyDir(DIST_ORIGIN, DIST);
|
||||||
print("Building API...");
|
print("Building API...");
|
||||||
runOrQuit("mvn clean package spring-boot:repackage");
|
runOrQuit("mvn clean package spring-boot:repackage -DskipTests=true");
|
||||||
print("Build complete!");
|
print("Build complete!");
|
||||||
|
|
||||||
if (args.length > 1 && args[1] == "run") {
|
if (args.length > 1 && args[1] == "run") {
|
||||||
|
|
|
@ -68,7 +68,7 @@ module.exports = configure(function (ctx) {
|
||||||
|
|
||||||
// rebuildCache: true, // rebuilds Vite/linter/etc cache on startup
|
// rebuildCache: true, // rebuilds Vite/linter/etc cache on startup
|
||||||
|
|
||||||
// publicPath: '/',
|
publicPath: "/app/",
|
||||||
// analyze: true,
|
// analyze: true,
|
||||||
env: {
|
env: {
|
||||||
API_URL: ctx.dev ? "http://localhost:8080/api" : "http://localhost:8080/api",
|
API_URL: ctx.dev ? "http://localhost:8080/api" : "http://localhost:8080/api",
|
||||||
|
@ -76,7 +76,7 @@ module.exports = configure(function (ctx) {
|
||||||
},
|
},
|
||||||
// rawDefine: {}
|
// rawDefine: {}
|
||||||
// ignorePublicFolder: true,
|
// ignorePublicFolder: true,
|
||||||
// minify: false,
|
// minify: "hidden",
|
||||||
// polyfillModulePreload: true,
|
// polyfillModulePreload: true,
|
||||||
// distDir
|
// distDir
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,14 @@ import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({command, mode}) => {
|
||||||
plugins: [vue()],
|
return {
|
||||||
resolve: {
|
plugins: [vue()],
|
||||||
alias: {
|
resolve: {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
alias: {
|
||||||
}
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
base: mode === "production" ? "/app/" : undefined
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package nl.andrewl.railsignalapi.model;
|
package nl.andrewl.railsignalapi.model;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a closed system that contains a collection of components.
|
* Represents a closed system that contains a collection of components.
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
public class RailSystem {
|
public class RailSystem {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -25,6 +24,11 @@ public class RailSystem {
|
||||||
@Column(nullable = false, unique = true)
|
@Column(nullable = false, unique = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
|
@PrimaryKeyJoinColumn
|
||||||
|
@Setter
|
||||||
|
private RailSystemSettings settings;
|
||||||
|
|
||||||
public RailSystem(String name) {
|
public RailSystem(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package nl.andrewl.railsignalapi.model;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single entity that's paired with each rail system, and contains some
|
||||||
|
* settings that apply globally to the rail system.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
@Getter
|
||||||
|
public class RailSystemSettings {
|
||||||
|
@Id
|
||||||
|
@Column(name = "rail_system_id", unique = true, nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@MapsId
|
||||||
|
@OneToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "rail_system_id")
|
||||||
|
private RailSystem railSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether the rail system is read-only, meaning it cannot be changed
|
||||||
|
* by any means.
|
||||||
|
*/
|
||||||
|
@Column(nullable = false) @Setter
|
||||||
|
private boolean readOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether it is required for users to be authenticated in order to access
|
||||||
|
* this rail system. If true, the system will check that users are
|
||||||
|
* authenticated prior to any access or modification of the system.
|
||||||
|
*/
|
||||||
|
@Column(nullable = false) @Setter
|
||||||
|
private boolean authenticationRequired;
|
||||||
|
|
||||||
|
public RailSystemSettings(RailSystem rs) {
|
||||||
|
this.id = rs.getId();
|
||||||
|
this.railSystem = rs;
|
||||||
|
this.readOnly = false;
|
||||||
|
this.authenticationRequired = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package nl.andrewl.railsignalapi.rest;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import nl.andrewl.railsignalapi.rest.dto.RailSystemSettingsPayload;
|
||||||
|
import nl.andrewl.railsignalapi.service.RailSystemSettingsService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(path = "/api/rs/{rsId}/settings")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RailSystemSettingsApiController {
|
||||||
|
private final RailSystemSettingsService settingsService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public RailSystemSettingsPayload getSettings(@PathVariable long rsId) {
|
||||||
|
return settingsService.getSettings(rsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public RailSystemSettingsPayload updateSettings(@PathVariable long rsId, @RequestBody @Valid RailSystemSettingsPayload payload) {
|
||||||
|
return settingsService.setSettings(rsId, payload);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.andrewl.railsignalapi.rest.dto;
|
||||||
|
|
||||||
|
import nl.andrewl.railsignalapi.model.RailSystemSettings;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public record RailSystemSettingsPayload(
|
||||||
|
@NotNull
|
||||||
|
boolean readOnly,
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
boolean authenticationRequired
|
||||||
|
) {
|
||||||
|
public RailSystemSettingsPayload(RailSystemSettings settings) {
|
||||||
|
this(
|
||||||
|
settings.isReadOnly(),
|
||||||
|
settings.isAuthenticationRequired()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package nl.andrewl.railsignalapi.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import nl.andrewl.railsignalapi.dao.RailSystemRepository;
|
||||||
|
import nl.andrewl.railsignalapi.model.RailSystem;
|
||||||
|
import nl.andrewl.railsignalapi.model.RailSystemSettings;
|
||||||
|
import nl.andrewl.railsignalapi.rest.dto.RailSystemSettingsPayload;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RailSystemSettingsService {
|
||||||
|
private final RailSystemRepository railSystemRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public RailSystemSettingsPayload getSettings(long rsId) {
|
||||||
|
var rs = railSystemRepository.findById(rsId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||||
|
return new RailSystemSettingsPayload(getOrCreateSettings(rs));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public RailSystemSettingsPayload setSettings(long rsId, RailSystemSettingsPayload payload) {
|
||||||
|
var rs = railSystemRepository.findById(rsId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||||
|
RailSystemSettings settings = getOrCreateSettings(rs);
|
||||||
|
settings.setReadOnly(payload.readOnly());
|
||||||
|
settings.setAuthenticationRequired(payload.authenticationRequired());
|
||||||
|
railSystemRepository.save(rs);
|
||||||
|
return new RailSystemSettingsPayload(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RailSystemSettings getOrCreateSettings(RailSystem rs) {
|
||||||
|
if (rs.getSettings() == null) {
|
||||||
|
rs.setSettings(new RailSystemSettings(rs));
|
||||||
|
railSystemRepository.save(rs);
|
||||||
|
}
|
||||||
|
return rs.getSettings();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue