Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
huangbaixun committed Apr 25, 2018
0 parents commit 5dd1760
Show file tree
Hide file tree
Showing 35 changed files with 586 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
40 changes: 40 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>course-api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
16 changes: 16 additions & 0 deletions .springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.9.3.201803200843-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
</configs>
<autoconfigs>
<config>java:io.huangbaixun.springbootstarter.CourseApiApp</config>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>
13 changes: 13 additions & 0 deletions derby.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
----------------------------------------------------------------
Wed Apr 25 22:23:49 CST 2018:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.13.1.1 - (1765088): instance a816c00e-0162-fd30-618b-00000ca12a28
on database directory memory:D:\workspace\course-api\testdb with class loader sun.misc.Launcher$AppClassLoader@73d16e93
Loaded from file:/C:/Users/Admin/.m2/repository/org/apache/derby/derby/10.13.1.1/derby-10.13.1.1.jar
java.vendor=Oracle Corporation
java.runtime.version=1.8.0_101-b13
user.dir=D:\workspace\course-api
os.name=Windows 10
os.arch=amd64
os.version=10.0
derby.system.home=null
Database Class Loader started - derby.database.classpath=''
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.huangbaixun.springbootquickstart</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
63 changes: 63 additions & 0 deletions src/main/java/io/huangbaixun/springbootstarter/Course/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.huangbaixun.springbootstarter.Course;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import io.huangbaixun.springbootstarter.Topic.Topic;

@Entity
public class Course {

@Id
private String id;
private String name;
private String description;

@ManyToOne
private Topic topic;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Course() {

}

public Course(String id, String name, String description, String topicId) {
super();
this.id = id;
this.name = name;
this.description = description;
this.setTopic(new Topic(topicId, "", ""));
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Topic getTopic() {
return topic;
}

public void setTopic(Topic topic) {
this.topic = topic;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.huangbaixun.springbootstarter.Course;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.huangbaixun.springbootstarter.Topic.Topic;

@RestController
public class CourseController {

@Autowired
private CourseService courseService;

@RequestMapping(method=RequestMethod.GET,value="/topics/{id}/courses")
public List<Course> getAllCourses(@PathVariable String id)
{
return courseService.getAllCourses(id);
}

@RequestMapping("/topics/{topicId}/courses/{id}")
public Course getCourse(@PathVariable String id)
{
return courseService.GetCourse(id);
}

@RequestMapping(method=RequestMethod.POST,value="/topics/{topicId}/courses")
public void addCourse(@RequestBody Course course,@PathVariable String topicId)
{
course.setTopic(new Topic(topicId,"",""));
courseService.addCourse(course);
}

@RequestMapping(method=RequestMethod.DELETE,value="/topics/{topicId}/courses/{id}")
public void deleteCourse(@PathVariable String id)
{
courseService.deleteCourse(id);
}

@RequestMapping(method=RequestMethod.PUT,value="/topics/{topicId}/courses/{id}")
public void updateCourse(@RequestBody Course course,@PathVariable String id,@PathVariable String topicId)
{
course.setTopic(new Topic(topicId,"",""));
courseService.updateCourse(course);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.huangbaixun.springbootstarter.Course;

import org.springframework.data.repository.CrudRepository;
import java.lang.String;
import io.huangbaixun.springbootstarter.Course.Course;
import java.util.List;

public interface CourseRepository extends CrudRepository<Course,String>{
List<Course> findByTopicId(String topicId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.huangbaixun.springbootstarter.Course;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseService {

@Autowired
private CourseRepository CourseRepository;

public List<Course> getAllCourses(String topicId)
{
return CourseRepository.findByTopicId(topicId);
}

public Course GetCourse(String id)
{
return CourseRepository.findOne(id);
}

public void addCourse(Course course)
{
CourseRepository.save(course);
}

public void updateCourse(Course course)
{
CourseRepository.save(course);
}

public void deleteCourse(String id)
{
CourseRepository.delete(id);
}

}
18 changes: 18 additions & 0 deletions src/main/java/io/huangbaixun/springbootstarter/CourseApiApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.huangbaixun.springbootstarter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import io.huangbaixun.springbootstarter.Topic.TopicRepository;

@SpringBootApplication
public class CourseApiApp {

public static void main(String[] args){
SpringApplication.run(CourseApiApp.class, args);
}
}
42 changes: 42 additions & 0 deletions src/main/java/io/huangbaixun/springbootstarter/Topic/Topic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.huangbaixun.springbootstarter.Topic;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Topic {

@Id
private String id;
private String name;
private String description;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Topic() {

}

public Topic(String id, String name, String description) {
super();
this.id = id;
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
Loading

0 comments on commit 5dd1760

Please sign in to comment.