Coder Social home page Coder Social logo

csalih / mflix-java Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 116 KB

My solutions for the MongoDB for Java Developers course

Home Page: https://university.mongodb.com/courses/M220J/about

Java 100.00%
mongodb react spring-boot mongo-university mongo-atlas mflix

mflix-java's Introduction

๐Ÿ‘‹ Hey there,
Header

About Me

I'm a passionate software developer with a knack for crafting robust solutions that power enterprises. I'm committed to continually improving, delivering efficient and scalable software daily. I have a deep passion for software architecture, considering it an essential element in building systems that withstand the changes of time.

My expertise spans a wide spectrum, from foundational languages like C, to dynamic typed languages like JavaScript, and my ongoing fascination with memory safety through Rust. With new technologies, I don't begin โ€“ I dive right in!

Interests

My interests range from developing backends for websites to working on embedded systems; I thrive on tackling complex challenges.

  • ๐Ÿ—๏ธ Software Architecture
  • ๐ŸŒ€ Scientific Computing
  • ๐Ÿ“ผ Embedded systems
  • โ˜๏ธ Cloud Computing
  • ๐Ÿ”€ Distributed systems
  • ๐Ÿš‘ Medicle in general

mflix-java's People

Contributors

csalih avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

mflix-java's Issues

Ticket: User Preferences

Ticket: User Preferences

User Story

"As a user, I want to be able to store preferences such as my favorite cast member and preferred language."


Task

For this Ticket, you'll be required to implement the updateUserPreferences method in UserDao.java. This method allows updates to be made to the "preferences" field in the users collection.


MFlix Functionality

Once this ticket is completed, users will be able to save preferences in their account information.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=UserPreferencesTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

Ticket: Handling Timeouts

Ticket: Handling Timeouts

Task

For this ticket, you'll be required to modify the connection information for MongoClient to set a write concern timeout of 2500 milliseconds.

The MongoClient in mflix.config.MongoDBConfiguration is initialized in the mongoClient bean method. There are a few other details in the Mongo Client section of the Java Driver documentation for your reference.

Aside from the write concern timeout, you are also tasked to set the connectTimeoutMS configuration option to 2000 milliseconds. This option should be set in the connection string. Check MongoDB URI options reference for more information.

The unit test TimeoutsTest.java will be asserting that these two configuration options are correctly set.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=TimeoutsTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Or run the Application.java class from your IDE.

Ticket: Connection Pooling

Ticket: Connection Pooling

Task

For this ticket, you'll be required to modify the configuration of option that defines our maxPoolSize in the application.properties file, and set the maximum size of the connection pool to 50 connections.

By changing the properties file, the MongoClient should be configured to use no more than 50 connections. Revise the ConnectionString java class api.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=ConnectionPoolingTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Or deploy the application from your IDE.

Ticket: Migration

Ticket: Migration

Task

For this ticket, you'll be completing a script that performs field data type migrations. The script main class implementation is src/main/java/mflix/Migrator.java.

Things always change, and a requirement has come down that the lastupdated value in each document of the movies collection needs to be stored as an ISODate rather than a String.

Apart from the lastupdated field, we also want to clean up the different data types that currently define the field imdb.rating, where in some cases it is set as of Number type, and in other cases set as String. Given that this field represents a numeric value, this field should be set as a number in all documents.

Complete the script so it updates the values using the bulk API.

To perform the migration, run the following command:

mvn clean compile exec:java -Dexec.mainClass="mflix.Migrator"

or run the Migrator.java class from your IDE.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

COPY
mvn test -Dtest=MigrationTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Ticket: Get Comments

Ticket: Get Comments

User Story

"As a user, I want to be able to view comments for a movie when I look at the movie detail page."


Task

For this ticket, you'll be required to extend the getMovie method in MovieDao.java so that it also fetches the comments for a given movie.

The comments should be returned in order from most recent to least recent using the date key.

Movie comments are stored in the comments collection, so this task can be accomplished by performing a $lookup. Refer to the Aggregation Quick Reference for the specific syntax.


MFlix Functionality

Once this ticket is completed, each movie's comments will be displayed on that movie's detail page.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=GetCommentsTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Or run Application.java from your IDE.

Ticket: Delete Comments

Ticket: Delete Comments

User Story

"As a user, I want to be able to delete my own comments."


Task

For this ticket, you'll be required to modify the deleteComment method in CommentDao.java. Ensure the delete operation is limited so only the user can delete their own comments, but not anyone else's comments.


MFlix Functionality

Once this ticket is completed, users will be able to delete their own comments, but they won't be able to delete anyone else's comments.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

COPY
mvn test -Dtest=DeleteCommentTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

Ticket: Principle of Least Privilege

Ticket: Principle of Least Privilege

Task

For this ticket, you'll be required to add a new user on your Atlas cluster for the MFlix application to connect with.

The user should follow credentials:

  • username: mflixAppUser
  • password: mflixAppPwd

This user should have the readWrite role on the sample_mflix database. Use Add Default Privileges to assign the user this specific role.

