Code Monkey home page Code Monkey logo

course4_assignment's People

Watchers

 avatar

course4_assignment's Issues

The same username can be registered by more than 1 person

Currently, a new user can register using the an username that has been taken by another user. This is a bug as multiple users can have the same username. Therefore, we won't be able to identify who's who.

Therefore, we need to update our UserController class and:

  1. Check if a new user is trying to register with a username that has been previously registered
  2. If yes, flash an error on the user registration page saying that the username has been previously registered.

Error occurs if an image is created with the same title that has been used by another image

Currently, you cannot create two images with the same title, even thought this should be allowed. However, the server will throw an error if you try to create two images with the same title, and then navigate to one of the images.

Reproduction Step:

  1. Create a new image with a title
  2. Create a second image with the same title as the first image
  3. You'll see a server error if you try to navigate to either the first or second image

The issue:

  1. The ImageManager class retrieves an image by its title in the "getImageByTitle" method. Please see the following code in the ImageManager class:
    public Image getImageByTitle(final String title) {
        Session session = openSession();

        try {
            Image image = (Image)session.createCriteria(Image.class)
                    .add(Restrictions.eq("title", title))
                    .uniqueResult(); // retrieves only 1 image
            commitSession(session);

            return image;
        } catch(HibernateException e) {
            System.out.println("unable to retrieve an image from database by its title");
        }

        return null;
    }
  1. As you can see in the getImageByTitle method, we uses a Hibernate method called "uniqueResult"
  2. the uniqueResult method will throw an exception if there is more than than one matching result. Please see the documentation at: https://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Query.html#uniqueResult()

Possible Solution:

  • Instead of retrieving an image by its title, we should retrieve an image by a more unique identifier, such as the image's table id.
  • In addition, we need to update the ImageController so that:
    • an image's url includes its unique identifier
    • the image controller will then use that unique identifier to retrieve an image. This will require an update to both the ImageServer and ImageManager classes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.