aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorcirakg <ciraboxkg@gmail.com>2023-01-02 17:00:24 +0100
committercirakg <ciraboxkg@gmail.com>2023-01-02 17:00:24 +0100
commitcd694d64cf1a9be635df6b15168a5950644e5ce2 (patch)
tree11350c2857b71617c6a2de1e9adf95c4777c9c42 /src/main
parentfc569fa42d3dd1f8709103c7dae7e995597072ca (diff)
Omogucen prikaz istorije korisnika.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/database/Database.java25
-rw-r--r--src/main/java/models/History.java39
-rw-r--r--src/main/java/pokemon/IService.java2
-rw-r--r--src/main/java/pokemon/Service.java8
-rw-r--r--src/main/webapp/pages/history.jsp34
-rw-r--r--src/main/webapp/pages/userIndex.jsp5
6 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/database/Database.java b/src/main/java/database/Database.java
index f6e18b3..587dc0e 100644
--- a/src/main/java/database/Database.java
+++ b/src/main/java/database/Database.java
@@ -14,6 +14,7 @@ import java.util.List;
import models.Ability;
import models.AbilityType;
import models.GameStatus;
+import models.History;
import models.Monster;
import models.MonsterViewModel;
import models.User;
@@ -356,5 +357,29 @@ public class Database {
}
return ps.executeUpdate();
}
+ public ArrayList<History> getUserHistory(long id){
+ ArrayList<History> history=new ArrayList<>();
+ String sql="SELECT * FROM history where player=? ";
+ try {
+ PreparedStatement ps=conn.prepareStatement(sql);
+ ps.setLong(1, id);
+ ResultSet res=ps.executeQuery();
+ while(res.next()) {
+ History h=new History();
+ h.pokemon=getMonsterViewModel(res.getLong("pokemon"));
+ h.time=res.getDate("time");
+ h.result=res.getInt("result");
+ history.add(h);
+ }
+
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ return history;
+
+ }
}
diff --git a/src/main/java/models/History.java b/src/main/java/models/History.java
new file mode 100644
index 0000000..1ce47e1
--- /dev/null
+++ b/src/main/java/models/History.java
@@ -0,0 +1,39 @@
+package models;
+
+import java.io.Serializable;
+import java.sql.Date;
+
+public class History implements Serializable {
+
+ public MonsterViewModel pokemon;
+ public Date time;
+ public int result;
+
+
+ public History() {
+
+
+
+ }
+ public MonsterViewModel getPokemon() {
+ return pokemon;
+ }
+ public void setPokemon(MonsterViewModel pokemon) {
+ this.pokemon = pokemon;
+ }
+ public Date getTime() {
+ return time;
+ }
+ public void setTime(Date time) {
+ this.time = time;
+ }
+ public int getResult() {
+ return result;
+ }
+ public void setResult(int result) {
+ this.result = result;
+ }
+
+
+
+}
diff --git a/src/main/java/pokemon/IService.java b/src/main/java/pokemon/IService.java
index de4b6e5..016fcb9 100644
--- a/src/main/java/pokemon/IService.java
+++ b/src/main/java/pokemon/IService.java
@@ -5,6 +5,7 @@ import java.rmi.RemoteException;
import java.util.ArrayList;
import models.Ability;
+import models.History;
import models.Monster;
import models.MonsterViewModel;
import models.PokemonAddModel;
@@ -25,5 +26,6 @@ public interface IService extends Remote {
public void deleteMonster(long id)throws RemoteException;
public User getUserById(long id) throws RemoteException;
public int addHistory(Game game) throws Exception;
+ public ArrayList<History> getUserHistory(long id) throws RemoteException;
}
diff --git a/src/main/java/pokemon/Service.java b/src/main/java/pokemon/Service.java
index f9f76de..1d95c4b 100644
--- a/src/main/java/pokemon/Service.java
+++ b/src/main/java/pokemon/Service.java
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import database.Database;
import models.Ability;
+import models.History;
import models.Monster;
import models.MonsterViewModel;
import models.PokemonAddModel;
@@ -118,6 +119,13 @@ public class Service extends UnicastRemoteObject implements IService {
Database db=Database.getInstance();
return db.addHistory(game);
}
+
+ @Override
+ public ArrayList<History> getUserHistory(long id) throws RemoteException {
+ Database db=Database.getInstance();
+
+ return db.getUserHistory(id);
+ }
}
diff --git a/src/main/webapp/pages/history.jsp b/src/main/webapp/pages/history.jsp
new file mode 100644
index 0000000..7e36faf
--- /dev/null
+++ b/src/main/webapp/pages/history.jsp
@@ -0,0 +1,34 @@
+<%@page import="java.util.ArrayList"%>
+<%@page import="pokemon.IService"%>
+<%@page import="models.History"%>
+<%@page import="models.CONSTS"%>
+<%@page import="java.rmi.Naming"%>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="ISO-8859-1">
+</head>
+<body>
+<%
+ long userId=(long)session.getAttribute("id");
+ IService service=(IService)Naming.lookup(CONSTS.rmiUrl);
+ ArrayList<History> history=service.getUserHistory(userId);
+ request.setAttribute("history", history);
+
+
+%>
+<table>
+<c:forEach items="${history}" var="item">
+ <tr bgcolor="${item.result eq 1 ? 'LawnGreen': 'IndianRed'}">
+ <td><c:out value="${item.pokemon.name}"/></td>
+ <td><img style="height: 50px" src="data:image/*;base64, ${item.pokemon.base64Image}" /></td>
+ <td><c:out value="${item.time}"/></td>
+ <td><c:out value="${item.result eq 1 ? 'Victory': 'Defeat'}"/></td>
+ </tr>
+ </c:forEach>
+</table>
+</body>
+</html> \ No newline at end of file
diff --git a/src/main/webapp/pages/userIndex.jsp b/src/main/webapp/pages/userIndex.jsp
index b06d966..57e4a16 100644
--- a/src/main/webapp/pages/userIndex.jsp
+++ b/src/main/webapp/pages/userIndex.jsp
@@ -89,5 +89,10 @@ Trenutno izabran pokemon:
</c:forEach>
</table>
+<br><br><br>
+<h1>Istorija</h1>
+<jsp:include page="history.jsp"/>
+
+
</body>
</html> \ No newline at end of file