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
12 changes: 12 additions & 0 deletions src/main/java/com/health/model/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class Category implements Comparable<Category>, Serializable {
@OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<UserRole> userRoles = new HashSet<UserRole>();

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<SubCategory> subCategoriess = new HashSet<SubCategory>();

@OneToMany(mappedBy = "catId", cascade = CascadeType.ALL)
private Set<Brouchure> brochures = new HashSet<Brouchure>();

Expand Down Expand Up @@ -118,6 +121,15 @@ public void setOrder(int order) {
this.order = order;
}

public Set<SubCategory> getSubCategoriess() {
return subCategoriess;
}

public void setSubCategoriess(Set<SubCategory> subCategoriess) {
this.subCategoriess = subCategoriess;

}

public Timestamp getDateAdded() {
return dateAdded;
}
Expand Down
125 changes: 125 additions & 0 deletions src/main/java/com/health/model/SubCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.health.model;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "sub_category")
public class SubCategory implements Comparable<SubCategory>, Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "sub_category_id", nullable = false, updatable = false)
private int subCategoryId;

@Column(name = "sub_category_name", nullable = false, unique = true)
private String subCategoryName;

@Column(name = "date_added", nullable = false)
private Timestamp dateAdded;

@Column(name = "status", nullable = false)
private boolean status = true;

@Column(name = "Image_path", nullable = true)
private String posterPath;

@Column(name = "Description", nullable = true, length = 2000)
private String description;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;

public Timestamp getDateAdded() {
return dateAdded;
}

public void setDateAdded(Timestamp dateAdded) {
this.dateAdded = dateAdded;
}

public boolean isStatus() {
return status;
}

public void setStatus(boolean status) {
this.status = status;
}

public String getPosterPath() {
return posterPath;
}

public void setPosterPath(String posterPath) {
this.posterPath = posterPath;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

public int getSubCategoryId() {
return subCategoryId;
}

public void setSubCategoryId(int subCategoryId) {
this.subCategoryId = subCategoryId;
}

public String getSubCategoryName() {
return subCategoryName;
}

public void setSubCategoryName(String subCategoryName) {
this.subCategoryName = subCategoryName;
}

public SubCategory(String subCategoryName, Timestamp dateAdded, boolean status, String posterPath,
String description, Category category) {
super();
this.subCategoryName = subCategoryName;
this.dateAdded = dateAdded;
this.status = status;
this.posterPath = posterPath;
this.description = description;
this.category = category;

}

public SubCategory() {

}

@Override
public int compareTo(SubCategory o) {

return this.getSubCategoryName().compareTo(o.getSubCategoryName());

}

}
13 changes: 13 additions & 0 deletions src/main/java/com/health/repository/SubCategoryRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.health.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.health.model.SubCategory;

public interface SubCategoryRepository extends JpaRepository<SubCategory, Integer> {

SubCategory findBySubCategoryName(String subCatName);

SubCategory findBySubCategoryId(int subCatId);

}
11 changes: 11 additions & 0 deletions src/main/java/com/health/service/SubCategoryService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.health.service;

import com.health.model.SubCategory;

public interface SubCategoryService {

SubCategory findBySubCategoryName(String subCatName);

SubCategory findBySubCategoryId(int subCatId);

}
28 changes: 28 additions & 0 deletions src/main/java/com/health/service/impl/SubCategoryServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.health.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.health.model.SubCategory;
import com.health.repository.SubCategoryRepository;
import com.health.service.SubCategoryService;

@Service
public class SubCategoryServiceImpl implements SubCategoryService {

@Autowired
private SubCategoryRepository repo;

@Override
public SubCategory findBySubCategoryName(String subCatName) {

return repo.findBySubCategoryName(subCatName);
}

@Override
public SubCategory findBySubCategoryId(int subCatId) {

return repo.findBySubCategoryId(subCatId);
}

}