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

Feature/place #39

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5c47f64
feat: Add manual company registration API
im-gnar Aug 13, 2022
ac05a75
feat: Add manual company registration API
im-gnar Aug 13, 2022
7c89d73
Merge remote-tracking branch 'origin/feature/place' into feature/place
im-gnar Aug 17, 2022
23a4e40
Merge branch 'develop' of https://github.com/hometerview/Server into …
im-gnar Aug 17, 2022
442ede4
feat: Add register company endpoint and duplication check method, mod…
im-gnar Aug 19, 2022
8250016
feat: Add search API
im-gnar Aug 19, 2022
22f8154
feat: Enable Mongo audit, apply missing changes
im-gnar Aug 19, 2022
8899ef5
Merge branch 'feature/review' of https://github.com/hometerview/Serve…
im-gnar Sep 19, 2022
92a06dd
refactor: Modify dto class name
im-gnar Oct 12, 2022
67d5300
refactor: Modify id field type ObjectId -> String
im-gnar Oct 12, 2022
62d4cb4
refactor: Modify CompanyDto.Meta field name specific
im-gnar Oct 12, 2022
8511fca
feat: Add station name to CompanyDto
im-gnar Oct 12, 2022
9f25345
refactor: Modify building total rating field type int -> double
im-gnar Oct 12, 2022
036d6f6
feat: Add String to SearchType converter
im-gnar Oct 12, 2022
8d44742
fix: Modify mongo repository method name
im-gnar Oct 12, 2022
5bffcad
Merge remote-tracking branch 'origin/feature/place' into feature/place
im-gnar Nov 1, 2022
69f121c
Merge branch 'develop' of https://github.com/hometerview/Server into …
im-gnar Nov 8, 2022
be52f60
feat: Modify home review api
im-gnar Jan 23, 2023
35e0bd1
Merge branch 'develop' of https://github.com/hometerview/Server into …
im-gnar Jan 28, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ftw.hometerview.core.domain;

import com.ftw.hometerview.core.util.Constants;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.ftw.hometerview.place.repository.building;

import com.ftw.hometerview.place.domain.Building;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BuildingRepository extends
MongoRepository<Building, String>, BuildingRepositoryCustom {

List<Building> findAllByCity(String city);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public List<BuildingDto.Meta> searchByKeyword(String keyword, Pageable pageable)
return response;
}

