diff --git a/mgl-webapp/pom.xml b/mgl-webapp/pom.xml index 0f66cb1f..d33599c2 100644 --- a/mgl-webapp/pom.xml +++ b/mgl-webapp/pom.xml @@ -39,12 +39,6 @@ provided - - - org.springframework - spring-context - ${spring.version} - org.springframework @@ -82,12 +76,12 @@ - + - log4j - log4j - 1.2.14 - runtime + org.apache.logging.log4j + log4j-slf4j-impl + 3.0.0-alpha1 + test diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/controller/MGL_Task1_Controller.java b/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/controller/MGL_Task1_Controller.java deleted file mode 100644 index a6a21a57..00000000 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/controller/MGL_Task1_Controller.java +++ /dev/null @@ -1,83 +0,0 @@ -//TODO 1.0 package naming convention, improve package declaration -package com.organization.mvcproject.MGL_Task1.controller; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -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.servlet.ModelAndView; - -import com.organization.mvcproject.MGL_Task1.model.Game; -import com.organization.mvcproject.MGL_Task1.model.Review; -import com.organization.mvcproject.MGL_Task1.service.Game_Service; - -//TODO 1.0 follow java class naming, improve class name -@Controller -public class MGL_Task1_Controller { - - //TODO 1.0 variable naming convention, improve reference name - @Autowired - private Game_Service javaGameService; - - @RequestMapping(value = "/", method = RequestMethod.GET) - public String home() { - return "index"; - } - - @RequestMapping(value = "/review", method = RequestMethod.GET) - public ModelAndView review() { - /** - * TODO 1.0 Rename the jsp view, to "reviewCreatePage" because it matches the URL triggering a circular view path error. - * update games.jsp as well. - * SEE: https://www.baeldung.com/spring-circular-view-path-error - */ - return new ModelAndView("review", "command", new Review()); - } - - @RequestMapping(value = "/addReview", method = RequestMethod.POST) - public ModelAndView addReview(Review review, ModelMap model) { - if(review.getAuthor().equals("")) { - review.setAuthor("anonymous"); - } - /** - * TODO 1.0 Rename the jsp view, to "reviewDetailPage" because what is the view the "result" of? - * update games.jsp as well. - */ - return new ModelAndView("result", "submittedReview", review); - } - - - @RequestMapping(value = "/games", method = RequestMethod.GET) - public ModelAndView game() { - /** - * TODO 1.0 Rename the jsp view, to "gamesPage" because it matches the URL triggering a circular view path error. - * update games.jsp as well. - * SEE: https://www.baeldung.com/spring-circular-view-path-error - */ - return new ModelAndView("games", "command", new Game()); - } - - /** - * TODO 2.0 (Separation of concerns) consider moving all controller endpoints that return a ResponseEntity into a @RestController. - */ - - //TODO 1.0 RequestMapping URL should follow RESTful. - @RequestMapping(value = "/game/getAll", method = RequestMethod.GET) - public ResponseEntity> fetchAllGames() { - return new ResponseEntity>(javaGameService.retrieveAllGames(), HttpStatus.OK); - } - - //TODO 1.0 RequestMapping URL should follow RESTful convention - @RequestMapping(value = "/createGame", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity createGame(@RequestBody Game game) { - javaGameService.saveGame(game); - return new ResponseEntity(HttpStatus.CREATED); - } -} \ No newline at end of file diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Game.java b/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Game.java deleted file mode 100644 index ae9627d3..00000000 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Game.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.organization.mvcproject.MGL_Task1.model; - -import org.springframework.stereotype.Component; - -@Component -public class Game { - - /** - * TODO 1.0 java object member variable naming convention declared here are not object oriented, - * rename the variables, and their setter/getter methods to match convention. - */ - private Long game_id; - private String game_name; - private String game_genre; - - public Long getGame_id() { - return game_id; - } - - public void setGame_id(Long game_id) { - this.game_id = game_id; - } - - public String getGame_name() { - return game_name; - } - - public void setGame_name(String game_name) { - this.game_name = game_name; - } - - public String getGame_genre() { - return game_genre; - } - - public void setGame_genre(String game_genre) { - this.game_genre = game_genre; - } - -} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Review.java b/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Review.java deleted file mode 100644 index b0a66767..00000000 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Review.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.organization.mvcproject.MGL_Task1.model; - -public class Review { - - /** - * TODO 1.0 java object member variable naming convention, - * one member declared here is not object oriented refactor it - */ - private String reviewBody; - private String author; - private Integer rating; - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public Integer getRating() { - return rating; - } - - public void setRating(Integer rating) { - this.rating = rating; - } - - public String getReviewBody() { - return reviewBody; - } - - public void setReviewBody(String reviewBody) { - this.reviewBody = reviewBody; - } -} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service.java b/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service.java deleted file mode 100644 index 476d8861..00000000 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.organization.mvcproject.MGL_Task1.service; - -import java.util.List; - -import com.organization.mvcproject.MGL_Task1.model.Game; - -//TODO 1.0 follow java interface naming conventions, improve interface name -public interface Game_Service { - - List retrieveAllGames(); - - Game saveGame(Game game); - -} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_Impl.java b/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_Impl.java deleted file mode 100644 index 476a20b5..00000000 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_Impl.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.organization.mvcproject.MGL_Task1.service; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.stereotype.Service; - -import com.organization.mvcproject.MGL_Task1.model.Game; - -//TODO 1.0 follow java class naming, improve class name -//TODO 1.0 "javaGameService" service reference name is not necessary, remove it. -@Service("javaGameService") -public class Game_Service_Impl implements Game_Service { - - /** - * TODO 2.0 The class that interacts with persistent data is called a Data Access Object(DAO) - * or a Repository class. The private static list is mocking our persistance of games. - * - * Move this list, and methods operating on this list to an appropriately named package and class. - */ - - private static Long gameId = new Long(0); - private static Long companyId = new Long(0); - private static List games = new ArrayList(); - - static { - games = populateGames(); - } - - private static List populateGames() { - - Game game1 = new Game(); - game1.setGame_id(++gameId); - game1.setGame_genre("Sport"); - game1.setGame_name("Rocket League"); - - Game game2 = new Game(); - game2.setGame_id(++gameId); - game2.setGame_genre("Shooter"); - game2.setGame_name("Halo 3"); - - Game game3 = new Game(); - game3.setGame_id(++gameId); - game3.setGame_genre("MMORPG"); - game3.setGame_name("Runescape"); - - games.add(game1); - games.add(game2); - games.add(game3); - - return games; - } - - @Override - public List retrieveAllGames() { - return games; - } - - @Override - public Game saveGame(Game game) { - game.setGame_id(++gameId); - games.add(game); - return game; - } - - /** - * TODO 1.0 the static methods below are either not related to a Game Service, - * are confused with methods found in the model, or duplicates. - * Remove them. - * - */ - public static Long getGameId() { - return gameId; - } - - public static void setGameId(Long gameId) { - Game_Service_Impl.gameId = gameId; - } - - public static Long getCompanyId() { - return companyId; - } - - public static void setCompanyId(Long companyId) { - Game_Service_Impl.companyId = companyId; - } - - public static List getGames() { - return games; - } - - public static void setGames(ArrayList games) { - Game_Service_Impl.games = games; - } - -} \ No newline at end of file diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/controller/GamesController.java b/mgl-webapp/src/main/java/com/organization/mvcproject/controller/GamesController.java new file mode 100644 index 00000000..bbc40d2f --- /dev/null +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/controller/GamesController.java @@ -0,0 +1,75 @@ + +package com.organization.mvcproject.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +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.servlet.ModelAndView; + +import com.organization.mvcproject.model.Game; +import com.organization.mvcproject.model.Review; +import com.organization.mvcproject.service.GameService; + + +@Controller +public class GamesController { + + + @Autowired + private GameService gameService; + + @RequestMapping(value = "/", method = RequestMethod.GET) + public String home() { + return "index"; + } + + @RequestMapping(value = "/review", method = RequestMethod.GET) + public ModelAndView review() { + + return new ModelAndView("reviewCreatePage", "command", new Review()); + } + + @RequestMapping(value = "/addReview", method = RequestMethod.POST) + public ModelAndView addReview(Review review, ModelMap model) { + if(review.getAuthor().equals("")) { + review.setAuthor("anonymous"); + } + + + return new ModelAndView("reviewDetailPage", "submittedReview", review); + } + + + @RequestMapping(value = "/games", method = RequestMethod.GET) + public ModelAndView game() { + + return new ModelAndView("gamesPage", "command", new Game()); + } + + /** + * TODO 2.0 (Separation of concerns) consider moving all controller endpoints that return a ResponseEntity into a @RestController. + */ + + + @RequestMapping(value = "/game", method = RequestMethod.GET) + public ResponseEntity> fetchAllGames() { + return new ResponseEntity>(gameService.retrieveAllGames(), HttpStatus.OK); + } + + + @RequestMapping(value = "/game", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity createGame(@RequestBody Game game) { + gameService.saveGame(game); + return new ResponseEntity(HttpStatus.CREATED); + } +} \ No newline at end of file diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Company.java b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Company.java similarity index 67% rename from mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Company.java rename to mgl-webapp/src/main/java/com/organization/mvcproject/model/Company.java index 9178b8f4..9f6249ef 100644 --- a/mgl-webapp/src/main/java/com/organization/mvcproject/MGL_Task1/model/Company.java +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Company.java @@ -1,19 +1,17 @@ -package com.organization.mvcproject.MGL_Task1.model; +package com.organization.mvcproject.model; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Component; -//TODO 1.0 remove @Component annotation, it is not used -@Component public class Company { private Long id; private String name; - //TODO 1.0 this List doesn't need to be initialized at declaration. - private List gamesMade = new ArrayList(); + + private List gamesMade; public Long getId() { return id; diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/model/Game.java b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Game.java new file mode 100644 index 00000000..81a842c5 --- /dev/null +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Game.java @@ -0,0 +1,33 @@ +package com.organization.mvcproject.model; + +import org.springframework.stereotype.Component; + +@Component +public class Game { + + + private Long id; + private String name; + private String genre; + 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 String getGenre() { + return genre; + } + public void setGenre(String genre) { + this.genre = genre; + } + + + +} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/model/Review.java b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Review.java new file mode 100644 index 00000000..f86195b1 --- /dev/null +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/model/Review.java @@ -0,0 +1,33 @@ +package com.organization.mvcproject.model; + +public class Review { + + + private String body; + private String author; + private Integer rating; + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public Integer getRating() { + return rating; + } + + public void setRating(Integer rating) { + this.rating = rating; + } + + public String getBody() { + return body; + } + + public void Body(String Body) { + this.body = Body; + } +} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameService.java b/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameService.java new file mode 100644 index 00000000..28ef7183 --- /dev/null +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameService.java @@ -0,0 +1,14 @@ +package com.organization.mvcproject.service; + +import java.util.List; + +import com.organization.mvcproject.model.Game; + + +public interface GameService { + + List retrieveAllGames(); + + Game saveGame(Game game); + +} diff --git a/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameServiceImpl.java b/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameServiceImpl.java new file mode 100644 index 00000000..100b1ed0 --- /dev/null +++ b/mgl-webapp/src/main/java/com/organization/mvcproject/service/GameServiceImpl.java @@ -0,0 +1,67 @@ +package com.organization.mvcproject.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.organization.mvcproject.model.Game; + + +@Service +public class GameServiceImpl implements GameService { + + /** + * TODO 2.0 The class that interacts with persistent data is called a Data Access Object(DAO) + * or a Repository class. The private static list is mocking our persistance of games. + * + * Move this list, and methods operating on this list to an appropriately named package and class. + */ + + private static Long gameId = new Long(0); + private static Long companyId = new Long(0); + private static List games = new ArrayList(); + + static { + games = populateGames(); + } + + private static List populateGames() { + + Game game1 = new Game(); + game1.setId(++gameId); + game1.setGenre("Sport"); + game1.setName("Rocket League"); + + Game game2 = new Game(); + game2.setId(++gameId); + game2.setGenre("Shooter"); + game2.setName("Halo 3"); + + Game game3 = new Game(); + game3.setId(++gameId); + game3.setGenre("MMORPG"); + game3.setName("Runescape"); + + games.add(game1); + games.add(game2); + games.add(game3); + + return games; + } + + @Override + public List retrieveAllGames() { + return games; + } + + @Override + public Game saveGame(Game game) { + game.setId(++gameId); + games.add(game); + return game; + } + + + +} \ No newline at end of file diff --git a/mgl-webapp/src/main/webapp/WEB-INF/views/games.jsp b/mgl-webapp/src/main/webapp/WEB-INF/views/games.jsp deleted file mode 100644 index f61b79a6..00000000 --- a/mgl-webapp/src/main/webapp/WEB-INF/views/games.jsp +++ /dev/null @@ -1,98 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> -<%@ taglib tagdir="/WEB-INF/tags" prefix="mgl" %> - - - - - - - - - - - - - Mist Library Task 1-Games - - - - - - - - - - - - Game Registration Form - - - - - - Name* - - - - This is a required field - Minimum length required is 3 - This field is invalid - - - - - - - - - Game Genre - - - - - - - - - - - - - - - - - List of all current games - - - - - Game Name - Game Genre - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mgl-webapp/src/main/webapp/WEB-INF/views/gamesPage.jsp b/mgl-webapp/src/main/webapp/WEB-INF/views/gamesPage.jsp new file mode 100644 index 00000000..0779cb5e --- /dev/null +++ b/mgl-webapp/src/main/webapp/WEB-INF/views/gamesPage.jsp @@ -0,0 +1,118 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib tagdir="/WEB-INF/tags" prefix="mgl"%> + + + + + + + + + + + + +Mist Library Task 1-Games + + + + + + + + + + + + + Game Registration Form + + + + + + + Name* + + + + This is a + required field Minimum + length required is 3 This + field is invalid + + + + + + + + + Game + Genre + + + + + + + + + + + + + + + + + + List of all current games + + + + + + Game Name + Game Genre + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mgl-webapp/src/main/webapp/WEB-INF/views/review.jsp b/mgl-webapp/src/main/webapp/WEB-INF/views/reviewCreatePage.jsp similarity index 100% rename from mgl-webapp/src/main/webapp/WEB-INF/views/review.jsp rename to mgl-webapp/src/main/webapp/WEB-INF/views/reviewCreatePage.jsp diff --git a/mgl-webapp/src/main/webapp/WEB-INF/views/result.jsp b/mgl-webapp/src/main/webapp/WEB-INF/views/reviewDetailPage.jsp similarity index 100% rename from mgl-webapp/src/main/webapp/WEB-INF/views/result.jsp rename to mgl-webapp/src/main/webapp/WEB-INF/views/reviewDetailPage.jsp diff --git a/mgl-webapp/src/main/webapp/resources/static/js/controller/MGL_Task1.controller.js b/mgl-webapp/src/main/webapp/resources/static/js/MGL_Task1.controller.js similarity index 100% rename from mgl-webapp/src/main/webapp/resources/static/js/controller/MGL_Task1.controller.js rename to mgl-webapp/src/main/webapp/resources/static/js/MGL_Task1.controller.js diff --git a/mgl-webapp/src/main/webapp/resources/static/js/service/MGL_Task1.service.js b/mgl-webapp/src/main/webapp/resources/static/js/MGL_Task1.service.js similarity index 71% rename from mgl-webapp/src/main/webapp/resources/static/js/service/MGL_Task1.service.js rename to mgl-webapp/src/main/webapp/resources/static/js/MGL_Task1.service.js index 473eda28..9c907070 100644 --- a/mgl-webapp/src/main/webapp/resources/static/js/service/MGL_Task1.service.js +++ b/mgl-webapp/src/main/webapp/resources/static/js/MGL_Task1.service.js @@ -12,14 +12,14 @@ angular.module('MGL_Task1_app').factory('MGL_Task1_Service', ['$http', function( return factory; function fetchAllGames() { - return $http.get(REST_SERVICE_URI + 'getAll').then(function(response) { + return $http.get(REST_SERVICE_URI).then(function(response) { return response.data; } ); } function createGame(game) { - return $http.post(REST_SERVICE_URI + 'createGame', game).then(function(response) { + return $http.post(REST_SERVICE_URI, game).then(function(response) { return response.data; } ); diff --git a/mgl-webapp/src/test/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_ImplTest.java b/mgl-webapp/src/test/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_ImplTest.java index 4d073214..aba338cf 100644 --- a/mgl-webapp/src/test/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_ImplTest.java +++ b/mgl-webapp/src/test/java/com/organization/mvcproject/MGL_Task1/service/Game_Service_ImplTest.java @@ -25,8 +25,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; -import com.organization.mvcproject.MGL_Task1.model.Game; import com.organization.mvcproject.config.MvcConfiguration; +import com.organization.mvcproject.model.Game; +import com.organization.mvcproject.service.GameService; @RunWith(JUnitPlatform.class) @ExtendWith(SpringExtension.class) @@ -37,15 +38,15 @@ class Game_Service_ImplTest { @Autowired - private Game_Service gameServiceUnderTest; + private GameService gameServiceUnderTest; private static Game testGame = createGame(1); private static final String TEST_GENRE = "Test Genre"; private static Game createGame(Integer number) { Game game = new Game(); - game.setGame_name("Testing Game Name " + String.valueOf(number)); - game.setGame_genre(TEST_GENRE); + game.setName("Testing Game Name " + String.valueOf(number)); + game.setGenre(TEST_GENRE); return game; } @@ -56,10 +57,10 @@ private static Game createGame(Integer number) { void saveGameServiceSavesAndUpdatesGame() { if(gamesToRemoveAfterTest.isEmpty()) { Game game = gameServiceUnderTest.saveGame(testGame); - Assertions.assertNotNull(game.getGame_id()); + Assertions.assertNotNull(game.getId()); //updates - game.setGame_name("Testing Game Name Updated" ); + game.setName("Testing Game Name Updated" ); testGame = gameServiceUnderTest.saveGame(game); assertEquals(game, testGame); gamesToRemoveAfterTest.add(testGame);