package com.pizza5stars.dao;

import com.pizza5stars.dao.mappers.RatingMapper;
import com.pizza5stars.representations.Address;
import com.pizza5stars.representations.Rating;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.Mapper;

import java.util.List;

public interface RatingDAO {
    @GetGeneratedKeys
    @SqlUpdate("insert into rating (customerId, pizzaId, value) values (:customerId, :pizzaId, :value)")
    int createRating(@Bind("customerId") int customerId,
                     @Bind("pizzaId") int pizzaId,
                     @Bind("rating") double value);

    @Mapper(RatingMapper.class)
    @SqlQuery("select * from rating where customer_id = :customerId")
    List<Rating>getRatingsByCustomerId(@Bind("customerId") int customerId);


}

@@ -928,11 +928,177 @@
 erId);%0A%0A
+    @Mapper(RatingMapper.class)%0A    @SqlQuery(%22select AVG(rating) from rating where pizza_id = :pizzaId%22)%0A    int getRatingsByPizzaId(@Bind(%22pizzaId%22) int pizzaId);%0A%0A
 %0A%7D%0A

Add getRatingByPizzaId to RatingDAO