In: Computer Science
Can anyone implement RestApi(CRUD) for this using Spring boot and Firebase? I will appreciate it
farms: [
{
id: string,
farmer: string,
name: string,
image: reference,
description: string,
location: string,
geoLocation: geopoint,
rating: number
}
]
(subcollection within a farm document) products: [
{
id: string,
name: string,
image: reference,
quantity: number,
description: string,
price: number,
expirationDate: timestamp,
updatedDate: timestamp,
categories: array[string],
tags: array[string],
location: string,
geoLocation: geopoint,
rating: number
}
]
Here you can go setp by setps ::
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.addListeners(new ApplicationPidFileWriter());
springApplication.run(args);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class InputController {
@PostMapping(value = "/greeting",produces= MediaType.APPLICATION_JSON_VALUE,consumes=MediaType.APPLICATION_JSON_VALUE)
public boolean indexCreator(@RequestBody InputClass input) throws IOException {
System.out.println(input[0].getF());
System.out.println(input[0].getP());
return true;
}
}
import java.util.List;
class InputClass {
private List<Farms> f;
private List<Products> p;
public InputClass(List<Farms> f, List<Products> p) {
this.f = f;
this.p = p;
}
public List<Farms> getF() {
return f;
}
public void setF(List<Farms> f) {
this.f = f;
}
public List<Products> getP() {
return p;
}
public void setP(List<Products> p) {
this.p = p;
}
}
import org.apache.lucene.spatial3d.geom.GeoPoint;
import javax.naming.Reference;
public class Farms {
private int id;
private String farmer;
private String name;
private Reference image;
private String description;
private String location;
private GeoPoint geolocation;
private String rating;
public Farms(int id, String farmer, String name, Reference image, String description, String location, GeoPoint geolocation, String rating) {
this.id = id;
this.farmer = farmer;
this.name = name;
this.image = image;
this.description = description;
this.location = location;
this.geolocation = geolocation;
this.rating = rating;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFarmer() {
return farmer;
}
public void setFarmer(String farmer) {
this.farmer = farmer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Reference getImage() {
return image;
}
public void setImage(Reference image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public GeoPoint getGeolocation() {
return geolocation;
}
public void setGeolocation(GeoPoint geolocation) {
this.geolocation = geolocation;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
}
import org.apache.lucene.spatial3d.geom.GeoPoint;
import java.lang.ref.Reference;
import java.sql.Timestamp;
public class Products {
private String id;
private String name;
private Reference image;
private int quantity;
private String description;
private int price;
private Timestamp expirationDate;
private Timestamp updatedDate;
private String[] categories;
private String[] tags;
private String location;
private GeoPoint geoLocation;
private int rating;
public Products(String id, String name, Reference image, int quantity, String description, int price, Timestamp expirationDate, Timestamp updatedDate, String[] categories, String[] tags, String location, GeoPoint geoLocation, int rating) {
this.id = id;
this.name = name;
this.image = image;
this.quantity = quantity;
this.description = description;
this.price = price;
this.expirationDate = expirationDate;
this.updatedDate = updatedDate;
this.categories = categories;
this.tags = tags;
this.location = location;
this.geoLocation = geoLocation;
this.rating = rating;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Reference getImage() {
return image;
}
public void setImage(Reference image) {
this.image = image;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Timestamp getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(Timestamp expirationDate) {
this.expirationDate = expirationDate;
}
public Timestamp getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Timestamp updatedDate) {
this.updatedDate = updatedDate;
}
public String[] getCategories() {
return categories;
}
public void setCategories(String[] categories) {
this.categories = categories;
}
public String[] getTags() {
return tags;
}
public void setTags(String[] tags) {
this.tags = tags;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public GeoPoint getGeoLocation() {
return geoLocation;
}
public void setGeoLocation(GeoPoint geoLocation) {
this.geoLocation = geoLocation;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
}
Here Now This will accept Rest Call :
/greeting
{
farms: [
{
id: string,
farmer: string,
name: string,
image: reference,
description: string,
location: string,
geoLocation: geopoint,
rating: number
}
]
products: [
{
id: string,
name: string,
image: reference,
quantity: number,
description: string,
price: number,
expirationDate: timestamp,
updatedDate: timestamp,
categories: array[string],
tags: array[string],
location: string,
geoLocation: geopoint,
rating: number
}
]
}