Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public LocalSessionFactoryBean sessionFactory(){
return sessionFactory;
}


private Properties hibernateProperties(){
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.khasang.bazaar.config.application;

import io.khasang.bazaar.dao.CatDao;
import io.khasang.bazaar.dao.FeedbackDao;
import io.khasang.bazaar.dao.impl.CatDaoImpl;
import io.khasang.bazaar.dao.impl.FeedbackDaoImpl;
import io.khasang.bazaar.entity.Cat;
import io.khasang.bazaar.entity.Feedback;
import io.khasang.bazaar.model.CreateTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -56,4 +59,9 @@ public CreateTable createTable(){
public CatDao catDao(){
return new CatDaoImpl(Cat.class);
}

@Bean
public FeedbackDao feedbackDao() {
return new FeedbackDaoImpl(Feedback.class);
}
}
82 changes: 79 additions & 3 deletions src/main/java/io/khasang/bazaar/controller/AppController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.khasang.bazaar.controller;

import io.khasang.bazaar.model.CreateTable;
import io.khasang.bazaar.model.Message;
import io.khasang.bazaar.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
Expand All @@ -22,6 +21,27 @@ public class AppController {
@Autowired
private CreateTable createTable;

@Autowired
private PopulateTable populateTable;

@Autowired
private SelectFromTable selectFromTable;

@Autowired
private UpdateTable updateTable;

@Autowired
private DeleteFromTable deleteFromTable;

@Autowired
private JoinTable joinTable;

@Autowired
private SubqueryTable subqueryTable;

@Autowired
private CaseWhenTable caseWhenTable;

// http://localhost:8080/
@RequestMapping("/")
public String javaPageHello() {
Expand All @@ -31,7 +51,56 @@ public String javaPageHello() {
@RequestMapping("/create")
public String createTable(Model model) {
model.addAttribute("status", createTable.createStatus());
// hello.jsp
// table.jsp
return "table";
}

@RequestMapping("/populate")
public String populateTable(Model model) {
model.addAttribute("status", populateTable.populateStatus());
// table.jsp
return "table";
}

@RequestMapping("/select")
public String selectFromTable(Model model) {
model.addAttribute("status", selectFromTable.selectStatus());
// table.jsp
return "table";
}

@RequestMapping("/update")
public String updateTable(Model model) {
model.addAttribute("status", updateTable.updateStatus());
// table.jsp
return "table";
}

@RequestMapping("/delete")
public String deleteFromTable(Model model) {
model.addAttribute("status", deleteFromTable.deleteStatus());
// table.jsp
return "table";
}

@RequestMapping("/join")
public String joinTable(Model model) {
model.addAttribute("status", joinTable.joinStatus());
// table.jsp
return "table";
}

@RequestMapping("/subquery")
public String subqueryTable(Model model) {
model.addAttribute("status", subqueryTable.subqueryStatus());
// table.jsp
return "table";
}

@RequestMapping("/casewhen")
public String caseWhenTable(Model model) {
model.addAttribute("status", caseWhenTable.caseWhenStatus());
// table.jsp
return "table";
}

Expand All @@ -41,6 +110,13 @@ public String getAdminInfo(Model model){
return "admin";
}

@RequestMapping("/user")
public String getUserInfo(Model model) {
model.addAttribute("secure", "It's a very secure page!");
// user.jsp
return "user";
}

@RequestMapping(value = {"/password/{password}"}, method = RequestMethod.GET)
public ModelAndView passwordEncode(@PathVariable("password") String password) {
ModelAndView modelAndView = new ModelAndView();
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/io/khasang/bazaar/controller/FeedbackController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.khasang.bazaar.controller;

import io.khasang.bazaar.entity.Feedback;
import io.khasang.bazaar.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/feedback")
public class FeedbackController {
private final FeedbackService feedbackService;

@Autowired
public FeedbackController(FeedbackService feedbackService) {
this.feedbackService = feedbackService;
}

@RequestMapping(value = "/get/id/{id}", method = RequestMethod.GET)
@ResponseBody
public Feedback getFeedbackById(@PathVariable(value = "id") String id) {
return feedbackService.getById(Long.parseLong(id));
}

@RequestMapping(value = "/add", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
@ResponseBody
public Feedback addFeedback(@RequestBody Feedback feedback) {
return feedbackService.addFeedback(feedback);
}

@RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public Feedback updateFeedback(@RequestBody Feedback feedback) {
return feedbackService.updateFeedback(feedback);
}

@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@ResponseBody
public Feedback deleteFeedback(@RequestParam(value = "id") String id){
return feedbackService.deleteFeedback(Long.parseLong(id));
}

@RequestMapping(value = "/get/byuser/{user_id}", method = RequestMethod.GET)
@ResponseBody
public List<Feedback> getFeedbacksByUser(@PathVariable(value = "user_id") String user_id){
return feedbackService.getFeedbacksByUser(Long.parseLong(user_id));
}

@RequestMapping(value = "/get/bygood/{good_id}", method = RequestMethod.GET)
@ResponseBody
public List<Feedback> getFeedbacksByGood(@PathVariable(value = "good_id") String good_id){
return feedbackService.getFeedbacksByGood(Long.parseLong(good_id));
}

@RequestMapping(value = "/get/avgratingbygood/{good_id}", method = RequestMethod.GET)
@ResponseBody
public Double getGoodAverageFeedbackRating(@PathVariable(value = "good_id") String good_id){
return feedbackService.getGoodAverageFeedbackRating(Long.parseLong(good_id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.khasang.bazaar.controller;

import io.khasang.bazaar.entity.GoodsCategory;
import io.khasang.bazaar.service.GoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Controller for Goods Category entity.
*
* @author Zulfia Garifullina
* @date 26.09.2017.
*/
@Controller
@RequestMapping(value = "/goodscategories")
public class GoodsCategoryController {
private final GoodsCategoryService goodsCategoryService;

@Autowired
public GoodsCategoryController(GoodsCategoryService goodsCategoryService) {
this.goodsCategoryService = goodsCategoryService;
}

@RequestMapping(value = "/get/id/{id}", method = RequestMethod.GET)
@ResponseBody
public GoodsCategory getGoodsCategoryById(@PathVariable(value = "id") String id) {
return goodsCategoryService.getById(Long.parseLong(id));
}

@RequestMapping(value = "/get/name/{name}", method = RequestMethod.GET)
@ResponseBody
public List<GoodsCategory> getGoodsCategoriesByName(@PathVariable(value = "name") String name) {
return goodsCategoryService.getGoodsCategoriesByName(name);
}

@RequestMapping(value = "/add", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
@ResponseBody
public GoodsCategory addGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
return goodsCategoryService.addGoodsCategory(goodsCategory);
}

@RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public GoodsCategory updateGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
return goodsCategoryService.updateGoodsCategory(goodsCategory);
}

@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@ResponseBody
public GoodsCategory deleteGoodsCategory(@RequestParam(value = "id") String id) {
return goodsCategoryService.deleteGoodsCategory(Long.parseLong(id));
}

@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public List<GoodsCategory> getGoodsCategories() {
return goodsCategoryService.getList();
}
}
80 changes: 80 additions & 0 deletions src/main/java/io/khasang/bazaar/controller/GoodsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.khasang.bazaar.controller;

import io.khasang.bazaar.entity.Goods;
import io.khasang.bazaar.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Controller for Goods entity.
*
* @author Zulfia Garifullina
* @date 04.10.2017.
*/
@Controller
@RequestMapping(value = "/goods")
public class GoodsController {
private final GoodsService goodsService;

@Autowired
public GoodsController(GoodsService goodsService) {
this.goodsService = goodsService;
}

@RequestMapping(value = "/get/id/{id}", method = RequestMethod.GET)
@ResponseBody
public Goods getGoodsById(@PathVariable(value = "id") String id) {
return goodsService.getById(Long.parseLong(id));
}

@RequestMapping(value = "/get/name/{name}", method = RequestMethod.GET)
@ResponseBody
public List<Goods> getGoodsByName(@PathVariable(value = "name") String name) {
return goodsService.getGoodsByName(name);
}

@RequestMapping(value = "/add", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
@ResponseBody
public Goods addGoods(@RequestBody Goods goods) {
return goodsService.addGoods(goods);
}

@RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public Goods updateGoods(@RequestBody Goods goods) {
return goodsService.updateGoods(goods);
}

@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@ResponseBody
public Goods deleteGoods(@RequestParam(value = "id") String id) {
return goodsService.deleteGoods(Long.parseLong(id));
}

@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public List<Goods> getGoods() {
return goodsService.getList();
}

@RequestMapping(value = "/reserve", method = RequestMethod.POST)
@ResponseBody
public Goods reserveGoods(@RequestParam(value = "id") String id, @RequestParam(value = "quantity") String quantity) {
return goodsService.reserveGoods(Long.parseLong(id), Integer.parseInt(quantity));
}

@RequestMapping(value = "/unreserve", method = RequestMethod.POST)
@ResponseBody
public Goods unreserveGoods(@RequestParam(value = "id") String id, @RequestParam(value = "quantity") String quantity) {
return goodsService.unreserveGoods(Long.parseLong(id), Integer.parseInt(quantity));
}

@RequestMapping(value = "/buy", method = RequestMethod.POST)
@ResponseBody
public Goods buyGoods(@RequestParam(value = "id") String id, @RequestParam(value = "quantity") String quantity) {
return goodsService.buyGoods(Long.parseLong(id), Integer.parseInt(quantity));
}
}
31 changes: 31 additions & 0 deletions src/main/java/io/khasang/bazaar/dao/FeedbackDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.khasang.bazaar.dao;

import io.khasang.bazaar.entity.Feedback;

import java.util.List;

public interface FeedbackDao extends BasicDao<Feedback> {
/**
* Receive all feedback records from database made by user specified by his id
*
* @param user_id - user's id
* @return list of feedback records
*/
List<Feedback> getFeedbacksByUser(Long user_id);

/**
* Receive all feedback records from database about some good item specified by it's id
*
* @param good_id - good's id
* @return list of feedback records
*/
List<Feedback> getFeedbacksByGood(Long good_id);

/**
* Receive average feedback rating for good item specified by it's id
*
* @param good_id - good's id
* @return list of feedback records
*/
Double getGoodAverageFeedbackRating(Long good_id);
}
Loading