Add project
0 parent commit b661930b2f59a14aeccb227c7f46309ff47aec32
Mark George authored on 27 Aug 2021
Showing 22 changed files
View
12
build.gradle 0 → 100644
plugins {
id 'java'
}
 
allprojects {
 
repositories {
mavenCentral()
}
 
}
View
44
service/build.gradle 0 → 100644
plugins {
id 'application'
}
 
dependencies {
def joobyVer = '2.10.0'
implementation group: 'io.jooby', name: 'jooby-netty', version: joobyVer
implementation group: 'io.jooby', name: 'jooby-gson', version: joobyVer
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.5'
}
 
task createMissingSourceDirs {
group = "Source Directories"
description = "Create all of the missing source directories for this project."
doFirst {
sourceSets.each { def sourceRoot ->
sourceRoot.allSource.srcDirTrees.each { def sourceDir ->
if(!sourceDir.dir.exists()) {
println "Creating ${sourceDir}"
mkdir sourceDir.dir
}
}
}
}
}
 
task deleteEmptySourceDirs {
group = "Source Directories"
description = "Delete all empty source directories."
doFirst {
sourceSets.each { def sourceRoot ->
sourceRoot.allSource.srcDirTrees.each { def sourceDir ->
if(sourceDir.dir.exists() && sourceDir.dir.isDirectory() && sourceDir.dir.list().length == 0) {
println "Removing empty ${sourceDir}"
sourceDir.dir.delete()
}
}
}
}
 
}
 
mainClassName = "web.Service"
View
45
service/src/main/java/dao/StudentDao.java 0 → 100644
package dao;
 
import domain.Student;
import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;
 
/**
*
* @author Mark George
*/
public final class StudentDao {
 
private final static SortedMap<String, Student> students = new TreeMap<>();
 
public StudentDao() {
// add some dummy data for testing
if (students.isEmpty()) {
addStudent(new Student("1234", "Boris"));
addStudent(new Student("4321", "Doris"));
}
}
 
public void addStudent(Student studentToAdd) {
students.put(studentToAdd.getId(), studentToAdd);
}
 
public void replaceStudent(String id, Student studentToAdd) {
removeStudent(id);
students.put(studentToAdd.getId(), studentToAdd);
}
 
public void removeStudent(String id) {
students.remove(id);
}
 
public Collection<Student> getStudents() {
return students.values();
}
 
public Student getStudentById(String id) {
return students.get(id);
}
}
View
70
service/src/main/java/domain/Student.java 0 → 100644
package domain;
 
import java.util.Objects;
 
public class Student implements Comparable<Student> {
 
private String id;
private String name;
 
public Student() {
}
 
public Student(String id, String name) {
this.id = id;
this.name = name;
}
 
public String getId() {
return id;
}
 
public void setId(String id) {
this.id = id;
}
 
public String getName() {
return name;
}
 
public void setName(String name) {
this.name = name;
}
 
@Override
public String toString() {
return "Student{" + "id=" + id + ", name=" + name + '}';
}
 
@Override
public int hashCode() {
int hash = 7;
hash = 73 * hash + Objects.hashCode(this.id);
return hash;
}
 
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Student other = (Student) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
 
@Override
public int compareTo(Student other) {
return this.getId().compareTo(other.getId());
}
 
}
View
33
service/src/main/java/web/Service.java 0 → 100644
package web;
 
import dao.StudentDao;
import io.jooby.Cors;
import io.jooby.CorsHandler;
import io.jooby.Jooby;
import io.jooby.ServerOptions;
import io.jooby.json.GsonModule;
 
/**
*
* @author Mark George
*/
public class Service extends Jooby {
 
private final StudentDao dao = new StudentDao();
 
public Service() {
 
setServerOptions(new ServerOptions().setPort(8080));
decorator(new CorsHandler(new Cors().setMethods(DELETE,GET,POST,PUT).setHeaders("*").setOrigin("*")));
install(new GsonModule());
mount(new StudentResource(dao));
 
}
 
public static void main(String[] args) {
new Service().start();
}
 
}
View
50
service/src/main/java/web/StudentResource.java 0 → 100644
package web;
 
import dao.StudentDao;
import domain.Student;
import io.jooby.Jooby;
import io.jooby.MediaType;
import io.jooby.StatusCode;
 
