Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Task1 dev #41

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions mgl-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
<scope>provided</scope>
</dependency>

<!-- Spring core & mvc TODO Maven Learning: Look at the Dependency Hierarchy and see what dependencies are being duplicated (spring-context or spring-webmvc?) -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -82,12 +76,12 @@
</dependency>


<!-- Logging TODO: upgrade logging to use log4j-slf4j-impl -->

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>3.0.0-alpha1</version>
<scope>test</scope>
</dependency>

<!-- JSR-330 for @Inject -->
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<List<Game>> fetchAllGames() {
return new ResponseEntity<List<Game>>(gameService.retrieveAllGames(), HttpStatus.OK);
}


@RequestMapping(value = "/game", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> createGame(@RequestBody Game game) {
gameService.saveGame(game);
return new ResponseEntity<Void>(HttpStatus.CREATED);
}
}
Loading