After you have created this user, modify the SRV connection string in your configuration file so the application connects with the new username and password.


Testing and Running the Application

There are no unit tests associated with this ticket.

Ticket: User Management

Ticket: User Management

User Story

"As a user, I should be able to register for an account, log in, and logout."


Task

For this Ticket, you'll be required to implement all the methods in UserDao.java that are marked for the User Management ticket. Specifically, you'll implement:

  • createUserSession
  • getUser
  • getUserSession
  • deleteUserSession
  • deleteUser

Registering should create an account and log the user in, ensuring an entry is made in the sessions collection. There is a unique index on the user_id field in sessions, so we can efficiently query on this field.


MFlix Functionality

Once this ticket is completed, users will be able to register for a new account, log in, logout, and delete their account.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=UserTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

Ticket: Create/Update Comments

Ticket: Create/Update Comments

User Story

"As a user, I want to be able to post comments to a movie page as well as edit my own comments."


Task

For this ticket, you'll be required to implement the addComment and updateComment methods in CommentDao.

Ensure that updateComment only allows users to update their own comments, and no one else's comments.


MFlix Functionality

Once this ticket is completed, users will be able to post comments on their favorite (and least favorite) movies, and edit comments they've posted.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=UpdateCreateCommentTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Our launch the Application from your IDE.

Ticket: Durable Writes

Ticket: Durable Writes

User Story

When a new user registers for MFlix, their information must be added to the database before they can do anything else. For this reason, we want to make sure that the data written by the addUser method will not be rolled back.

We can decrease the chances of a rollback by increasing the write durability of the addUser method.


Task

For this ticket, you'll be required to increase the durability of the addUser method.

Ticket: Handling Errors

Ticket: Handling Errors

Task

For this ticket, you'll be required to modify the following methods:

MovieDao.java

  • validIdValue

CommentDao.java

  • addComment
  • deleteComment
  • updateComment

UserDao.java

  • addUser
  • createUserSession
  • deleteUser
  • updateUserPreferences

Ensure that all of these methods are more robust and account for potential exceptions when executed.


MFlix Functionality

Once this ticket is completed, the app will be able to handle incorrect movie id values and various write exceptions without breaking or throwing an error within the application.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=HandlingErrorsTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

Ticket: Paging

Ticket: Paging

User Story

"As a user, I'd like to get the next page of results for my query by scrolling down in the main window of the application."


Task

For this ticket, you'll be required to modify the getMoviesByGenre method in MovieDao.java, to allow for paging.


MFlix Functionality

The UI is already asking for infinite scroll! You may have noticed a message stating "paging not implemented" when scrolling to the bottom of the page.

Once this ticket is completed, this message will go away, and scrolling to the bottom of the page will result in a new page of movies.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=PagingTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

Ticket: User Report

Ticket: User Report

User Story

"As an administrator, I want to be able to view the top 20 users by their number of comments."


Task

For this ticket, you'll be required to modify the mostActiveCommenters method in CommentDao.java. This method produces a report of the 20 most frequent commenters on the MFlix site.

Hint

This report is meant to be run from the backend by a manager who is very particular about the accuracy of data. Ensure that the read concern used in this read, avoids any potential document rollback.

Remember to add the necessary changes in the pipeline to meet the requirements. More information can be found in the comments of the method.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=UserReportTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

Or run Application.java from your IDE.

Ticket: Faceted Search

Ticket: Faceted Search

Problem:

User Story

"As a user, I want to be able to filter cast search results by one facet, metacritic rating."


Task

For this ticket, you'll be required to modify the getMoviesCastFaceted method in MovieDao.java, so the MFlix application can perform faceted searches. You will find a more detailed description of the task as a comment in the MovieDao.java file.


MFlix Functionality

Once the change is implemented for this ticket, the user interface will reflect this change when you search for cast (e.g. "Tom Hanks"), then additional search parameters will be added as shown below:

https://university-courses.s3.amazonaws.com/m220/facetedSearchScreenshot.png

What is a Faceted Search?

Faceted search is a way of narrowing down search results as search parameters are added. For example, let's say MFlix allows users to filter movies by a rating from 1 to 10, but Kate Winslet has only acted in movies that have a rating of 6 or higher.

If we didn't specify any other search parameters, MFlix would allow us to choose a rating between 1 and 10. But if we first search for Kate Winslet, MFlix would only let us choose a rating between 6 and 10, because none of the movie documents in the result set have a rating below 6.

If you're curious, you can read more about Faceted Search here.

Faceted Search in MFlix

Faceted searches on the MFlix site cannot be supported with the basic search method getMovies. For faceted searches, the application must use the Aggregation Framework.

The method getMoviesCastFaceted uses the Aggregation Framework, and the individual stages in the pipeline have already been completed. Follow instructions in the MovieDao.java file to add the required stages to the pipeline object.


Testing and Running the Application

If the application is already running, stop the application and run the unit tests for this ticket by executing the following command:

mvn test -Dtest=FacetedSearchTest

Once the unit tests are passing, run the application with:

mvn spring-boot:run

or run the Application.java from your IDE.

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.