Skip to content
Open
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
34 changes: 34 additions & 0 deletions UserCommentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.unicon.rebit.yongginae.userComment;

import com.unicon.rebit.yongginae.configure.response.DataResponse;
import com.unicon.rebit.yongginae.configure.response.ResponseService;
import com.unicon.rebit.yongginae.store.StoreService;
import com.unicon.rebit.yongginae.store.dto.StoreCategoryRes;
import com.unicon.rebit.yongginae.store.dto.StoreRes;
import com.unicon.rebit.yongginae.userComment.dto.UserCommentReq;
import com.unicon.rebit.yongginae.userComment.dto.UserCommentRes;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class UserCommentController {
private final UserCommentService userCommentService;
private final UserCommentRepository userCommentRepository;
private final ResponseService responseService;

@GetMapping("comment/user/{user_id}")
public DataResponse<List<UserCommentRes>> getComment(@PathVariable("user_id") Long id){
List<UserCommentRes> lists = userCommentService.findUserComment(id);
return responseService.getDataResponse(lists);

}

@PostMapping("/comments")
public DataResponse<Long> addComment(@RequestBody UserCommentReq userCommentReq) {
Long comment_id = userCommentService.addComment(userCommentReq);
return responseService.getDataResponse(comment_id);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/unicon/rebit/yongginae/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class Store {

private String store_photo;

private double starAvg;

private int reviewNum;

@OneToMany(mappedBy = "store")
private List<Review> review = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.unicon.rebit.yongginae.store;

import com.unicon.rebit.yongginae.configure.response.CommonResponse;
import com.unicon.rebit.yongginae.configure.response.DataResponse;
import com.unicon.rebit.yongginae.configure.response.ResponseService;
import com.unicon.rebit.yongginae.store.dto.*;
import lombok.RequiredArgsConstructor;
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.RestController;

import java.util.List;
Expand Down Expand Up @@ -34,7 +36,7 @@ public DataResponse<StoreAddressRes> getStoreAddress(@PathVariable("store_id") L
return responseService.getDataResponse(res);
}

// 마크용 주소 검색
// 마커용 주소 검색
@GetMapping("/store/mark/{search}")
public DataResponse<List<StoreAroundAddressRes>> getStoreAroundAddress(@PathVariable("search") String search) {
List<StoreAroundAddressRes> stores = storeService.findAroundAddress(search);
Expand All @@ -54,4 +56,33 @@ public DataResponse<StoreSearchRes> getStoreDetailInfo (@PathVariable("store_id"
StoreSearchRes res = storeService.findStoreDetail(store_id);
return responseService.getDataResponse(res);
}

// 가게 검색2 - 반환 값 변경
@GetMapping("/store/searchName/{search}")
public DataResponse<List<StoreSearchNameRes>> getStoreName (@PathVariable("search") String search) {
List<StoreSearchNameRes> stores = storeService.findStoreName(search);
return responseService.getDataResponse(stores);
}

// 포장시 포인트 증가 로직
@PostMapping("/store/takeout/{user_id}")
public CommonResponse postUserWithPoint(@PathVariable(value = "user_id") Long user_id) {
int point = storeService.postUserWithPoint(user_id);
return responseService.getDataResponse(point);
}

// 리뷰 리스트 반환
@GetMapping("/store/reviews/{store_id}")
public DataResponse<List<StoreReviewsRes>> getReviews (@PathVariable("store_id") Long store_id) {
List<StoreReviewsRes> stores = storeService.findReviews(store_id);
return responseService.getDataResponse(stores);
}

// 가게 전체 정보 반환
@GetMapping("/store")
public DataResponse<List<StoreAllInfoRes>> getAllStoreInfo() {
List<StoreAllInfoRes> res = storeService.findAll();
return responseService.getDataResponse(res);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public Store findStoreDetail(Long storeId) {
.setParameter("id", storeId)
.getSingleResult();
}

public List<Store> findAll() {
return em.createQuery("SELECT s FROM Store s", Store.class)
.getResultList();
}

}
36 changes: 35 additions & 1 deletion src/main/java/com/unicon/rebit/yongginae/store/StoreService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.unicon.rebit.yongginae.store;

import com.unicon.rebit.yongginae.configure.response.exception.CustomException;
import com.unicon.rebit.yongginae.configure.response.exception.CustomExceptionStatus;
import com.unicon.rebit.yongginae.review.ReviewSearchRes;
import com.unicon.rebit.yongginae.store.dto.*;
import com.unicon.rebit.yongginae.user.User;
import com.unicon.rebit.yongginae.user.UserRepository;
import com.unicon.rebit.yongginae.userComment.UserCommentDao;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -15,7 +20,8 @@
public class StoreService {

private final StoreRepository storeRepository;
// private final Store store;
private final UserRepository userRepository;
private final UserCommentDao userCommentDao;

public StoreRes findOne(Long storeId) {
Store store = storeRepository.findOne(storeId);
Expand Down Expand Up @@ -46,4 +52,32 @@ public StoreSearchRes findStoreDetail(Long store_id) {
Store store = storeRepository.findStoreDetail(store_id);
return new StoreSearchRes(store, store.getReview().stream().map(ReviewSearchRes::new).collect(Collectors.toList()));
}

public List<StoreSearchNameRes> findStoreName(String storeName) {
List<Store> stores = storeRepository.findStore(storeName);
return stores.stream().map(store -> new StoreSearchNameRes(store.getStoreName(), store.getId())).collect(Collectors.toList());
}

@Transactional
public int postUserWithPoint(Long id) {
User user = userRepository.findById(id)
.orElseThrow(() -> new CustomException(CustomExceptionStatus.ACCOUNT_NOT_FOUND));
user.postPoint(300);
return user.getPoint();
}

public List<StoreReviewsRes> findReviews(Long store_id) {
try {
List<StoreReviewsRes> reviewList = userCommentDao.selectReviews(store_id);
return reviewList;
} catch (NullPointerException exception) {
exception.printStackTrace();
throw new CustomException(CustomExceptionStatus.ACCOUNT_NOT_FOUND);
}
}

public List<StoreAllInfoRes> findAll() {
List<Store> stores = storeRepository.findAll();
return stores.stream().map(store -> new StoreAllInfoRes(store.getId(), store.getStoreName())).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.unicon.rebit.yongginae.store.dto;

import com.unicon.rebit.yongginae.store.Store;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class StoreAllInfoRes {
private Long storeId;
private String storeName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.unicon.rebit.yongginae.store.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor

public class StoreReviewsRes {
private Long user_id;
private int star;
private LocalDateTime commentDate;
private String photo;
private String commentDetail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.unicon.rebit.yongginae.store.dto;

import com.unicon.rebit.yongginae.store.Store;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class StoreSearchNameRes {
private String storeName;
private Long storeIid;

public StoreSearchNameRes(Store store) {
storeName = store.getAddress();
storeIid = store.getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.unicon.rebit.yongginae.userComment;

import com.unicon.rebit.yongginae.store.dto.StoreReviewsRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.List;

@Repository
public class UserCommentDao {
private JdbcTemplate jdbcTemplate;

@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}

public List<StoreReviewsRes> selectReviews(Long store_id) {

String selectReviewsQuery = "select star, comment_date, u.user_id, c.photo, comment_detail\n" +
"FROM store s\n" +
"LEFT OUTER JOIN user_comment c ON s.store_id = c.store_id\n" +
"LEFT OUTER JOIN user u ON c.user_id = u.user_id\n" +
"where s.store_id = ?";
long selectReviewsParam = store_id;


return this.jdbcTemplate.query(selectReviewsQuery,
(rs, rowNum) -> new StoreReviewsRes(
rs.getLong("user_id"),
rs.getInt("star"),
rs.getTimestamp("comment_date").toLocalDateTime(),
rs.getString("photo"),
rs.getString("comment_detail")),
selectReviewsParam);
}

public Long checkStoreIdExist(Long store_id) {
String checkStoreIdQuery = "select exists(select store_id from user_comment where store_id = ?)";
Long checkStoreIdParams = store_id;
return this.jdbcTemplate.queryForObject(checkStoreIdQuery,
Long.class,
checkStoreIdParams);
}

}