syncstream-dev / syncstream-backend

Java + SpringBoot backend for SyncStream Application
GNU General Public License v2.0
2 stars 2 forks source link

Integrate User database and User repository #13

Closed Xu-Gavin closed 8 months ago

Xu-Gavin commented 9 months ago
  1. Add Dependencies: Add the Spring Boot Data Cassandra starter tobuild.gradle file. This starter includes auto-configuration support for Cassandra and the Cassandra Java driver, as well as Spring Data Cassandra which provides abstractions for storing and querying your data.
  2. Configure Cassandra Properties: In application.properties file, specify properties like the keyspace name, contact points (IP addresses of the Cassandra nodes), and port. Specify other properties like the consistency level, load balancing policy, etc.
  3. Setup Database: Set up the Cassandra database. Use a local installation for development, but for production, likely use a Cassandra cluster.
  4. Create Data Models: These are entity classes that map to tables in your Cassandra database. Annotate these classes with @Table and the fields with @Column or @PrimaryKey.
  5. Create Repositories: These interfaces extend CassandraRepository or ReactiveCassandraRepository and provide methods for common CRUD operations. Can also define custom methods.
  6. Use Repositories in Your Services and Controllers: Use @Autowire your repositories into your services to use in business logic, and then your services can be used in controllers to handle HTTP requests.
  7. Write Tests for Cassandra DB: Use the CassandraRepository.
Xu-Gavin commented 9 months ago

I'm going to combine UserInfo.java and User.java into a single class because of the way I think that theUser table should be stored in the database.

FYI: @itsmarsss

Xu-Gavin commented 9 months ago

For repository queries: https://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/repository-query-keywords.html

Xu-Gavin commented 9 months ago

Docker Setup: Once you have started a docker container with the Cassandra database running, you need to add a keyspace manually (for now I hope): docker run -p 9042:9042 --rm --name cassandra -d cassandra:4.0.7 docker exec -it cassandra bash -c "cqlsh -u cassandra -p cassandra" CREATE KEYSPACE spring_cassandra WITH replication = {'class' : 'SimpleStrategy', 'replication_factor' : 1};

Xu-Gavin commented 8 months ago

Test containers is going to be put in the backlog due to issues trying to get it to work.

Xu-Gavin commented 8 months ago

There is a failing test. Let me try to resolve it first before review.

Xu-Gavin commented 8 months ago

Failing tests resolved. PR #16 open for review.