public List<String> getBuildingsByCity(String city) {
List<Building> buildings = this.buildingRepository.findAllByCity(city);
return buildings.stream().map(Building::getId).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.ftw.hometerview.core.annotation.NonAuthorized;
import com.ftw.hometerview.core.domain.ResponseEntity;
import com.ftw.hometerview.review.controller.dto.ReviewDto;
import com.ftw.hometerview.review.service.ReviewService;
import com.ftw.hometerview.review.service.ReviewServiceFacade;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,16 +28,17 @@
@RestController
public class ReviewController {

private final ReviewService reviewService;
private final ReviewServiceFacade reviewService;

@Operation(summary = "홈 지역별 리뷰 리스트 조회")
@NonAuthorized
@GetMapping
public ResponseEntity<List<ReviewDto.Meta>> getMainReviews(
@RequestParam(required = false, defaultValue = DEFAULT_KEYWORD) String buildingId,
// 사용처를 명확히 하고 required 조정 필요. 현재 홈화면 용으로 구현되어서 required임
@RequestParam(required = false, defaultValue = DEFAULT_KEYWORD) String companyId,
@RequestParam(required = false, defaultValue = DEFAULT_KEYWORD) String cityId,
@PageableDefault(size = DEFAULT_PAGE_SIZE) Pageable pageable) {
var reviewList = this.reviewService.getHomeReviewList(buildingId, cityId, pageable);
var reviewList = this.reviewService.getHomeReviewList(companyId, cityId, pageable);
return ResponseEntity.successResponse(reviewList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface ReviewRepository extends MongoRepository<Review, String> {

List<Review> getReviewByBuildingId(String buildingId, Pageable pageable);

List<Review> getReviewByCompanyId(String companyId, Pageable pageable);

List<Review> getReviewByMemberId(String memberId, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,83 @@
package com.ftw.hometerview.review.service;

import static com.ftw.hometerview.core.interceptor.AuthUtil.getCurrentMemberId;

import com.ftw.hometerview.core.domain.ResponseType;
import com.ftw.hometerview.core.exception.BadRequestException;
import com.ftw.hometerview.core.exception.NotFoundException;
import com.ftw.hometerview.review.controller.dto.ReviewDto;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Create;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Detail;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Meta;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Modify;
import com.ftw.hometerview.review.domain.Review;
import com.ftw.hometerview.review.repository.ReviewRepository;
import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class ReviewService {


private final ReviewRepository reviewRepository;

public List<Meta> getHomeReviewList(String companyId, Pageable pageable, List<String> buildingIds) {
List<Review> reviews = this.reviewRepository.getReviewByCompanyId(companyId, pageable);
return reviews.stream()
.filter(review -> buildingIds.contains(review.getBuildingId()))
.map(Review::toMeta)
.toList();
}

public interface ReviewService {
public List<Detail> getBuildingReviewList(String buildingId, Pageable pageable) {
List<Review> reviews = this.reviewRepository.getReviewByBuildingId(buildingId, pageable);
List<ReviewDto.Detail> response = reviews.stream().map(Review::toDetail).toList();
return response;
}

List<ReviewDto.Meta> getHomeReviewList(String buildingId, String cityId, Pageable pageable);
public List<Detail> getMyReviewList(Pageable pageable) {
List<Review> reviews = this.reviewRepository.getReviewByMemberId(getCurrentMemberId(),
pageable);
List<ReviewDto.Detail> response = reviews.stream().map(Review::toDetail).toList();
return response;
}

List<ReviewDto.Detail> getBuildingReviewList(String buildingId, Pageable pageable);
public void registerReview(Create req) {
Review review = req.toReview();
setCertification(review);
this.reviewRepository.save(review);
}

List<ReviewDto.Detail> getMyReviewList(Pageable pageable);
public void modifyReview(Modify req) {
Review review = getReviewWithAuthCheck(req.getReviewId());
review.modify(req);
setCertification(review);
this.reviewRepository.save(review);
}

void registerReview(ReviewDto.Create req);
private void setCertification(Review review) {
// TODO:: member service, feign... param: getCurrentMemberId, response: String
List<String> cert = Collections.emptyList();
review.setCertification(cert);
}

void modifyReview(ReviewDto.Modify req);
public void deleteReview(String reviewId) {
Review review = getReviewWithAuthCheck(reviewId);
this.reviewRepository.delete(review);
}

void deleteReview(String reviewId);
private Review getReviewWithAuthCheck(String reviewId) {
Review review = this.reviewRepository.findById(reviewId)
.orElseThrow(() -> new NotFoundException(
ResponseType.REVIEW_NOT_EXIST));
if (!review.getMemberId().equals(getCurrentMemberId())) {
throw new BadRequestException(ResponseType.REVIEW_NOT_AUTHOR);
}
return review;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.ftw.hometerview.review.service;

import com.ftw.hometerview.place.service.BuildingService;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Create;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Detail;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Meta;
import com.ftw.hometerview.review.controller.dto.ReviewDto.Modify;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class ReviewServiceFacade {

private final ReviewService reviewService;
private final BuildingService buildingService;

public List<Meta> getHomeReviewList(String companyId, String cityId, Pageable pageable) {
List<String> buildingIds = this.buildingService.getBuildingsByCity(cityId);
return this.reviewService.getHomeReviewList(companyId, pageable, buildingIds);
}

public List<Detail> getBuildingReviewList(String buildingId, Pageable pageable) {
return this.reviewService.getBuildingReviewList(buildingId, pageable);
}

public List<Detail> getMyReviewList(Pageable pageable) {
return this.reviewService.getMyReviewList(pageable);
}

public void registerReview(Create req) {
this.reviewService.registerReview(req);
}

public void modifyReview(Modify req) {
this.reviewService.modifyReview(req);
}

public void deleteReview(String reviewId) {
this.reviewService.deleteReview(reviewId);
}
}

This file was deleted.