diff --git a/VamPa/src/main/java/com/vam/mapper/ReplyMapper.java b/VamPa/src/main/java/com/vam/mapper/ReplyMapper.java index 4c5401f..84d8509 100644 --- a/VamPa/src/main/java/com/vam/mapper/ReplyMapper.java +++ b/VamPa/src/main/java/com/vam/mapper/ReplyMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.vam.model.Criteria; import com.vam.model.ReplyDTO; +import com.vam.model.UpdateReplyDTO; public interface ReplyMapper { @@ -28,4 +29,10 @@ public interface ReplyMapper { /* 댓글 삭제 */ public int deleteReply(int replyId); + /* 평점 평균 구하기 */ + public Double getRatingAverage(int bookId); + + /* 평점 평균 반영하기 */ + public int updateRating(UpdateReplyDTO dto); + } diff --git a/VamPa/src/main/java/com/vam/model/UpdateReplyDTO.java b/VamPa/src/main/java/com/vam/model/UpdateReplyDTO.java new file mode 100644 index 0000000..1587fc6 --- /dev/null +++ b/VamPa/src/main/java/com/vam/model/UpdateReplyDTO.java @@ -0,0 +1,32 @@ +package com.vam.model; + +public class UpdateReplyDTO { + + private int bookId; + + private double ratingAvg; + + public int getBookId() { + return bookId; + } + + public void setBookId(int bookId) { + this.bookId = bookId; + } + + public double getRatingAvg() { + return ratingAvg; + } + + public void setRatingAvg(double ratingAvg) { + this.ratingAvg = ratingAvg; + } + + @Override + public String toString() { + return "UpdateReplyDTO [bookId=" + bookId + ", ratingAvg=" + ratingAvg + "]"; + } + + + +} diff --git a/VamPa/src/main/java/com/vam/service/ReplyServiceImpl.java b/VamPa/src/main/java/com/vam/service/ReplyServiceImpl.java index d71895c..3f4a01d 100644 --- a/VamPa/src/main/java/com/vam/service/ReplyServiceImpl.java +++ b/VamPa/src/main/java/com/vam/service/ReplyServiceImpl.java @@ -8,6 +8,7 @@ import com.vam.model.Criteria; import com.vam.model.PageDTO; import com.vam.model.ReplyDTO; import com.vam.model.ReplyPageDTO; +import com.vam.model.UpdateReplyDTO; @Service public class ReplyServiceImpl implements ReplyService{ @@ -21,6 +22,8 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.enrollReply(dto); + setRating(dto.getBookId()); + return result; } @@ -54,6 +57,8 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.updateReply(dto); + setRating(dto.getBookId()); + return result; } @@ -68,8 +73,28 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.deleteReply(dto.getReplyId()); + setRating(dto.getBookId()); + return result; } + public void setRating(int bookId) { + + Double ratingAvg = replyMapper.getRatingAverage(bookId); + + if(ratingAvg == null) { + ratingAvg = 0.0; + } + + ratingAvg = (double) (Math.round(ratingAvg*10)); + ratingAvg = ratingAvg / 10; + + UpdateReplyDTO urd = new UpdateReplyDTO(); + urd.setBookId(bookId); + urd.setRatingAvg(ratingAvg); + + replyMapper.updateRating(urd); + + } } diff --git a/VamPa/src/main/resources/com/vam/mapper/ReplyMapper.xml b/VamPa/src/main/resources/com/vam/mapper/ReplyMapper.xml index 80b497e..27b2f7b 100644 --- a/VamPa/src/main/resources/com/vam/mapper/ReplyMapper.xml +++ b/VamPa/src/main/resources/com/vam/mapper/ReplyMapper.xml @@ -63,7 +63,25 @@ DELETE FROM vam_reply WHERE replyId = #{replyId} - + + + + + + + update vam_book + set ratingAvg = #{ratingAvg} + where bookId = #{bookId} + + + + \ No newline at end of file diff --git a/VamPa/target/classes/com/vam/mapper/ReplyMapper.xml b/VamPa/target/classes/com/vam/mapper/ReplyMapper.xml index 80b497e..27b2f7b 100644 --- a/VamPa/target/classes/com/vam/mapper/ReplyMapper.xml +++ b/VamPa/target/classes/com/vam/mapper/ReplyMapper.xml @@ -63,7 +63,25 @@ DELETE FROM vam_reply WHERE replyId = #{replyId} - + + + + + + + update vam_book + set ratingAvg = #{ratingAvg} + where bookId = #{bookId} + + + + \ No newline at end of file diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index ffd551e..48c9b67 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Sun Jan 09 17:57:01 KST 2022 +#Thu Feb 03 02:45:21 KST 2022 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa_MySQL/src/main/java/com/vam/mapper/ReplyMapper.java b/VamPa_MySQL/src/main/java/com/vam/mapper/ReplyMapper.java index 0c0c8b9..09d1300 100644 --- a/VamPa_MySQL/src/main/java/com/vam/mapper/ReplyMapper.java +++ b/VamPa_MySQL/src/main/java/com/vam/mapper/ReplyMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.vam.model.Criteria; import com.vam.model.ReplyDTO; +import com.vam.model.UpdateReplyDTO; public interface ReplyMapper { @@ -28,4 +29,10 @@ public interface ReplyMapper { /* 댓글 삭제 */ public int deleteReply(int replyId); + /* 평점 평균 구하기 */ + public Double getRatingAverage(int bookId); + + /* 평점 평균 반영하기 */ + public int updateRating(UpdateReplyDTO dto); + } diff --git a/VamPa_MySQL/src/main/java/com/vam/model/UpdateReplyDTO.java b/VamPa_MySQL/src/main/java/com/vam/model/UpdateReplyDTO.java new file mode 100644 index 0000000..3c80454 --- /dev/null +++ b/VamPa_MySQL/src/main/java/com/vam/model/UpdateReplyDTO.java @@ -0,0 +1,30 @@ +package com.vam.model; + +public class UpdateReplyDTO { + + private int bookId; + + private double ratingAvg; + + public int getBookId() { + return bookId; + } + + public void setBookId(int bookId) { + this.bookId = bookId; + } + + public double getRatingAvg() { + return ratingAvg; + } + + public void setRatingAvg(double ratingAvg) { + this.ratingAvg = ratingAvg; + } + + @Override + public String toString() { + return "UpdateReplyDTO [bookId=" + bookId + ", ratingAvg=" + ratingAvg + "]"; + } + +} diff --git a/VamPa_MySQL/src/main/java/com/vam/service/ReplyServiceImpl.java b/VamPa_MySQL/src/main/java/com/vam/service/ReplyServiceImpl.java index 968d7c5..9695adc 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/ReplyServiceImpl.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/ReplyServiceImpl.java @@ -8,6 +8,7 @@ import com.vam.model.Criteria; import com.vam.model.PageDTO; import com.vam.model.ReplyDTO; import com.vam.model.ReplyPageDTO; +import com.vam.model.UpdateReplyDTO; @Service public class ReplyServiceImpl implements ReplyService{ @@ -21,6 +22,8 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.enrollReply(dto); + setRating(dto.getBookId()); + return result; } @@ -53,6 +56,8 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.updateReply(dto); + setRating(dto.getBookId()); + return result; } @@ -67,7 +72,28 @@ public class ReplyServiceImpl implements ReplyService{ int result = replyMapper.deleteReply(dto.getReplyId()); + setRating(dto.getBookId()); + return result; + } + + public void setRating(int bookId) { + + Double ratingAvg = replyMapper.getRatingAverage(bookId); + + if(ratingAvg == null) { + ratingAvg = 0.0; + } + + ratingAvg = (double) (Math.round(ratingAvg*10)); + ratingAvg = ratingAvg / 10; + + UpdateReplyDTO urd = new UpdateReplyDTO(); + urd.setBookId(bookId); + urd.setRatingAvg(ratingAvg); + + replyMapper.updateRating(urd); + } } diff --git a/VamPa_MySQL/src/main/resources/com/vam/mapper/ReplyMapper.xml b/VamPa_MySQL/src/main/resources/com/vam/mapper/ReplyMapper.xml index 6f7a9d9..fb70129 100644 --- a/VamPa_MySQL/src/main/resources/com/vam/mapper/ReplyMapper.xml +++ b/VamPa_MySQL/src/main/resources/com/vam/mapper/ReplyMapper.xml @@ -60,5 +60,21 @@ WHERE replyId = #{replyId} + + + + + + update vam_book + set ratingAvg = #{ratingAvg} + where bookId = #{bookId} + + \ No newline at end of file diff --git a/VamPa_MySQL/target/classes/com/vam/mapper/ReplyMapper.xml b/VamPa_MySQL/target/classes/com/vam/mapper/ReplyMapper.xml index 6f7a9d9..fb70129 100644 --- a/VamPa_MySQL/target/classes/com/vam/mapper/ReplyMapper.xml +++ b/VamPa_MySQL/target/classes/com/vam/mapper/ReplyMapper.xml @@ -60,5 +60,21 @@ WHERE replyId = #{replyId} + + + + + + update vam_book + set ratingAvg = #{ratingAvg} + where bookId = #{bookId} + + \ No newline at end of file diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 2eeb6f2..fd515d6 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Sun Jan 09 17:57:01 KST 2022 +#Thu Feb 03 02:45:21 KST 2022 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam