From 5a6b750a1ba8e03961baf54c046aa122a12673d7 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Wed, 29 Jul 2020 01:41:03 +0900 Subject: [PATCH] Implement basic endpoints and functions --- .../java/com/example/demo/Controller.java | 224 ------------------ .../java/com/example/demo/DataRepository.java | 11 - .../com/example/demo/DemoApplication.java | 25 -- src/main/java/com/example/demo/Movie.java | 63 ----- .../java/com/example/demo/MovieRequest.java | 23 -- src/main/java/sig/family/CorsFilter.java | 31 +++ src/main/java/sig/family/Endpoints.java | 172 ++++++++++++++ .../demo/Data.java => sig/family/Family.java} | 24 +- src/main/java/sig/family/FamilyApp.java | 16 ++ src/main/java/sig/family/FamilyMember.java | 56 +++++ .../sig/family/FamilyMemberRepository.java | 6 + .../java/sig/family/FamilyRelationship.java | 57 +++++ .../family/FamilyRelationshipRepository.java | 10 + .../java/sig/family/FamilyRepository.java | 6 + src/main/java/sig/family/KnownLocation.java | 72 ++++++ .../sig/family/KnownLocationRepository.java | 7 + src/main/java/sig/family/Location.java | 73 ++++++ .../java/sig/family/LocationRepository.java | 7 + src/main/resources/application.properties | 2 +- 19 files changed, 526 insertions(+), 359 deletions(-) delete mode 100644 src/main/java/com/example/demo/Controller.java delete mode 100644 src/main/java/com/example/demo/DataRepository.java delete mode 100644 src/main/java/com/example/demo/DemoApplication.java delete mode 100644 src/main/java/com/example/demo/Movie.java delete mode 100644 src/main/java/com/example/demo/MovieRequest.java create mode 100644 src/main/java/sig/family/CorsFilter.java create mode 100644 src/main/java/sig/family/Endpoints.java rename src/main/java/{com/example/demo/Data.java => sig/family/Family.java} (71%) create mode 100644 src/main/java/sig/family/FamilyApp.java create mode 100644 src/main/java/sig/family/FamilyMember.java create mode 100644 src/main/java/sig/family/FamilyMemberRepository.java create mode 100644 src/main/java/sig/family/FamilyRelationship.java create mode 100644 src/main/java/sig/family/FamilyRelationshipRepository.java create mode 100644 src/main/java/sig/family/FamilyRepository.java create mode 100644 src/main/java/sig/family/KnownLocation.java create mode 100644 src/main/java/sig/family/KnownLocationRepository.java create mode 100644 src/main/java/sig/family/Location.java create mode 100644 src/main/java/sig/family/LocationRepository.java diff --git a/src/main/java/com/example/demo/Controller.java b/src/main/java/com/example/demo/Controller.java deleted file mode 100644 index cea7289..0000000 --- a/src/main/java/com/example/demo/Controller.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.example.demo; - -import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.ConnectException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import javax.imageio.ImageIO; -import javax.websocket.server.PathParam; - -@Service -@RestController -public class Controller { - - public static DataRepository database; - RestTemplate connection = new RestTemplate(); - - public Controller(DataRepository database) { - this.database=database; - } - - @GetMapping("/movies") - public List _8(@RequestParam("q") String q) { - System.out.println(connection.getForObject("http://www.omdbapi.com/?apikey={key}&s={title}", String.class, "6ba5969a",q)); - MovieRequest mr = connection.getForObject("http://www.omdbapi.com/?apikey={key}&s={title}", MovieRequest.class, "6ba5969a",q); - return mr.movies; - } - - @GetMapping("") - public Iterable _1(){ - return database.findAll(); - } - @PostMapping("") - public Data _2(@RequestBody Data data){ - return database.save(data); - } - @GetMapping("/data/{id}") - public Data _3(@PathVariable Long id) { - return database.findById(id).orElse(null); - } - @PutMapping("/data/{id}") - public Object _5(@PathVariable Long id,@RequestBody Data data) { - if (database.existsById(id)) { - return database.save(data); - } else { - return "ID "+id+" does not exist!"; - } - } - @PatchMapping("/data/{id}") - public Object _6(@PathVariable Long id,@RequestBody Data data) { - if (database.existsById(id)) { - return database.save(data); - } else { - return "ID "+id+" does not exist!"; - } - } - @GetMapping("/lessons/find/{name}") - public Data _7(@PathVariable String name) { - return database.findByName(name); - } - @GetMapping("/lessons/between") - public List _8(@DateTimeFormat(pattern = "MM-dd-yyyy")@RequestParam("date1") Date date1, - @DateTimeFormat(pattern = "MM-dd-yyyy")@RequestParam("date2") Date date2) { - return database.submittedOnBetween(date1, date2); - } - @DeleteMapping("/data/{id}") - public String _4(@PathVariable Long id) { - if (database.existsById(id)) { - database.deleteById(id); - return "Removed ID "+id+" from database."; - } else { - return "ID "+id+" does not exist!"; - } - } - - public static void downloadFileFromUrl(String url, String file) throws IOException{ - File filer = new File(file); - filer.createNewFile(); - - URL website = new URL(url); - HttpURLConnection connection = (HttpURLConnection) website.openConnection(); - /*for (String s : connection.getHeaderFields().keySet()) { - System.out.println(s+": "+connection.getHeaderFields().get(s)); - }*/ - connection.setRequestMethod("GET"); - //connection.setRequestProperty("Content-Type", "application/json"); - try { - ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream()); - FileOutputStream fos = new FileOutputStream(file); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - } catch (ConnectException e) { - System.out.println("Failed to connect, moving on..."); - } - } - - public double CalculateArea(double width,double height) { - return width*height; - } - - public double CalculateArea(double radius) { - return Math.PI*Math.pow(radius, 2); - } - - @PostMapping("/math/area") - public String areaDisplay( - @RequestParam Map map) { - if (map.containsKey("type")) { - if (map.get("type").equalsIgnoreCase("circle")) { - if (map.containsKey("radius")) { - return new StringBuilder("Area of a circle with a radius of ") - .append(map.get("radius")) - .append(" is "+CalculateArea(Double.parseDouble(map.get("radius")))) - .toString(); - } - }else if(map.get("type").equalsIgnoreCase("rectangle")) { - if (map.containsKey("width") && map.containsKey("height")) { - return new StringBuilder("Area of a ") - .append(map.get("width")).append("x") - .append(map.get("height")) - .append(" rectangle is "+CalculateArea(Double.parseDouble(map.get("width")),Double.parseDouble(map.get("height")))) - .toString(); - } - } - } - return "Invalid"; - } - - @GetMapping("/math/volume/{l}/{w}/{h}") - public String volumeDisplay( - @PathVariable(value="l") String length, - @PathVariable(value="w") String width, - @PathVariable(value="h") String height) { - return new StringBuilder("The volume of a ") - .append(length).append("x") - .append(width).append("x") - .append(height) - .append(" rectangle is ") - .append(Integer.parseInt(length)*Integer.parseInt(width)*Integer.parseInt(height)) - .toString(); - } - - @GetMapping("/math/calculate") - public String piDisplay(@RequestParam(value="operation",required=false) String operation, - @RequestParam(value="x") String x, - @RequestParam(value="y") String y) { - int val1=Integer.parseInt(x); - int val2=Integer.parseInt(y); - switch (operation) { - case "subtract":{ - return Integer.toString(val1-val2); - } - case "multiply":{ - return Integer.toString(val1*val2); - } - case "divide":{ - return Integer.toString(val1/val2); - } - default:{ - return Integer.toString(val1+val2); - } - } - } - - @GetMapping("/time") - public void updateTime( - @DateTimeFormat(pattern="MM-dd-yyyy HH:mm:ss") - @RequestParam("startDate") Date date1, - @DateTimeFormat(pattern="MM-dd-yyyy HH:mm:ss") - @RequestParam("endDate") Date date2 - ) { - System.out.println(date1+"/"+date2); - } - - @PostMapping("/math/sum") - public String sumDisplay(@RequestParam Map keys) { - int sum = 0; - for (String i : keys.keySet()) { - sum += Integer.parseInt(keys.get(i)); - } - return Integer.toString(sum); - } - - @GetMapping("/math/pi") - public String piDisplay() { - return Double.toString(Math.PI); - } - - @GetMapping("/image") - public HashMap helloWorld(@RequestParam("url") String url){ - try { - downloadFileFromUrl("http://pbs.twimg.com/media/EdKE8xzVcCEf1qd.jpg","temp"); - BufferedImage img = ImageIO.read(new File("temp")); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } -} \ No newline at end of file diff --git a/src/main/java/com/example/demo/DataRepository.java b/src/main/java/com/example/demo/DataRepository.java deleted file mode 100644 index b77f5de..0000000 --- a/src/main/java/com/example/demo/DataRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.demo; - -import java.util.Date; -import java.util.List; - -import org.springframework.data.repository.CrudRepository; - -public interface DataRepository extends CrudRepository{ - Data findByName(String name); - List submittedOnBetween(Date date1,Date date2); -} diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java deleted file mode 100644 index 81191b4..0000000 --- a/src/main/java/com/example/demo/DemoApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.demo; - -import java.util.Calendar; -import java.util.Date; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DemoApplication { - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - Date date1 = new Date(); - Date date2 = (Date)date1.clone(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date2); - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - System.out.println(); - - } - -} diff --git a/src/main/java/com/example/demo/Movie.java b/src/main/java/com/example/demo/Movie.java deleted file mode 100644 index 46a3a81..0000000 --- a/src/main/java/com/example/demo/Movie.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.example.demo; - -import org.springframework.web.bind.annotation.RequestMapping; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@RequestMapping -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Movie { - String title; - String imdbId; - String poster; - int year; - - @JsonCreator - Movie( - @JsonProperty("Title") String title, - @JsonProperty("imdbID") String imdbId, - @JsonProperty("Poster") String poster, - @JsonProperty("Year") int year) { - this.title=title; - this.imdbId=imdbId; - this.poster=poster; - this.year=year; - } - - @JsonProperty("title") - public String getTitle() { - return title; - } - @JsonProperty("title") - public void setTitle(String title) { - this.title = title; - } - @JsonProperty("imdbId") - public String getImdbId() { - return imdbId; - } - @JsonProperty("imdbId") - public void setImdbId(String imdbId) { - this.imdbId = imdbId; - } - @JsonProperty("poster") - public String getPoster() { - return poster; - } - @JsonProperty("poster") - public void setPoster(String poster) { - this.poster = poster; - } - @JsonProperty("year") - public int getYear() { - return year; - } - @JsonProperty("year") - public void setYear(int year) { - this.year = year; - } - - -} diff --git a/src/main/java/com/example/demo/MovieRequest.java b/src/main/java/com/example/demo/MovieRequest.java deleted file mode 100644 index f7732ad..0000000 --- a/src/main/java/com/example/demo/MovieRequest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.demo; - -import java.util.List; - -import org.springframework.web.bind.annotation.RequestMapping; - -import com.fasterxml.jackson.annotation.JsonProperty; - -@RequestMapping -public class MovieRequest { - List movies; - - @JsonProperty("Search") - public List getMovies() { - return movies; - } - - @JsonProperty("Search") - public void setMovies(List movies) { - this.movies = movies; - } - -} diff --git a/src/main/java/sig/family/CorsFilter.java b/src/main/java/sig/family/CorsFilter.java new file mode 100644 index 0000000..f6d3328 --- /dev/null +++ b/src/main/java/sig/family/CorsFilter.java @@ -0,0 +1,31 @@ +package sig.family; + +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class CorsFilter extends OncePerRequestFilter { + @Override + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, + + final FilterChain filterChain) +throws +ServletException, IOException { + response.addHeader("Access-Control-Allow-Origin", "*"); + response.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, HEAD"); + response.addHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); + response.addHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials"); + response.addHeader("Access-Control-Allow-Credentials", "true"); + response.addIntHeader("Access-Control-Max-Age", 10); + filterChain.doFilter(request, response); + } +} \ No newline at end of file diff --git a/src/main/java/sig/family/Endpoints.java b/src/main/java/sig/family/Endpoints.java new file mode 100644 index 0000000..3676324 --- /dev/null +++ b/src/main/java/sig/family/Endpoints.java @@ -0,0 +1,172 @@ +package sig.family; + +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.ConnectException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import javax.imageio.ImageIO; +import javax.websocket.server.PathParam; + +@Service +@RestController +public class Endpoints { + + FamilyRepository families; + FamilyMemberRepository members; + FamilyRelationshipRepository relationships; + LocationRepository locations; + KnownLocationRepository knownlocations; + RestTemplate connection = new RestTemplate(); + + public Endpoints(FamilyRepository families, + FamilyMemberRepository members, + FamilyRelationshipRepository relationships, + LocationRepository locations, + KnownLocationRepository knownlocations) { + this.families=families; + this.members=members; + this.relationships=relationships; + this.locations=locations; + this.knownlocations=knownlocations; + } + + @GetMapping("/family") + public Iterable _1() { + return families.findAll(); + } + + @GetMapping("/family/{id}") + public Optional _2(@PathVariable Long id) { + return families.findById(id); + } + + @PostMapping("/family") + /** + * @RequestBody requires: + * name - Name of new family. + * @return + */ + public Family _3(@RequestBody Map body) { + if (body.containsKey("name")) { + return families.save(new Family(body.get("name"))); + } + return null; + } + + @PostMapping("/member/create") + /** + * @RequestBody requires: + * firstName - First Name of family member. + * lastName - Last Name of family member. + * mobileId - ID of mobile device. + * @return + */ + public FamilyMember _4( + @RequestBody Map body) { + if (body.containsKey("firstName")&&body.containsKey("lastName")&&body.containsKey("mobileId")) { + return members.save(new FamilyMember(body.get("firstName"),body.get("lastName"),Long.parseLong(body.get("mobileId")))); + } + return null; + } + + @PostMapping("/relationship/{familyid}/{memberid}/{relationship}") + public FamilyRelationship _5( + @PathVariable Long familyid, + @PathVariable Long memberid, + @PathVariable String relationship) { + if (!families.existsById(familyid)||!members.existsById(memberid)) {return null;} + List fr = relationships.findByMemberId(memberid); + FamilyRelationship relation = null; + if (fr.size()>0) { + relation = fr.get(0); + relation.setFamilyId(familyid); + relation.setRelationship(relationship); + } else { + relation = new FamilyRelationship(familyid,memberid,relationship); + } + return relationships.save(relation); + } + + @DeleteMapping("/relationship/{familyid}/{memberid}") + public FamilyRelationship _6( + @PathVariable Long familyid, + @PathVariable Long memberid) { + List r = relationships.findByFamilyIdAndMemberId(familyid, memberid); + if (r.size()>0) { + FamilyRelationship f = r.get(0); + relationships.delete(f); + return f; + } + return null; + } + + @PostMapping("/location") + /** + * @RequestBody requires: + * member - The member posting this location. + * x - The X coordinate of the location (latitude). + * y - The Y coordination of the location (longitude). + * @return + */ + public Location _7(@RequestBody Map body) { + if (body.containsKey("member")&&body.containsKey("x")&&body.containsKey("y")&&members.existsById(Long.parseLong(body.get("member")))) { + return locations.save(new Location(Double.parseDouble(body.get("x")),Double.parseDouble(body.get("y")),Long.parseLong(body.get("member")),new Date())); + } else { + return null; + } + } + + @PostMapping("/knownlocation") + /** + * @RequestBody requires: + * name - The name of the location. + * x - The X coordinate of the location (latitude). + * y - The Y coordination of the location (longitude). + * safe - True if safe, false if unsafe location. + * @return + */ + public KnownLocation _8(@RequestBody Map body) { + if (body.containsKey("name")&&body.containsKey("x")&&body.containsKey("y")&&body.containsKey("safe")) { + return knownlocations.save(new KnownLocation(Double.parseDouble(body.get("x")),Double.parseDouble(body.get("y")),body.get("name"),Boolean.parseBoolean(body.get("safe")))); + } else { + return null; + } + } + + @DeleteMapping("/knownlocation/{id}") + public KnownLocation _9(@PathVariable Long id) { + if (knownlocations.existsById(id)) { + KnownLocation k = knownlocations.findById(id).get(); + knownlocations.deleteById(id); + return k; + } else { + return null; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/Data.java b/src/main/java/sig/family/Family.java similarity index 71% rename from src/main/java/com/example/demo/Data.java rename to src/main/java/sig/family/Family.java index 818dd80..c6bcc23 100644 --- a/src/main/java/com/example/demo/Data.java +++ b/src/main/java/sig/family/Family.java @@ -1,4 +1,4 @@ -package com.example.demo; +package sig.family; import java.util.Date; @@ -15,34 +15,34 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; @Entity -@Table(name="data") +@Table(name="family") @RequestMapping @JsonInclude(JsonInclude.Include.NON_NULL) -public class Data { +public class Family { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id; String name; - @Column(columnDefinition="date") - @JsonFormat(pattern="MM-dd-yyyy") - Date submittedOn; + + Family(String name) { + this.name=name; + } + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + public String getName() { return name; } + public void setName(String name) { this.name = name; } - public Date getSubmittedOn() { - return submittedOn; - } - public void setSubmittedOn(Date submittedOn) { - this.submittedOn = submittedOn; - } + } diff --git a/src/main/java/sig/family/FamilyApp.java b/src/main/java/sig/family/FamilyApp.java new file mode 100644 index 0000000..b9b4aee --- /dev/null +++ b/src/main/java/sig/family/FamilyApp.java @@ -0,0 +1,16 @@ +package sig.family; + +import java.util.Calendar; +import java.util.Date; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FamilyApp { + + public static void main(String[] args) { + SpringApplication.run(FamilyApp.class, args); + } + +} diff --git a/src/main/java/sig/family/FamilyMember.java b/src/main/java/sig/family/FamilyMember.java new file mode 100644 index 0000000..5835264 --- /dev/null +++ b/src/main/java/sig/family/FamilyMember.java @@ -0,0 +1,56 @@ +package sig.family; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@Entity +@Table(name="familymember") +@RequestMapping +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FamilyMember { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + Long id; + + String firstName,lastName; + + Long mobileDeviceId; + + public FamilyMember(String firstName, String lastName, Long mobileDeviceId) { + this.firstName = firstName; + this.lastName = lastName; + this.mobileDeviceId = mobileDeviceId; + } + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public Long getMobileDeviceId() { + return mobileDeviceId; + } + public void setMobileDeviceId(Long mobileDeviceId) { + this.mobileDeviceId = mobileDeviceId; + } +} diff --git a/src/main/java/sig/family/FamilyMemberRepository.java b/src/main/java/sig/family/FamilyMemberRepository.java new file mode 100644 index 0000000..d09e401 --- /dev/null +++ b/src/main/java/sig/family/FamilyMemberRepository.java @@ -0,0 +1,6 @@ +package sig.family; + +import org.springframework.data.repository.CrudRepository; + +public interface FamilyMemberRepository extends CrudRepository{ +} diff --git a/src/main/java/sig/family/FamilyRelationship.java b/src/main/java/sig/family/FamilyRelationship.java new file mode 100644 index 0000000..d4fa56a --- /dev/null +++ b/src/main/java/sig/family/FamilyRelationship.java @@ -0,0 +1,57 @@ +package sig.family; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; + +@Entity +@Table(name="familyrelationships") +@RequestMapping +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FamilyRelationship { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + Long id; + + public FamilyRelationship() {}; + + public FamilyRelationship(Long familyId, Long memberId, String relationship) { + this.familyId = familyId; + this.memberId = memberId; + this.relationship = relationship; + } + Long familyId; + Long memberId; + String relationship; + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public Long getFamilyId() { + return familyId; + } + public void setFamilyId(Long familyId) { + this.familyId = familyId; + } + public Long getMemberId() { + return memberId; + } + public void setMemberId(Long memberId) { + this.memberId = memberId; + } + public String getRelationship() { + return relationship; + } + public void setRelationship(String relationship) { + this.relationship = relationship; + } +} diff --git a/src/main/java/sig/family/FamilyRelationshipRepository.java b/src/main/java/sig/family/FamilyRelationshipRepository.java new file mode 100644 index 0000000..e8d0c61 --- /dev/null +++ b/src/main/java/sig/family/FamilyRelationshipRepository.java @@ -0,0 +1,10 @@ +package sig.family; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + +public interface FamilyRelationshipRepository extends CrudRepository{ + List findByMemberId(Long memberId); + List findByFamilyIdAndMemberId(Long familyId,Long memberId); +} diff --git a/src/main/java/sig/family/FamilyRepository.java b/src/main/java/sig/family/FamilyRepository.java new file mode 100644 index 0000000..8a1e145 --- /dev/null +++ b/src/main/java/sig/family/FamilyRepository.java @@ -0,0 +1,6 @@ +package sig.family; + +import org.springframework.data.repository.CrudRepository; + +public interface FamilyRepository extends CrudRepository{ +} diff --git a/src/main/java/sig/family/KnownLocation.java b/src/main/java/sig/family/KnownLocation.java new file mode 100644 index 0000000..66757c1 --- /dev/null +++ b/src/main/java/sig/family/KnownLocation.java @@ -0,0 +1,72 @@ +package sig.family; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; + +@Entity +@Table(name="knownlocations") +@RequestMapping +@JsonInclude(JsonInclude.Include.NON_NULL) +public class KnownLocation { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + Long id; + double x,y; + String name; + boolean isSafe; + + public KnownLocation() {} + + public KnownLocation(double x, double y, String name, boolean isSafe) { + this.x = x; + this.y = y; + this.name=name; + this.isSafe=isSafe; + } + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public double getX() { + return x; + } + public void setX(double x) { + this.x = x; + } + public double getY() { + return y; + } + public void setY(double y) { + this.y = y; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isSafe() { + return isSafe; + } + + public void setSafe(boolean isSafe) { + this.isSafe = isSafe; + } + +} diff --git a/src/main/java/sig/family/KnownLocationRepository.java b/src/main/java/sig/family/KnownLocationRepository.java new file mode 100644 index 0000000..237598d --- /dev/null +++ b/src/main/java/sig/family/KnownLocationRepository.java @@ -0,0 +1,7 @@ +package sig.family; + +import org.springframework.data.repository.CrudRepository; + +public interface KnownLocationRepository extends CrudRepository{ + +} diff --git a/src/main/java/sig/family/Location.java b/src/main/java/sig/family/Location.java new file mode 100644 index 0000000..90adb47 --- /dev/null +++ b/src/main/java/sig/family/Location.java @@ -0,0 +1,73 @@ +package sig.family; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; + +@Entity +@Table(name="locations") +@RequestMapping +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Location { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + Long id; + double x,y; + Long memberId; + + @Column(columnDefinition="datetime") + @JsonFormat(pattern="MM-dd-yyyy HH:mm:ss") + Date date; + + public Location() {} + + public Location(double x, double y, Long memberId, Date date) { + this.x = x; + this.y = y; + this.memberId = memberId; + this.date=date; + } + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public double getX() { + return x; + } + public void setX(double x) { + this.x = x; + } + public double getY() { + return y; + } + public void setY(double y) { + this.y = y; + } + public Long getMemberId() { + return memberId; + } + public void setMemberId(Long memberId) { + this.memberId = memberId; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + +} diff --git a/src/main/java/sig/family/LocationRepository.java b/src/main/java/sig/family/LocationRepository.java new file mode 100644 index 0000000..f284e46 --- /dev/null +++ b/src/main/java/sig/family/LocationRepository.java @@ -0,0 +1,7 @@ +package sig.family; + +import org.springframework.data.repository.CrudRepository; + +public interface LocationRepository extends CrudRepository{ + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a692ce4..f39a2c4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.datasource.url=jdbc:mysql://localhost/playground?serverTimezone=UTC +spring.datasource.url=jdbc:mysql://localhost/family?serverTimezone=UTC spring.datasource.username=sigonasr2 spring.datasource.password= spring.datasource.driver-class-name=com.mysql.jdbc.Driver