Coder Social home page Coder Social logo

photosharewebapp's Introduction

PhotoShare

Client and RESTful server built with Jersey and Grizzly

Overview

This system is split into 2 components: a server using gradle, and a web-based client.

Building the server

Simply navigate to the project's top-level directory and run the following command: ./gradlew build

Please note, a more recent version of gradle may be needed when building. If so, run the following commands.

  • ./gradlew wrapper --gradle-version 4.7
  • ./gradlew --version

Running Server and Web-Client

Simply navigate to the project's top-level directory and run the following command: ./gradlew run

With the server running, the client will be exposed at the following URL: http://localhost:8080 The client can also then be accessed from remote machines as well.

Note: Many web-clients can be running at a time. Note: Only one ServerMain instance can be running at a time.

photosharewebapp's People

Contributors

keananf avatar gthedev avatar 14znash avatar stuartkumar avatar zlan18 avatar stuartkumar0630 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

photosharewebapp's Issues

Auth bugs

Login: the restSpec says the endpoint is POST, but trying to post to that method I get Method Not Allowed - the wadl files also suggests it's a GET endpoint. As per previous discussion, can we make this endpoint not require the auth headers, because I need to validate the user's details for login before making the auth token, and need to receive hashed password from the server to avoid different hashing on the front-end and back-end.

Register: Sending POST request to the endpoint with following data: {username: "test", password: "test"} throws Exception in the server console log:

org.h2.jdbc.JdbcSQLException: NULL not allowed for column "USERNAME"; SQL statement:
INSERT INTO users(username,password,admin) values(?, ?, ?) [23502-171]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
        at org.h2.message.DbException.get(DbException.java:169)
        at org.h2.message.DbException.get(DbException.java:146)
        at org.h2.table.Column.validateConvertUpdateSequence(Column.java:293)
        at org.h2.table.Table.validateConvertUpdateSequence(Table.java:692)
        at org.h2.command.dml.Insert.insertRows(Insert.java:120)
        at org.h2.command.dml.Insert.update(Insert.java:84)
        at org.h2.command.CommandContainer.update(CommandContainer.java:75)
        at org.h2.command.Command.executeUpdate(Command.java:230)
        at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
        at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
        at server.datastore.DatabaseBackedDataStore.persistAddUser(DatabaseBackedDataStore.java:406)
        at server.datastore.RequestResolver.addUser(RequestResolver.java:249)
        at server.restApi.UsersAPI.addUser(UsersAPI.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
        at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
        at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:377)
        at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
        at java.lang.Thread.run(Thread.java:745)

POST /users/login - return User data

On the POST /users/login endpoint, on success, can it return a User object (like ones in GET /users/) as the client needs to know the info about the user when they log in (for example, whether they're an admin).

Optionally, it would be useful if it returned an error message otherwise (something I can feed back to the user).

Uploading pictures

Server-side component mostly finished. Will need logic to reject large photos, given an arbitrary, configurable size limit ('X' MB).

Supported file types (?) : PNG, JPG, GIF

Create Table for Photo Ratings

This will follow a similar model to Comment votes, in that there will be a separate table storing associations. That is, a photo_id, a user_id, and a boolean indicating a up / down vote.

Rename Endpoints to fit with RESTful standards

For example a resource called users

Getting all users: GET /users
Fetching a user: GET /users/{id} or GET /users/{username}
Creating a user POST /users
Updating a user PUT /users/{id} or PATCH /users/{id}
Deleting a user DELETE /users/{id}

Retrieving an album by id

The server-side component will follow a similar structure to how photos and comments are retrieved by id.

Get News-Feed

This API will retrieve photos from users who the given user is following.

Un-follow a user

Server / client-side APIs allowing a user to un-follow another

API for Album creation not working

I believe it's a ID generation issue. The first Album created has ID of 0, and then the second ones throws an Exception:

org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.ALBUMS(ALBUMID)";

Full trace:

INSERT INTO albums(albumId,albumName,username,albumDescription,albumTime) values(?, ?, ?, ?, ?) [23505-171]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
        at org.h2.message.DbException.get(DbException.java:169)
        at org.h2.message.DbException.get(DbException.java:146)
        at org.h2.index.PageDataIndex.getNewDuplicateKeyException(PageDataIndex.java:161)
        at org.h2.index.PageDataIndex.add(PageDataIndex.java:139)
        at org.h2.table.RegularTable.addRow(RegularTable.java:122)
        at org.h2.command.dml.Insert.insertRows(Insert.java:124)
        at org.h2.command.dml.Insert.update(Insert.java:84)
        at org.h2.command.CommandContainer.update(CommandContainer.java:75)
        at org.h2.command.Command.executeUpdate(Command.java:230)
        at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
        at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
        at server.datastore.DatabaseBackedDataStore.persistAddAlbum(DatabaseBackedDataStore.java:230)
        at server.datastore.RequestResolver.addAlbum(RequestResolver.java:206)
        at server.restApi.AlbumsApi.addAlbum(AlbumsApi.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
        at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
        at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:377)
        at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
        at java.lang.Thread.run(Thread.java:745)

Server endpoint for adding a photo to an album

This is mostly completed, however uploading a photo will now also require an album_id.
This will mandate adding a foreign key reference to 'album_id' in the 'photos' table, and changing relevant APIs to expect an 'album_id.'

Search bar

Searching for Users.
Perhaps in the future, allow for the ability to search for albums / specific photos

Create table for Following users

This table will hold associations, and could be as simple as rows with two elements each: the user following as well as the user being followed.

Set up scaffolding for the web client

Decide on front-end frameworks and libraries to use.
Look at VueJS, Bootstrap 3/4, useful npm packages if we're using npm.
Assuming we will not use webpack or similar tools.

Server-side API for rating a photo

This will entail a server / client side component, and will follow a similar model to voting on a comment.
A potential endpoint could be: /photos/upvote/{id}

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.