Browse Source

Removed smells.

Thomas Flucke 9 năm trước cách đây
mục cha
commit
45f26bfba9

+ 3 - 5
server/app/controllers/EventsController.java

@@ -6,8 +6,6 @@ import play.mvc.*;
 import play.libs.Json;
 
 import java.util.List;
-import java.util.LinkedList;
-import java.util.Date;
 
 import models.Event;
 
@@ -21,7 +19,7 @@ public class EventsController extends Controller {
     public Result get()
     {
 		List<Event> res = JPA.em().createQuery("SELECT e from Event e", Event.class).getResultList();
-		if (res == null || res.size() == 0)
+		if (res == null || res.isEmpty())
 		{
 			return notFound(Json.toJson("No Events"));
 		}
@@ -32,7 +30,7 @@ public class EventsController extends Controller {
     public Result create()
     {
     	Event e = Json.fromJson(request().body().asJson(), Event.class);
-    	e.eventId = 0;
+    	e.setEventId(0);
 		JPA.em().persist(e);
 		return created(Json.toJson(e));
     }
@@ -46,7 +44,7 @@ public class EventsController extends Controller {
     	{
     		return notFound("No event with id "+id);
     	}
-    	e.eventId = id;
+    	e.setEventId(id);
 		JPA.em().merge(e);
 		return ok(Json.toJson(e));
     }

+ 87 - 11
server/app/models/Event.java

@@ -9,15 +9,91 @@ import javax.persistence.GenerationType;
 @Entity
 public class Event
 {
-	@Id
-	@GeneratedValue(strategy=GenerationType.IDENTITY)
-    public long eventId;
-    public long userId;
-    public String name;
-    public Date time;
-    public String place;
-    public String foodType;
-    public String description;
-    public double lat;
-    public double lng;
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    private long eventId;
+    private long userId;
+    private Date time;
+    private String name;
+    private String place;
+    private String foodType;
+    private String description;
+    private double lat;
+    private double lng;
+
+    public void setEventId(long id)
+    {
+    	eventId = id;
+    }
+
+    public long getEventId()
+    {
+    	return eventId;
+    }
+
+    public void setUserId(long id)
+    {
+    	userId = id;
+    }
+
+    public long getUserId()
+    {
+    	return userId;
+    }
+
+	public Date getTime() {
+		return time;
+	}
+
+	public void setTime(Date time) {
+		this.time = time;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPlace() {
+		return place;
+	}
+
+	public void setPlace(String place) {
+		this.place = place;
+	}
+
+	public String getFoodType() {
+		return foodType;
+	}
+
+	public void setFoodType(String foodType) {
+		this.foodType = foodType;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public double getLat() {
+		return lat;
+	}
+
+	public void setLat(double lat) {
+		this.lat = lat;
+	}
+
+	public double getLng() {
+		return lng;
+	}
+
+	public void setLng(double lng) {
+		this.lng = lng;
+	}
 }

+ 1 - 4
server/build.sbt

@@ -6,16 +6,13 @@ lazy val root = (project in file(".")).enablePlugins(PlayJava)
 
 scalaVersion := "2.11.11"
 
-val jUnitVersion = "4.11" // replace appropriately
-
 libraryDependencies += javaJdbc
 libraryDependencies += cache
 libraryDependencies += javaWs
 
 libraryDependencies ++= Seq(
   javaJpa,
-  "org.hibernate" % "hibernate-entitymanager" % "5.1.0.Final", // replace by your jpa implementation
-  "junit" % "junit" % jUnitVersion % Test
+  "org.hibernate" % "hibernate-entitymanager" % "5.1.0.Final" // replace by your jpa implementation
 )
 
 PlayKeys.externalizeResources := false

BIN
server/public/images/favicon.png


+ 0 - 3
server/public/javascripts/hello.js

@@ -1,3 +0,0 @@
-if (window.console) {
-  console.log("Welcome to your Play application's JavaScript!");
-}

+ 0 - 0
server/public/stylesheets/main.css


+ 12 - 10
server/test/test/EventControllerTester.java

@@ -26,17 +26,19 @@ public class EventControllerTester extends WithApplication {
 	{ 
        Helpers.running(Helpers.fakeApplication(Helpers.inMemoryDatabase()), () -> {
     	    RequestBuilder rb = Helpers.fakeRequest("PUT", "/events");
-			String name = "Free Pizza Knight", desc = "Board games and free pizza";
-			float lat = 7f, lng = 0.3f;
-			Event e = new Event();
-			e.name = name;
-			e.lat = lat;
-			e.lng = lng;
-			e.description = desc;
+	    String name = "Free Pizza Knight";
+	    String desc = "Board games and free pizza";
+	    float lat = 7f;
+	    float lng = 0.3f;
+	    Event e = new Event();
+	    e.setName(name);
+	    e.setLat(lat);
+	    e.setLng(lng);
+	    e.setDescription(desc);
     	    rb.bodyJson(Json.toJson(e));
-    	   	Result res = Helpers.route(rb);
-			assertEquals(201, res.status());
-		});
+	    Result res = Helpers.route(rb);
+	    assertEquals(201, res.status());
+	   });
 	}
 
 }

+ 29 - 25
server/test/test/EventTester.java

@@ -13,35 +13,39 @@ public class EventTester {
 	@Test
 	public void testEventSerialization()
 	{
-		String name = "Free Pizza Knight", desc = "Board games and free pizza";
-		float lat = 7f, lng = 0.3f;
-		Event e = new Event();
-		e.name = name;
-		e.lat = 7;
-		e.lng = .3;
-		e.description = desc;
-		JsonNode jn = Json.toJson(e);
-		assertEquals(lat, jn.get("lat").floatValue(), 0.00001);
-		assertEquals(lng, jn.get("lng").floatValue(), 0.00001);
-		assertEquals(name, jn.get("name").textValue());
-		assertEquals(desc, jn.get("description").textValue());
+	    String name = "Free Pizza Knight";
+	    String desc = "Board games and free pizza";
+	    float lat = 7f;
+	    float lng = 0.3f;
+	    Event e = new Event();
+	    e.setName(name);
+	    e.setLat(7);
+	    e.setLng(.3);
+	    e.setDescription(desc);
+	    JsonNode jn = Json.toJson(e);
+	    assertEquals(lat, jn.get("lat").floatValue(), 0.00001);
+	    assertEquals(lng, jn.get("lng").floatValue(), 0.00001);
+	    assertEquals(name, jn.get("name").textValue());
+	    assertEquals(desc, jn.get("description").textValue());
 	}
 	
 	@Test
 	public void testEventDeserialization()
 	{
-		String name = "Free Pizza Knight", desc = "Board games and free pizza";
-		float lat = 7f, lng = 0.3f;
-		Event e = new Event();
-		e.name = name;
-		e.lat = 7;
-		e.lng = .3;
-		e.description = desc;
-		JsonNode jn = Json.toJson(e);
-		Event e2 = Json.fromJson(jn, Event.class);
-		assertEquals(lat, e2.lat, 0.00001);
-		assertEquals(lng, e2.lng, 0.00001);
-		assertEquals(name, e2.name);
-		assertEquals(desc, e2.description);
+	    String name = "Free Pizza Knight";
+	    String desc = "Board games and free pizza";
+	    float lat = 7f;
+	    float lng = 0.3f;
+	    Event e = new Event();
+	    e.setName(name);
+	    e.setLat(7);
+	    e.setLng(.3);
+	    e.setDescription(desc);
+	    JsonNode jn = Json.toJson(e);
+	    Event e2 = Json.fromJson(jn, Event.class);
+	    assertEquals(lat, e2.getLat(), 0.00001);
+	    assertEquals(lng, e2.getLng(), 0.00001);
+	    assertEquals(name, e2.getName());
+	    assertEquals(desc, e2.getDescription());
 	}
 }