Skip to content

Commit

Permalink
-Moved Game DAO to Hibernate
Browse files Browse the repository at this point in the history
-Fixed News DAO
  • Loading branch information
ghandhikus committed Mar 28, 2016
1 parent a619ffc commit a61d756
Show file tree
Hide file tree
Showing 18 changed files with 523 additions and 160 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/clockwise/tworcy/controllers/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
import org.springframework.web.servlet.ModelAndView;

import com.clockwise.tworcy.model.account.AccountService;
import com.clockwise.tworcy.model.game.GameService;
import com.clockwise.tworcy.model.news.NewsService;

public @RequestMapping("/") @Controller class Index {

@Autowired AccountService accounts;
@Autowired GameService game;
@Autowired NewsService news;

public @RequestMapping("/") ModelAndView home(HttpServletRequest request, HttpServletResponse response, HttpSession session) {

ModelAndView ret = new ModelAndView("core");
ret.addObject("account", accounts.getLogged());
ret.addObject("news", news.getRecentNews(10, 0));
ret.addObject("newsList", news.getRecentNews(1, 0));
ret.addObject("gameList", game.getRecentGames(1, 0));
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/** Catches table of AccountData */
static {
accountDataTable = AccountData.class.getAnnotation(Table.class).name();
accountDataTable = AccountData.class.getDeclaredAnnotation(Table.class).name();
getStatement = "from "+accountDataTable;
getByUsernameStatement = getStatement + " where username=:username";
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/clockwise/tworcy/model/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
*
*/
public class Game {
private Integer gameId;
private Integer authorId;
private int gameId;
private int authorId;
private List<String> media;
private String title;
private String description;
private DateTime dateAdded;
private DateTime dateUpdated;

public Integer getGameId() {
public int getGameId() {
return gameId;
}

public Integer getAuthorId() {
public int getAuthorId() {
return authorId;
}

Expand All @@ -47,11 +47,11 @@ public DateTime getDateUpdated() {
}


void setGameId(Integer gameId) {
void setGameId(int gameId) {
this.gameId = gameId;
}

void setAuthorId(Integer authorId) {
void setAuthorId(int authorId) {
this.authorId = authorId;
}

Expand All @@ -74,4 +74,14 @@ void setDateAdded(DateTime dateAdded) {
void setDateUpdated(DateTime dateUpdated) {
this.dateUpdated = dateUpdated;
}

public void setDefault() {
gameId = 0;
authorId = 0;
media = null;
title = null;
description = null;
dateAdded = null;
dateUpdated = null;
}
}
123 changes: 123 additions & 0 deletions src/main/java/com/clockwise/tworcy/model/game/GameArchiveData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.clockwise.tworcy.model.game;

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.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
* Defines Game added by users of the page.
* @author Daniel
*
*/
@Entity
@Table(name = "GameArchiveData")
public class GameArchiveData {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private int id;

@Column(name = "gameId", nullable = false)
private int gameId;

@Column(name = "authorId", nullable = false)
private int authorId;

@Column(name = "media", nullable = true)
private String media;

@Column(name = "title", nullable = false)
private String title;

@Column(name = "description", nullable = false)
private String description;

@Column(name = "dateAdded", nullable = false)
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime dateAdded;

@Column(name = "dateUpdated", nullable = true)
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime dateUpdated;

public int getId() {
return id;
}
public int getGameId() {
return gameId;
}

public int getAuthorId() {
return authorId;
}

public String getMedia() {
return media;
}

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public DateTime getDateAdded() {
return dateAdded;
}

public DateTime getDateUpdated() {
return dateUpdated;
}


void setId(int id) {
this.id = id;
}

void setGameId(int gameId) {
this.gameId = gameId;
}

void setAuthorId(int authorId) {
this.authorId = authorId;
}

public void setMedia(String media) {
this.media = media;
}

public void setTitle(String title) {
this.title = title;
}

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

void setDateAdded(DateTime dateAdded) {
this.dateAdded = dateAdded;
}

void setDateUpdated(DateTime dateUpdated) {
this.dateUpdated = dateUpdated;
}

public void setDefault() {
gameId = 0;
authorId = 0;
media = null;
title = null;
description = null;
dateAdded = null;
dateUpdated = null;
}
}
78 changes: 78 additions & 0 deletions src/main/java/com/clockwise/tworcy/model/game/GameConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.clockwise.tworcy.model.game;

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

import com.clockwise.tworcy.util.JSONUtils;

@Service class GameConverter {

private @Autowired JSONUtils json;
GameData toData(Game game) {
GameData data = new GameData();
data.setGameId(game.getGameId());
data.setAuthorId(game.getAuthorId());
data.setMedia(json.stringArrayToJSON(game.getMedia()));
data.setTitle(game.getTitle());
data.setDescription(game.getDescription());
data.setDateAdded(game.getDateAdded());
data.setDateUpdated(game.getDateUpdated());
return data;
}
GameData toData(Game game, GameData data) {
data.setGameId(game.getGameId());
data.setAuthorId(game.getAuthorId());
data.setMedia(json.stringArrayToJSON(game.getMedia()));
data.setTitle(game.getTitle());
data.setDescription(game.getDescription());
data.setDateAdded(game.getDateAdded());
data.setDateUpdated(game.getDateUpdated());
return data;
}
GameData toData(GameArchiveData archive) {
GameData data = new GameData();
data.setGameId(archive.getGameId());
data.setAuthorId(archive.getAuthorId());
data.setMedia(archive.getMedia());
data.setTitle(archive.getTitle());
data.setDescription(archive.getDescription());
data.setDateAdded(archive.getDateAdded());
data.setDateUpdated(archive.getDateUpdated());
return data;
}

Game toGame(GameData data) {
Game game = new Game();
game.setGameId(data.getGameId());
game.setAuthorId(data.getAuthorId());
game.setMedia(json.stringListFromJSON(data.getMedia()));
game.setTitle(data.getTitle());
game.setDescription(data.getDescription());
game.setDateAdded(data.getDateAdded());
game.setDateUpdated(data.getDateUpdated());
return game;
}
Game toGame(GameData data, Game game) {
game.setGameId(data.getGameId());
game.setAuthorId(data.getAuthorId());
game.setMedia(json.stringListFromJSON(data.getMedia()));
game.setTitle(data.getTitle());
game.setDescription(data.getDescription());
game.setDateAdded(data.getDateAdded());
game.setDateUpdated(data.getDateUpdated());
return game;
}

GameArchiveData toArchive(GameData data) {
GameArchiveData archive = new GameArchiveData();
archive.setGameId(data.getGameId());
archive.setAuthorId(data.getAuthorId());
archive.setMedia(data.getMedia());
archive.setTitle(data.getTitle());
archive.setDescription(data.getDescription());
archive.setDateAdded(data.getDateAdded());
archive.setDateUpdated(data.getDateUpdated());

return archive;
}
}
Loading

0 comments on commit a61d756

Please sign in to comment.