From 7f5799591c143dd2f12ccde2a9cf78cc01cfb973 Mon Sep 17 00:00:00 2001 From: Awhn <69659322+Awhn@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:42:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EA=B0=95=EC=9B=90/=EC=A0=84=EB=B6=81=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EB=8F=84=EC=8B=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/district_and_coordinate_kr.csv | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/main/resources/district_and_coordinate_kr.csv b/src/main/resources/district_and_coordinate_kr.csv index 0693937..500404d 100644 --- a/src/main/resources/district_and_coordinate_kr.csv +++ b/src/main/resources/district_and_coordinate_kr.csv @@ -121,39 +121,22 @@ 4140000,6410000,경기도,연천군,38.09272995,127.0244564,FALSE 4160000,6410000,경기도,가평군,37.81843317,127.4501921,FALSE 4170000,6410000,경기도,양평군,37.51805585,127.5792645,FALSE -4181000,6530000,강원특별자치도,춘천시,37.88979679,127.7398684,FALSE 4180000,6530000,강원도,춘천시,37.88979679,127.7398684,FALSE -4191000,6530000,강원특별자치도,원주시,37.30822288,127.9295253,FALSE 4190000,6530000,강원도,원주시,37.30822288,127.9295253,FALSE -4201000,6530000,강원특별자치도,강릉시,37.70910197,128.8323789,FALSE 4200000,6530000,강원도,강릉시,37.70910197,128.8323789,FALSE -4211000,6530000,강원특별자치도,동해시,37.5066814,129.0555688,FALSE 4210000,6530000,강원도,동해시,37.5066814,129.0555688,FALSE -4221000,6530000,강원특별자치도,태백시,37.17231241,128.9800726,FALSE 4220000,6530000,강원도,태백시,37.17231241,128.9800726,FALSE -4231000,6530000,강원특별자치도,속초시,38.17603138,128.519541,FALSE 4230000,6530000,강원도,속초시,38.17603138,128.519541,FALSE -4241000,6530000,강원특별자치도,삼척시,37.27748089,129.12171,FALSE 4240000,6530000,강원도,삼척시,37.27748089,129.12171,FALSE -4251000,6530000,강원특별자치도,홍천군,37.74504907,128.0742609,FALSE 4250000,6530000,강원도,홍천군,37.74504907,128.0742609,FALSE -4261000,6530000,강원특별자치도,횡성군,37.50914207,128.0770674,FALSE 4260000,6530000,강원도,횡성군,37.50914207,128.0770674,FALSE -4271000,6530000,강원특별자치도,영월군,37.20411361,128.500296,FALSE 4270000,6530000,강원도,영월군,37.20411361,128.500296,FALSE -4281000,6530000,강원특별자치도,평창군,37.55683921,128.48259,FALSE 4280000,6530000,강원도,평창군,37.55683921,128.48259,FALSE -4291000,6530000,강원특별자치도,정선군,37.37868629,128.7390632,FALSE 4290000,6530000,강원도,정선군,37.37868629,128.7390632,FALSE -4301000,6530000,강원특별자치도,철원군,38.23908523,127.3989244,FALSE 4300000,6530000,강원도,철원군,38.23908523,127.3989244,FALSE -4311000,6530000,강원특별자치도,화천군,38.13842628,127.6851657,FALSE 4310000,6530000,강원도,화천군,38.13842628,127.6851657,FALSE -4321000,6530000,강원특별자치도,양구군,38.17560879,128.0002064,FALSE 4320000,6530000,강원도,양구군,38.17560879,128.0002064,FALSE -4331000,6530000,강원특별자치도,인제군,38.06460026,128.2647272,FALSE 4330000,6530000,강원도,인제군,38.06460026,128.2647272,FALSE -4341000,6530000,강원특별자치도,고성군,38.36275363,128.4111555,FALSE 4340000,6530000,강원도,고성군,38.36275363,128.4111555,FALSE 5420000,6480000,경상남도,고성군,35.01630447,128.2906632,FALSE 5720000,6430000,충청북도,청주시 상당구,36.59211242,127.5848802,FALSE @@ -189,37 +172,21 @@ 4600000,6440000,충청남도,홍성군,36.57009431,126.6258536,FALSE 4610000,6440000,충청남도,예산군,36.67062867,126.7843109,FALSE 4620000,6440000,충청남도,태안군,36.7036613,126.2809571,FALSE -4641000,6540000,전북특별자치도,전주시,35.79209428,127.1195036,FALSE 4640000,6540000,전라북도,전주시,35.79209428,127.1195036,FALSE -4651000,6540000,전북특별자치도,전주시 완산구,35.79209428,127.1195036,FALSE 4650000,6540000,전라북도,전주시 완산구,35.79209428,127.1195036,FALSE -4661000,6540000,전북특별자치도,전주시 덕진구,35.85870118,127.1129157,FALSE 4660000,6540000,전라북도,전주시 덕진구,35.85870118,127.1129157,FALSE -4671000,6540000,전북특별자치도,군산시,35.95043894,126.7260152,FALSE 4670000,6540000,전라북도,군산시,35.95043894,126.7260152,FALSE -4681000,6540000,전북특별자치도,익산시,36.02310555,126.9895102,FALSE 4680000,6540000,전라북도,익산시,36.02310555,126.9895102,FALSE -4691000,6540000,전북특별자치도,정읍시,35.60262466,126.9058575,FALSE 4690000,6540000,전라북도,정읍시,35.60262466,126.9058575,FALSE -4701000,6540000,전북특별자치도,남원시,35.4225448,127.4418897,FALSE 4700000,6540000,전라북도,남원시,35.4225448,127.4418897,FALSE -4711000,6540000,전북특별자치도,김제시,35.80671644,126.8948857,FALSE 4710000,6540000,전라북도,김제시,35.80671644,126.8948857,FALSE -4721000,6540000,전북특별자치도,완주군,35.91861444,127.2151146,FALSE 4720000,6540000,전라북도,완주군,35.91861444,127.2151146,FALSE -4731000,6540000,전북특별자치도,진안군,35.82880745,127.4300354,FALSE 4730000,6540000,전라북도,진안군,35.82880745,127.4300354,FALSE -4741000,6540000,전북특별자치도,무주군,35.93936736,127.7129531,FALSE 4740000,6540000,전라북도,무주군,35.93936736,127.7129531,FALSE -4751000,6540000,전북특별자치도,장수군,35.65746098,127.5442641,FALSE 4750000,6540000,전라북도,장수군,35.65746098,127.5442641,FALSE -4761000,6540000,전북특별자치도,임실군,35.59820204,127.2366472,FALSE 4760000,6540000,전라북도,임실군,35.59820204,127.2366472,FALSE -4771000,6540000,전북특별자치도,순창군,35.4336343,127.090087,FALSE 4770000,6540000,전라북도,순창군,35.4336343,127.090087,FALSE -4781000,6540000,전북특별자치도,고창군,35.44816757,126.6160462,FALSE 4780000,6540000,전라북도,고창군,35.44816757,126.6160462,FALSE -4791000,6540000,전북특별자치도,부안군,35.6779229,126.6443774,FALSE 4790000,6540000,전라북도,부안군,35.6779229,126.6443774,FALSE 4800000,6460000,전라남도,목포시,34.80376416,126.3918353,FALSE 4810000,6460000,전라남도,여수시,34.69617175,127.6532031,FALSE @@ -291,9 +258,7 @@ 5460000,6480000,경상남도,함양군,35.55160171,127.7220411,FALSE 5470000,6480000,경상남도,거창군,35.73255219,127.9041696,FALSE 5480000,6480000,경상남도,합천군,35.57657745,128.1415437,FALSE -5490000,6500000,제주도,제주시,33.44220188,126.5292476,FALSE 6510000,6500000,제주특별자치도,제주시,33.44220188,126.5292476,FALSE -5500000,6500000,제주도,서귀포시,33.32504027,126.5810857,FALSE 6520000,6500000,제주특별자치도,서귀포시,33.32504027,126.5810857,FALSE 5690000,5690000,세종특별자치시,세종특별자치시,36.56072897,127.258722,FALSE 6530000,6530000,강원특별자치도,강원특별자치도,37.71904264,128.3008969,TRUE @@ -312,4 +277,4 @@ 6540000,6540000,전북특별자치도,전북특별자치도,35.71581062,127.1427384,TRUE 6500000,6500000,제주특별자치도,제주특별자치도,33.38699923,126.5538395,TRUE 6440000,6440000,충청남도,충청남도,36.52940199,126.8497393,TRUE -6430000,6430000,충청북도,충청북도,36.73877678,127.8313457,TRUE \ No newline at end of file +6430000,6430000,충청북도,충청북도,36.73877678,127.8313457,TRUE From b41a6deab7537cf02d84b57b2e6cfe77bffe2c5d Mon Sep 17 00:00:00 2001 From: 5win <94297900+5win@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:06:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EB=A6=AC=EB=B7=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - score를 int -> double 변경 - 리뷰 기능 동작 오류 수정 --- .../com/gamsa/common/config/WebConfig.java | 3 +- .../review/controller/ReviewController.java | 12 ++++--- .../java/com/gamsa/review/domain/Answer.java | 2 +- .../java/com/gamsa/review/domain/Review.java | 5 +-- .../gamsa/review/dto/AnswerSaveRequest.java | 2 +- .../gamsa/review/entity/AnswerJpaEntity.java | 23 +++++++++--- .../gamsa/review/entity/ReviewJpaEntity.java | 22 +++++++++--- .../gamsa/review/service/ReviewService.java | 36 +++++++++---------- 8 files changed, 68 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/gamsa/common/config/WebConfig.java b/src/main/java/com/gamsa/common/config/WebConfig.java index 5b87dee..c93583c 100644 --- a/src/main/java/com/gamsa/common/config/WebConfig.java +++ b/src/main/java/com/gamsa/common/config/WebConfig.java @@ -17,7 +17,8 @@ public class WebConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(jwtInterceptor) .addPathPatterns("/api/v1/avatars/**") - .addPathPatterns("/api/v1/histories/**"); + .addPathPatterns("/api/v1/histories/**") + .addPathPatterns("/api/v1/reviews"); } @Override diff --git a/src/main/java/com/gamsa/review/controller/ReviewController.java b/src/main/java/com/gamsa/review/controller/ReviewController.java index 1df238c..5913706 100644 --- a/src/main/java/com/gamsa/review/controller/ReviewController.java +++ b/src/main/java/com/gamsa/review/controller/ReviewController.java @@ -6,12 +6,16 @@ import com.gamsa.review.dto.ReviewSaveRequest; import com.gamsa.review.service.ReviewService; import jakarta.servlet.http.HttpServletRequest; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController @@ -22,7 +26,7 @@ public class ReviewController { @PostMapping public ResponseEntity saveReview(@RequestBody ReviewSaveRequest saveRequest, - HttpServletRequest request) { + HttpServletRequest request) { Long userId = ExtractUserIdFromJwt.extract(request); reviewService.saveReview(userId, saveRequest); diff --git a/src/main/java/com/gamsa/review/domain/Answer.java b/src/main/java/com/gamsa/review/domain/Answer.java index 3c69b71..7961ca0 100644 --- a/src/main/java/com/gamsa/review/domain/Answer.java +++ b/src/main/java/com/gamsa/review/domain/Answer.java @@ -7,6 +7,6 @@ @Builder public class Answer { private Long answerId; - private int score; + private double score; private Question question; } diff --git a/src/main/java/com/gamsa/review/domain/Review.java b/src/main/java/com/gamsa/review/domain/Review.java index ba82f6f..c75a51f 100644 --- a/src/main/java/com/gamsa/review/domain/Review.java +++ b/src/main/java/com/gamsa/review/domain/Review.java @@ -2,20 +2,17 @@ import com.gamsa.activity.domain.Activity; import com.gamsa.activity.domain.Institute; -import com.gamsa.avatar.domain.Avatar; import com.gamsa.history.domain.History; +import java.util.List; import lombok.Builder; import lombok.Getter; -import java.util.List; - @Getter @Builder public class Review { private Long reviewId; private List answers; - private Avatar avatar; private Activity activity; private Institute institute; private History history; diff --git a/src/main/java/com/gamsa/review/dto/AnswerSaveRequest.java b/src/main/java/com/gamsa/review/dto/AnswerSaveRequest.java index e7738f8..cfc04c2 100644 --- a/src/main/java/com/gamsa/review/dto/AnswerSaveRequest.java +++ b/src/main/java/com/gamsa/review/dto/AnswerSaveRequest.java @@ -8,5 +8,5 @@ public class AnswerSaveRequest { private final Integer questionId; - private final int score; + private final double score; } diff --git a/src/main/java/com/gamsa/review/entity/AnswerJpaEntity.java b/src/main/java/com/gamsa/review/entity/AnswerJpaEntity.java index bf9da5f..7109470 100644 --- a/src/main/java/com/gamsa/review/entity/AnswerJpaEntity.java +++ b/src/main/java/com/gamsa/review/entity/AnswerJpaEntity.java @@ -1,8 +1,20 @@ package com.gamsa.review.entity; import com.gamsa.review.domain.Answer; -import jakarta.persistence.*; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Getter @Builder @@ -17,8 +29,11 @@ public class AnswerJpaEntity { @Column(name = "answer_id") private Long answerId; - @Column - private int score; + @Column(name = "score") + private double score; + + @Column(name = "review_id") + private Long reviewId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "question_id") diff --git a/src/main/java/com/gamsa/review/entity/ReviewJpaEntity.java b/src/main/java/com/gamsa/review/entity/ReviewJpaEntity.java index 18d0896..17210c5 100644 --- a/src/main/java/com/gamsa/review/entity/ReviewJpaEntity.java +++ b/src/main/java/com/gamsa/review/entity/ReviewJpaEntity.java @@ -4,10 +4,23 @@ import com.gamsa.activity.entity.InstituteJpaEntity; import com.gamsa.history.entity.HistoryJpaEntity; import com.gamsa.review.domain.Review; -import jakarta.persistence.*; -import lombok.*; - +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Getter @Builder @@ -22,7 +35,8 @@ public class ReviewJpaEntity { @Column(name = "review_id") private Long reviewId; - @OneToMany + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "review_id") private List answers; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/com/gamsa/review/service/ReviewService.java b/src/main/java/com/gamsa/review/service/ReviewService.java index 26b315a..ab62a70 100644 --- a/src/main/java/com/gamsa/review/service/ReviewService.java +++ b/src/main/java/com/gamsa/review/service/ReviewService.java @@ -13,14 +13,13 @@ import com.gamsa.review.repository.QuestionRepository; import com.gamsa.review.repository.ReviewRepository; import com.gamsa.user.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import java.math.BigDecimal; import java.util.List; import java.util.NoSuchElementException; import java.util.OptionalDouble; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service @@ -48,15 +47,6 @@ public void saveReview(Long userId, ReviewSaveRequest saveRequest) { history.changeReviewed(true); historyRepository.save(history); - // save review - Review review = Review.builder() - .avatar(avatar) - .history(history) - .institute(activity.getInstitute()) - .build(); - - reviewRepository.save(review); - // save answers List answers = saveRequest.getAnswers().stream() .map(answer -> { @@ -71,15 +61,25 @@ public void saveReview(Long userId, ReviewSaveRequest saveRequest) { .toList(); answers.forEach(answerRepository::save); + + // save review + Review review = Review.builder() + .activity(activity) + .answers(answers) + .history(history) + .institute(activity.getInstitute()) + .build(); + + reviewRepository.save(review); } public BigDecimal getAverageScore(long instituteId, int questionId) { OptionalDouble averageScore = reviewRepository.findReviews(instituteId, questionId) - .stream() - .flatMap(review -> review.getAnswers().stream()) - .filter(answer -> answer.getQuestion().getQuestionId() == questionId) - .mapToInt(Answer::getScore) - .average(); + .stream() + .flatMap(review -> review.getAnswers().stream()) + .filter(answer -> answer.getQuestion().getQuestionId() == questionId) + .mapToDouble(Answer::getScore) + .average(); if (averageScore.isPresent()) { return BigDecimal.valueOf(averageScore.getAsDouble());