Skip to content

Commit

Permalink
Merge branch 'master' of github.com:plutec/MFF_implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
plutec committed Dec 22, 2011
2 parents 366bfb6 + 551460f commit cbfe730
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 204 deletions.
9 changes: 9 additions & 0 deletions MFF/src/java/MFF/Controller/RatingController.java
Expand Up @@ -21,6 +21,8 @@ public RatingController() {
public HashMap<String, Object> call(String action, HashMap parameters) {
if (action.equals("rate")) {
return this.rate(parameters);
} else if(action.equals("delete")) {
return this.delete(parameters);
} else if(action.equals("getBestRatedFilms")) {
return this.getBestRatedFilms(parameters);
}
Expand All @@ -34,6 +36,13 @@ protected HashMap<String, Object> rate(HashMap<String, Object> parameters) {
model.rate(u, f, rate);
return toRet;
}
protected HashMap<String, Object> delete(HashMap<String, Object> parameters) {
HashMap<String, Object> toRet=new HashMap<String, Object>();
Film f = new Film(Integer.parseInt((String)parameters.get("film")), "", 0);
User u = new User((String)parameters.get("sessionUserID"), "", false);
model.deleteRating(u, f);
return toRet;
}
protected HashMap<String, Object> getBestRatedFilms(HashMap<String, Object> parameters) {
HashMap<String, Object> toRet=new HashMap<String, Object>();
int max=10; //Máximo de películas a devolver
Expand Down
2 changes: 0 additions & 2 deletions MFF/src/java/MFF/Controller/UserController.java
Expand Up @@ -9,8 +9,6 @@
import MFF.Exceptions.NotLoginUser;
import MFF.Model.*;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand Down
30 changes: 15 additions & 15 deletions MFF/src/java/MFF/Model/DAO/DAOFilm.java
Expand Up @@ -57,21 +57,21 @@ public ArrayList<Film> search(String s) {
return null;
}
public void insert(Film f) {
try {
String sql = "INSERT INTO film(title, year) VALUES(?, ?);";
PreparedStatement query = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
query.setString(1, f.getTitle());
query.setInt(2, f.getYear());
query.executeUpdate();
ResultSet res=query.getGeneratedKeys();
int id = -1;
while(res.next())
id=res.getInt(1);
f.setId(id);
} catch (SQLException ex) {
Logger.getLogger(DAOFilm.class.getName()).log(Level.SEVERE, null, ex);
}
}
try {
String sql = "INSERT INTO film(title, year) VALUES(?, ?);";
PreparedStatement query = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
query.setString(1, f.getTitle());
query.setInt(2, f.getYear());
query.executeUpdate();
ResultSet res=query.getGeneratedKeys();
int id = -1;
while(res.next())
id=res.getInt(1);
f.setId(id);
} catch (SQLException ex) {
Logger.getLogger(DAOFilm.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void update(Film f) {
try {
String sql = "UPDATE film SET title = ?, year = ? WHERE id=?";
Expand Down
11 changes: 11 additions & 0 deletions MFF/src/java/MFF/Model/DAO/DAORating.java
Expand Up @@ -50,6 +50,17 @@ public void update(User u, Film f, Rating r) {
}

}
public void delete(User u, Film f) {
try {
String sql = "DELETE FROM ratings WHERE user_id=? AND film_id=?";
PreparedStatement query = connection.prepareStatement(sql);
query.setString(1, u.getId());
query.setInt(2, f.getId());
query.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAOFilm.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Rating get(User u, Film f) {
try {
String sql = "SELECT rate, rate_date FROM ratings WHERE user_id=? AND film_id=?";
Expand Down
4 changes: 2 additions & 2 deletions MFF/src/java/MFF/Model/DAO/DAOUser.java
Expand Up @@ -37,10 +37,10 @@ public void insert(User u) throws DuplicateUser {
int isAdmin=0;
if (u.getIsAdmin()) { isAdmin=1; }
query.setInt(3, isAdmin);
if (query.executeUpdate() == 0)
throw new DuplicateUser(); // TODO: Puede que no se inserte por algún otro motivo que no sea que está duplicado.
query.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAOUser.class.getName()).log(Level.SEVERE, null, ex); // TODO: Puede dar un fallo de SQL, habría que definir alguna excepción para esto.
throw new DuplicateUser(); // TODO: Puede que no se inserte por algún otro motivo que no sea que está duplicado.
}
}
public Boolean validate(User u) {
Expand Down

0 comments on commit cbfe730

Please sign in to comment.