-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from mahipat303/Day_4(Arup)
day_4
- Loading branch information
Showing
7 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
foodland/src/main/java/com/foodland/controller/CategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.foodland.controller; | ||
|
||
import com.foodland.exception.CategoryException; | ||
import com.foodland.model.Category; | ||
import com.foodland.service.CategoryService; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
public class CategoryController { | ||
private CategoryService cs; | ||
@PostMapping("/category/{key}") | ||
public Category addCategory(Category category,String key) throws CategoryException { | ||
|
||
return cs.addCategory(category,key); | ||
} | ||
@PutMapping("/category/{key}") | ||
public Category updateCategory(@RequestBody Category category, String key) throws CategoryException { | ||
|
||
return cs.updateCategory(category,key); | ||
} | ||
|
||
@PutMapping("/removecategory/{key}") | ||
public Category removeCategory(@RequestBody Category category, String key) throws CategoryException { | ||
|
||
return cs.removeCategory(category,key); | ||
} | ||
@GetMapping("/category/{key}") | ||
public Category viewCategory(@RequestBody Category category, String key) throws CategoryException { | ||
|
||
return cs.viewCategory(category,key); | ||
} | ||
@GetMapping("/categories/{key}") | ||
public List<Category> viewAllCategory(String key) throws CategoryException { | ||
|
||
return cs.viewAllCategory(key); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
foodland/src/main/java/com/foodland/repository/CategoryDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.foodland.repository; | ||
|
||
import com.foodland.exception.CategoryException; | ||
import com.foodland.model.Category; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CategoryDao extends JpaRepository<Category,Integer> { | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 97 additions & 10 deletions
107
foodland/src/main/java/com/foodland/serviceImpl/CategoryServiseImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,121 @@ | ||
package com.foodland.serviceImpl; | ||
|
||
import com.foodland.exception.CategoryException; | ||
import com.foodland.exception.RestaurantException; | ||
import com.foodland.exception.UserException; | ||
import com.foodland.model.Category; | ||
import com.foodland.model.CurrentUserSession; | ||
import com.foodland.model.Restaurant; | ||
import com.foodland.model.UserType; | ||
import com.foodland.repository.CategoryDao; | ||
import com.foodland.repository.SessionDao; | ||
import com.foodland.service.CategoryService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class CategoryServiseImpl implements CategoryService{ | ||
@Autowired | ||
private SessionDao sdo; | ||
private CategoryDao cdo; | ||
@Override | ||
public Category addCategory(Category category) throws CategoryException { | ||
return null; | ||
public Category addCategory(Category category, String key) throws CategoryException { | ||
CurrentUserSession cus = sdo.findByUuid(key); | ||
|
||
UserType uType = cus.getType(); | ||
|
||
if (uType.name().equals("Restaurant")) { | ||
if(category!=null){ | ||
return cdo.save(category); | ||
}else{ | ||
throw new CategoryException("Please Enter Valid Category"); | ||
} | ||
|
||
|
||
} else { | ||
throw new UserException("Please login as a Restaurant"); | ||
} | ||
} | ||
|
||
@Override | ||
public Category updateCategory(Category category) throws CategoryException { | ||
return null; | ||
public Category updateCategory(Category category, String key) throws CategoryException { | ||
CurrentUserSession cus = sdo.findByUuid(key); | ||
|
||
UserType uType = cus.getType(); | ||
|
||
if (uType.name().equals("Restaurant")) { | ||
Optional<Category> ocategory =cdo.findById(category.getCategoryId()); | ||
if(ocategory.isPresent()) { | ||
cdo.delete(category); | ||
return ocategory.get(); | ||
}else{ | ||
throw new CategoryException("No category Found"); | ||
} | ||
|
||
|
||
} else { | ||
throw new UserException("Please login as a Restaurant"); | ||
} | ||
} | ||
|
||
@Override | ||
public Category removeCategory(Category category) throws CategoryException { | ||
return null; | ||
public Category removeCategory(Category category, String key) throws CategoryException { | ||
CurrentUserSession cus = sdo.findByUuid(key); | ||
|
||
UserType uType = cus.getType(); | ||
|
||
if (uType.name().equals("Restaurant")) { | ||
Optional<Category> ocategory= cdo.findById(category.getCategoryId()); | ||
|
||
if(ocategory.isPresent()){ | ||
cdo.delete(category); | ||
return ocategory.get(); | ||
}else{ | ||
throw new CategoryException("No Category available like :" +category); | ||
} | ||
} else { | ||
throw new UserException("Please login as a Restaurant"); | ||
} | ||
} | ||
|
||
@Override | ||
public Category viewCategory(Category category) throws CategoryException { | ||
return null; | ||
public Category viewCategory(Category category, String key) throws CategoryException { | ||
CurrentUserSession cus = sdo.findByUuid(key); | ||
|
||
UserType uType = cus.getType(); | ||
|
||
if (uType.name().equals("Customer") || uType.name().equals("Restaurant")) { | ||
|
||
Optional<Category> ct=cdo.findById(category.getCategoryId()); | ||
if(ct.isPresent()) { | ||
return ct.get(); | ||
}else{ | ||
throw new CategoryException("No Category found"); | ||
} | ||
|
||
} else { | ||
throw new UserException("Please Log in first"); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Category> viewAllCategory() throws CategoryException { | ||
return null; | ||
public List<Category> viewAllCategory(String key) throws CategoryException { | ||
CurrentUserSession cus = sdo.findByUuid(key); | ||
|
||
UserType uType = cus.getType(); | ||
|
||
if (uType.name().equals("Customer") || uType.name().equals("Restaurant")) { | ||
|
||
List<Category> clist=cdo.findAll(); | ||
if(clist.size()==0) { | ||
return clist; | ||
}else{ | ||
throw new CategoryException("No Category found"); | ||
} | ||
|
||
} else { | ||
throw new UserException("Please Log in first"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters