Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alperkurtul/spring-boot-starter-firebase-realtime-database

RELEASED version -- An Easy Way to Access Firebase Realtime Database in Spring Boot
https://github.com/alperkurtul/spring-boot-starter-firebase-realtime-database

firebase firebase-realtime-database spring-boot springboot

Last synced: about 2 months ago
JSON representation

RELEASED version -- An Easy Way to Access Firebase Realtime Database in Spring Boot

Awesome Lists containing this project

README

        

# An Easy Way to Access `Firebase Realtime Database` in Spring Boot
This project gives you the ability to access to `Firebase Realtime Database`. To achieve this, you just have to add some basic annotations and define a generic repository in your Spring Boot application. These are the list of methods you can use in this release(1.0.5):

- save (@Deprecated in 1.0.5.RELEASE)
- saveWithRandomId (added in 1.0.5.RELEASE)
- saveWithSpecificId (added in 1.0.5.RELEASE)
- read
- update
- delete

## How to Apply

### Configuration
Add this property in your `application.properties`.
```properties
firebase-realtime-database.database-url=[firebase realtime database url]
```

### Dependencies
Primarily, you have to add `spring-boot-starter-web` dependency in your Spring Boot application.
```xml

org.springframework.boot
spring-boot-starter-web

```

Then, you have to also add this dependency in your `pom.xml`.
```xml

com.github.alperkurtul
spring-boot-starter-firebase-realtime-database
1.0.5.RELEASE

```

### and How to Use
1) create a class for your Firebase Realtime Database `Document`
2) annotate this class as `@FirebaseDocumentPath` and specify a path for your realtime database
3) create a `String` property for your `authentication idToken` and annotate it as `@FirebaseUserAuthKey`
- for a valid `authentication idToken`, use `spring-boot-starter-firebase-user-authentication`.
4) create a property for the ID and annotate it with `@FirebaseDocumentId`

```java
@FirebaseDocumentPath("/product")
public class Product {

@FirebaseUserAuthKey
private String authKey;

@FirebaseDocumentId
private String firebaseId;

private String id;
private String name;
private BigDecimal price;

}
```

Then create a Repository class. This class must extend the `FirebaseRealtimeDbRepoServiceImpl` class.

```java
@Repository
public class ProductRepository extends FirebaseRealtimeDbRepoServiceImpl {
}
```

At last, put `@EnableFirebaseRealtimeDatabase` just next to `@SpringBootApplication` in your main class of Spring Boot application.

```java
@EnableFirebaseRealtimeDatabase
@SpringBootApplication
public class DemoApplication {

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

}
```

### Demo
Here is a demo that I made for you. `Demo`

### Releases
- 1.0.5.RELEASE (2019-11-27)
- **BugFix :** Annotated fields (@FirebaseUserAuthKey and @FirebaseDocumentId) also were being saved to Firebase Database. It is fixed.
- `save` method `@Deprecated`
- Instead of `save` method, `saveWithRandomId` method was added.
- `saveWithSpecificId` method wad added as a new feature. By using this method, you can set specific FirebaseId of your record.

## Next
I hope, I will be able to continue to add new features in the next. Don't be shy to send your advice to me.
Take care...