Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions README.MD

This file was deleted.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Start Neo4J:

```
docker run \
--name my-neo4j-container2 \
--publish=7474:7474 --publish=7687:7687 \
--env NEO4J_AUTH=neo4j/password \
--volume=$HOME/neo4j/data:/data \
neo4j:latest

```
Neo4J started:
<img width="1259" alt="image" src="https://github.com/rahulvaish/SpringBoot-Java/assets/689226/c5ec7cb9-1a2c-426b-880b-c216a72cd08d">



<img width="1299" alt="image" src="https://github.com/rahulvaish/SpringBoot-Java/assets/689226/c95209ff-4fcd-49b0-99be-759c652fde0b">


<img width="1728" alt="image" src="https://github.com/rahulvaish/SpringBoot-Java/assets/689226/6cb77bf7-8184-4544-98ec-4c0ae390576f">
36 changes: 36 additions & 0 deletions SpringBootNeo4J/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
spring-neo4j/db/*
spring-neo4j/mvnw
spring-neo4j/mvnw.cmd
Binary file added SpringBootNeo4J/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions SpringBootNeo4J/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
15 changes: 15 additions & 0 deletions SpringBootNeo4J/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"
services:
neo4j:
image: neo4j:4.4.20-community
ports:
- 7474:7474
- 7687:7687
restart: unless-stopped
environment:
- NEO4J_AUTH=neo4j/password
volumes:
- ./db/data:/data
- ./db/conf:/conf
- ./db/logs:/logs
- ./db/plugins:/plugins
70 changes: 70 additions & 0 deletions SpringBootNeo4J/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spring.neo4j</groupId>
<artifactId>SpringBootNeo4J</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootNeo4J</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-graphql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.graphql</groupId>
<artifactId>spring-graphql-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
17 changes: 17 additions & 0 deletions SpringBootNeo4J/src/main/java/com/spring/neo4j/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.spring.neo4j;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.neo4j.config.EnableNeo4jAuditing;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;

@SpringBootApplication
@EnableNeo4jAuditing
@EnableNeo4jRepositories(basePackages = {"com.spring.neo4j.repository"})
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.spring.neo4j.controller;

import com.spring.neo4j.repository.node.Author;
import com.spring.neo4j.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("author")
public class AuthorController {

private final AuthorService authorService;

@Autowired
public AuthorController(AuthorService authorService) {
this.authorService = authorService;
}


@GetMapping
public List<Author> getAllAuthors(){
return authorService.getAllAuthors();
}

@PostMapping
public Author addAuthor(@RequestBody Author author){
return authorService.addAuthor(author);
}

@PutMapping
public Author updateAuthor(@RequestBody Author author) {
return authorService.updateAuthor(author);
}

@DeleteMapping("/author/{authorId}")
public void deleteAuthor(@PathVariable Long authorId){
authorService.deleteAuthor(authorId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.spring.neo4j.repository;

import com.spring.neo4j.repository.node.Author;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AuthorRepository extends Neo4jRepository<Author, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.spring.neo4j.repository.node;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Node("Author")
public class Author {
@Id
@GeneratedValue
Long id;
String name;
@Relationship(type = "AUTHORED", direction = Relationship.Direction.INCOMING)
List<Book> books;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.spring.neo4j.repository.node;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Node("Book")
public class Book {
@Id
@GeneratedValue
Long id;
String name;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.spring.neo4j.service;

import com.spring.neo4j.repository.AuthorRepository;
import com.spring.neo4j.repository.node.Author;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Optional;

@Service
public class AuthorService {
private final AuthorRepository authorRepository;

@Autowired
public AuthorService(AuthorRepository authorRepository) {
this.authorRepository = authorRepository;
}

public List<Author> getAllAuthors(){
return authorRepository.findAll();
}

public Author addAuthor( Author author){
return authorRepository.save(author);
}

public Author updateAuthor(Author author) {
Optional<Author> authorFromDB= authorRepository.findById(author.getId());
if(authorFromDB.isPresent()){
Author authorFromDBVal = authorFromDB.get();
authorFromDBVal.setBooks(author.getBooks());
authorFromDBVal.setName(author.getName());
authorRepository.save(authorFromDBVal);
}else{
return null;
}
return author;
}

public void deleteAuthor(Long id) {
authorRepository.deleteById(id);
}
}
10 changes: 10 additions & 0 deletions SpringBootNeo4J/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring:
neo4j:
uri: bolt://localhost:7687
authentication:
username: neo4j
password: password


server:
port: 8030
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.spring.neo4j;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringNeo4jApplicationTests {

@Test
void contextLoads() {
}

}
Loading