Skip to content

Commit

Permalink
complete concrete implementation of CRUD services
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymitrevski committed Apr 1, 2013
1 parent 44f2f39 commit 91d60c7
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@
public class Category implements Serializable {

@Id
private String category;
private String categoryId;
private Category parent;
private List<Category> children;

public Category(String category, List<Category> children)
public Category(String categoryId, List<Category> children)
{
this.category = category;
this.categoryId = categoryId;
this.children = children;
}

public String getCategory() {
return category;
public String getCategoryId() {
return categoryId;
}

public void setCategory(String category) {
this.category = category;
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}

public Category getParent() {
return parent;
}

public void setParent(Category parent) {
this.parent = parent;
}

public List<Category> getChildren() {
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/com/blogspot/agilisto/classifieds/model/Enquiry.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@
* <li>Used to represent enquiries made on listings<br>
*/
@Document(collection = "Enquiry")
public class Enquiry implements Serializable {
public class Enquiry {

@Id
private Long enquiryId;
private Listing listing;
private String id;
private String listingId;
private String email;
private String description;
private String comments;

public Long getEnquiryId() {
return enquiryId;
public Enquiry(String listingId, String email, String comments)
{
this.listingId = listingId;
this.email = email;
this.comments = comments;
}

public void setEnquiryId(Long enquiryId) {
this.enquiryId = enquiryId;
public String getId() {
return id;
}

public Listing getListing() {
return listing;
public String getListingId() {
return listingId;
}

public void setListing(Listing listing) {
this.listing = listing;
public void setListingId(String listingId) {
this.listingId = listingId;
}

public String getEmail() {
Expand All @@ -42,11 +44,11 @@ public void setEmail(String email) {
this.email = email;
}

public String getDescription() {
return description;
public String getComments() {
return comments;
}

public void setDescription(String description) {
this.description = description;
public void setComments(String comments) {
this.comments = comments;
}
}
30 changes: 13 additions & 17 deletions src/main/java/com/blogspot/agilisto/classifieds/model/Listing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

/**
Expand All @@ -14,23 +12,29 @@
@Document(collection = "Listing")
public class Listing implements Serializable{

@Id
private Long listingId;
private String id;
private String title;
private String description;
private Double price;
private Category category;
private List<String> images;
private SellerIdentity sellerIdentity;
private Date listingDate;
private Date expiryDate;

public Long getListingId() {
return listingId;
public Listing(String title, String description, Double price, Category category, SellerIdentity sellerIdentity,
Date listingDate, Date expiryDate)
{
this.title = title;
this.description = description;
this.price = price;
this.category = category;
this.sellerIdentity = sellerIdentity;
this.listingDate = listingDate;
this.expiryDate = expiryDate;
}

public void setId(Long listingId) {
this.listingId = listingId;
public String getId() {
return id;
}

public String getTitle() {
Expand Down Expand Up @@ -64,14 +68,6 @@ public void setCategory(Category category) {
this.category = category;
}

public List<String> getImages() {
return images;
}

public void setImages(List<String> images) {
this.images = images;
}

public SellerIdentity getSellerIdentity() {
return sellerIdentity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class SellerCredential implements Serializable{
String username;
String password;

public SellerCredential(String username, String password)
{
this.username = username;
this.password = password;
}

public String getUsername() {
return username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SellerIdentity implements Serializable{

@Id
SellerCredential sellerCredential;
String username;
String email;
String firstName;
String lastName;
Expand All @@ -25,12 +25,27 @@ public class SellerIdentity implements Serializable{
double[] location;
String phoneNumber;

public SellerCredential getSellerCredential() {
return sellerCredential;
public SellerIdentity(String username, String email, String firstName, String lastName, String street, String suburb,
String state, String postcode, String country, double[] location, String phoneNumber)
{
this.username = username;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.street = street;
this.suburb = suburb;
this.state = state;
this.postcode = postcode;
this.location = location;
this.phoneNumber = phoneNumber;
}

public String getUsername() {
return username;
}

public void setSellerCredential(SellerCredential sellerCredential) {
this.sellerCredential = sellerCredential;
public void setUsername(String username) {
this.username = username;
}

public String getEmail() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.blogspot.agilisto.classifieds.services;

import org.springframework.data.mongodb.core.query.Update;

import com.blogspot.agilisto.classifieds.model.Category;

/**
Expand All @@ -8,9 +10,9 @@
public interface CategoryService {
void save(Category category);

Category getCategory(String category);
Category getCategory(String categoryId);

void updateCategory(Category category);
void updateCategory(String categoryId, Update update);

void deleteCategory(Category category);
void deleteCategory(String categoryId);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.blogspot.agilisto.classifieds.services;

import java.util.List;

import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.blogspot.agilisto.classifieds.model.Enquiry;

/**
* CRUD interface for Enquiry domain model
*/
public interface EnquiryService {
Long save(Enquiry enquiry);
void save(Enquiry enquiry);

Enquiry getEnquiry(String id);

List<Enquiry> getEnquiries(Query query);

Enquiry getEnquiry(String enquiry);
void updateEnquiries(Query query, Update update);

void updateEnquiry(Enquiry enquiry);
void deleteEnquiry(String id);

void deleteEnquiry(Enquiry enquiry);
void deleteEnquries(Query query);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.blogspot.agilisto.classifieds.services;

import java.util.List;

import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.blogspot.agilisto.classifieds.model.Listing;

/**
* CRUD interface for Listing domain model
*/
public interface ListingService {
Long save(Listing listing);
void save(Listing listing);

Listing getListing(String id);

Listing getListing(String listing);
List<Listing> getListings(Query query);

void updateListing(Listing listing);
void updateListing(String id, Update update);

void deleteListing(Listing listing);
void deleteListing(String id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.blogspot.agilisto.classifieds.services;

import org.springframework.data.mongodb.core.query.Update;

import com.blogspot.agilisto.classifieds.model.SellerCredential;

/**
Expand All @@ -8,9 +10,9 @@
public interface SellerCredentialService {
void save(SellerCredential sellerCredential);

SellerCredential getSellerCredential(String sellerCredential);
SellerCredential getSellerCredential(String username);

void updateSellerCredential(SellerCredential sellerCredential);
void updateSellerCredential(String username, Update update);

void deleteSellerCredential(SellerCredential sellerCredential);
void deleteSellerCredential(String username);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.blogspot.agilisto.classifieds.services;

import org.springframework.data.mongodb.core.query.Update;

import com.blogspot.agilisto.classifieds.model.SellerIdentity;

/**
Expand All @@ -8,9 +10,9 @@
public interface SellerIdentityService {
void save(SellerIdentity sellerIdentity);

SellerIdentity getSellerIdentity(String sellerIdentity);
SellerIdentity getSellerIdentity(String username);

void updateSellerIdentity(SellerIdentity sellerIdentity);
void updateSellerIdentity(String username, Update update);

void deleteSellerIdentity(SellerIdentity sellerIdentity);
void deleteSellerIdentity(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import com.blogspot.agilisto.classifieds.model.Category;
Expand All @@ -24,18 +27,18 @@ public void save(Category category) {
}

@Override
public Category getCategory(String category) {
// TODO Auto-generated method stub
return null;
public Category getCategory(String categoryId) {
return mongoTemplate.findById(categoryId, Category.class, CATEGORY_COLLECTION_NAME);
}

@Override
public void updateCategory(Category category) {
// TODO Auto-generated method stub
public void updateCategory(String categoryId, Update update) {
mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(categoryId)), update, CATEGORY_COLLECTION_NAME);
}

@Override
public void deleteCategory(Category category) {
public void deleteCategory(String categoryId) {
Category category = this.getCategory(categoryId);
mongoTemplate.remove(category, CATEGORY_COLLECTION_NAME);
}

Expand Down
Loading

0 comments on commit 91d60c7

Please sign in to comment.