/**
*
* @author Mark George
*/
public class StudentResource extends Jooby {
 
public StudentResource(StudentDao dao) {
 
path("/api/students", () -> {
 
post("", ctx -> {
Student student = ctx.body().to(Student.class);
dao.addStudent(student);
System.out.println("Created " + student);
return ctx.send(StatusCode.CREATED);
});
 
get("", ctx -> dao.getStudents());
 
get("/{id}", ctx -> dao.getStudentById(ctx.path("id").value()));
 
delete("/{id}", ctx -> {
String id = ctx.path("id").value();
dao.removeStudent(id);
System.out.println("Removed " + id);
return ctx.send(StatusCode.NO_CONTENT);
});
 
put("/{id}", ctx -> {
String id = ctx.path("id").value();
Student student = ctx.body().to(Student.class);
dao.replaceStudent(id, student);
System.out.println("Replaced " + id + " with " + student);
return ctx.send(StatusCode.NO_CONTENT);
});
 
}).produces(MediaType.json);
 
}
 
}
View
44
service/src/main/resources/logback.xml 0 → 100644
<!-- logback logging configuration -->
<configuration debug="false">
 
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
 
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger - %msg%n %ex{full}</pattern>
</encoder>
 
<!-- send all except ERROR to stdout -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>ACCEPT</onMismatch>
</filter>
 
<target>System.out</target>
</appender>
 
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
 
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger - %msg%n %ex{full}</pattern>
</encoder>
 
<!-- send only ERROR to stderr -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
 
<target>System.err</target>
 
</appender>
 
<!-- set default logging level -->
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDERR" />
</root>
 
</configuration>
View
5
settings.gradle 0 → 100644
rootProject.name = 'vue-demo'
include 'service'
include 'vue-client'
 
View
56
vue-client/build.gradle 0 → 100644
plugins {
id 'application'
}
 
sourceSets {
// Jooby assets
web {
resources {
srcDirs=['static']
}
java {
srcDirs = []
}
}
}
 
dependencies {
def joobyVer = '2.10.0'
implementation group: 'io.jooby', name: 'jooby-netty', version: joobyVer
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.5'
}
 
 
task createMissingSourceDirs {
group = "Source Directories"
description = "Create all of the missing source directories for this project."
doFirst {
sourceSets.each { def sourceRoot ->
sourceRoot.allSource.srcDirTrees.each { def sourceDir ->
if(!sourceDir.dir.exists()) {
println "Creating ${sourceDir}"
mkdir sourceDir.dir
}
}
}
}
}
 
task deleteEmptySourceDirs {
group = "Source Directories"
description = "Delete all empty source directories."
doFirst {
sourceSets.each { def sourceRoot ->
sourceRoot.allSource.srcDirTrees.each { def sourceDir ->
if(sourceDir.dir.exists() && sourceDir.dir.isDirectory() && sourceDir.dir.list().length == 0) {
println "Removing empty ${sourceDir}"
sourceDir.dir.delete()
}
}
}
}
 
}
 
mainClassName = "Server"
View
14
vue-client/customs.json 0 → 100644
{
"elements": {
"pageheader": {}
},
"attributes": {
"@click": {},
"v-on:click": {},
"v-for": {},
":href": {
"context": "a"
},
"v-model": {}
}
}
View
27
vue-client/src/main/java/Server.java 0 → 100644
import io.jooby.Jooby;
import io.jooby.ServerOptions;
import io.jooby.StatusCode;
import java.nio.file.Paths;
 
/**
*
* @author Mark George
*/
public class Server extends Jooby {
 
public Server() {
setServerOptions(new ServerOptions().setPort(8081));
 
get("/favicon.ico", ctx -> ctx.send(StatusCode.NO_CONTENT));
assets("/", "/static/list.html");
assets("/*", Paths.get("static"));
}
 
public static void main(String[] args) {
System.out.println("Vue.js Client");
new Server().start();
}
 
}
View
vue-client/src/main/resources/logback.xml 0 → 100644
View
vue-client/static/add.html 0 → 100644
View
vue-client/static/css/forms.css 0 → 100644
View
vue-client/static/css/style.css 0 → 100644
View
vue-client/static/js/external/axios.js 0 → 100644
View
vue-client/static/js/external/vue.global.js 0 → 100644
View
vue-client/static/js/pageheader.js 0 → 100644
View
vue-client/static/js/student-list.js 0 → 100644
View
vue-client/static/js/student.js 0 → 100644
View
vue-client/static/list.html 0 → 100644
View
vue-client/static/view.html 0 → 100644