Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: 리뷰 관련 수정 버전 배포 #87

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/main/java/com/gamsa/common/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/gamsa/review/controller/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gamsa/review/domain/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Builder
public class Answer {
private Long answerId;
private int score;
private double score;
private Question question;
}
5 changes: 1 addition & 4 deletions src/main/java/com/gamsa/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Answer> answers;
private Avatar avatar;
private Activity activity;
private Institute institute;
private History history;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gamsa/review/dto/AnswerSaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public class AnswerSaveRequest {

private final Integer questionId;
private final int score;
private final double score;
}
23 changes: 19 additions & 4 deletions src/main/java/com/gamsa/review/entity/AnswerJpaEntity.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/com/gamsa/review/entity/ReviewJpaEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AnswerJpaEntity> answers;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/gamsa/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Answer> answers = saveRequest.getAnswers().stream()
.map(answer -> {
Expand All @@ -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());
Expand Down
37 changes: 1 addition & 36 deletions src/main/resources/district_and_coordinate_kr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
6430000,6430000,충청북도,충청북도,36.73877678,127.8313457,TRUE
Loading