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

version/v0.1.4 #22

Merged
merged 13 commits into from
May 20, 2024
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dependencies {
// WebSocket
implementation 'org.springframework.boot:spring-boot-starter-websocket'

// 이미지 검사
implementation 'org.apache.tika:tika-core:1.4'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.1.3
version=0.1.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.swygbro.trip.backend.domain.admin.controller;

import com.swygbro.trip.backend.domain.admin.dao.GuideProductDao;
import com.swygbro.trip.backend.domain.admin.dao.ReservationDao;
import com.swygbro.trip.backend.domain.admin.dao.ReviewDao;
import com.swygbro.trip.backend.domain.admin.dto.GuideProductDetailDto;
import com.swygbro.trip.backend.domain.admin.dto.ReservationDetailDto;
import com.swygbro.trip.backend.domain.admin.dto.ReviewDetailDto;
import com.swygbro.trip.backend.domain.guideProduct.application.GuideProductService;
import com.swygbro.trip.backend.domain.reservation.aplication.ReservationService;
import com.swygbro.trip.backend.domain.review.application.ReviewService;
import com.swygbro.trip.backend.domain.user.application.UserService;
import com.swygbro.trip.backend.domain.user.domain.Gender;
import com.swygbro.trip.backend.domain.user.domain.Nationality;
import com.swygbro.trip.backend.domain.user.domain.SignUpType;
import com.swygbro.trip.backend.domain.user.dto.UserDetailDto;
import com.swygbro.trip.backend.global.status.PayStatus;
import com.swygbro.trip.backend.global.status.ReservationStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/v1/admin")
@RequiredArgsConstructor
public class AdminController {

private final UserService userService;
private final GuideProductService guideProductService;
private final ReservationService reservationService;
private final ReviewService reviewService;

private final GuideProductDao guideProductDao;
private final ReservationDao reservationDao;
private final ReviewDao reviewDao;


@GetMapping("/users")
public Page<UserDetailDto> getUsersDetails(@RequestParam(defaultValue = "0") int offset,
@RequestParam(defaultValue = "10") int limit,
@RequestParam(defaultValue = "id") String sort,
@RequestParam(required = false) String email,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String name,
@RequestParam(required = false) String phone,
@RequestParam(required = false) String location,
@RequestParam(required = false) Nationality nationality,
@RequestParam(required = false) LocalDate birthdate,
@RequestParam(required = false) Gender gender,
@RequestParam(required = false) SignUpType signUpType) {

return userService.getUsersByFilter(PageRequest.of(offset, limit, Sort.by(sort)), email,
nickname,
name,
phone,
location,
nationality,
birthdate,
gender,
signUpType);
}

@GetMapping("/guideProducts")
public Page<GuideProductDetailDto> getGuideProductsByFilter(@RequestParam(defaultValue = "0") int offset,
@RequestParam(defaultValue = "10") int limit,
@RequestParam(defaultValue = "id") String sort,
@RequestParam(required = false) Long id,
@RequestParam(required = false) String title,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String locationName) {
return guideProductDao.findGuideProductsByFilter(PageRequest.of(offset, limit, Sort.by(sort)), id, title, nickname, locationName);
}

@GetMapping("/reservations")
public Page<ReservationDetailDto> getReservationsByFilter(@RequestParam(required = false, defaultValue = "0") int offset,
@RequestParam(required = false, defaultValue = "10") int limit,
@RequestParam(required = false, defaultValue = "id") String sort,
@RequestParam(required = false) Long id,
@RequestParam(required = false) String merchantUid,
@RequestParam(required = false) Long productId,
@RequestParam(required = false) String client,
@RequestParam(required = false) String guide,
@RequestParam(required = false) PayStatus payStatus,
@RequestParam(required = false) ReservationStatus reservationStatus) {
return reservationDao.findReservationsByFilter(PageRequest.of(offset, limit, Sort.by(sort)), id, merchantUid, productId, client, guide, payStatus, reservationStatus);
}

@GetMapping("/reviews")
public Page<ReviewDetailDto> getReviewsByFilter(@RequestParam(defaultValue = "0") int offset,
@RequestParam(defaultValue = "10") int limit,
@RequestParam(defaultValue = "id") String sort,
@RequestParam(required = false) Long id,
@RequestParam(required = false) String reviewer,
@RequestParam(required = false) Long guideProductId) {
return reviewDao.findReviewsByFilter(PageRequest.of(offset, limit, Sort.by(sort)), id, reviewer, guideProductId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.swygbro.trip.backend.domain.admin.dao;

import com.swygbro.trip.backend.domain.admin.dto.GuideProductDetailDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface GuideProductDao {
Page<GuideProductDetailDto> findGuideProductsByFilter(Pageable pageable,
Long id,
String title,
String nickname,
String locationName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.swygbro.trip.backend.domain.admin.dao;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.swygbro.trip.backend.domain.admin.dto.GuideProductDetailDto;
import com.swygbro.trip.backend.domain.guideProduct.domain.QGuideProduct;
import com.swygbro.trip.backend.domain.user.domain.QUser;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.Optional;

@Repository
@RequiredArgsConstructor
public class GuideProductImpl implements GuideProductDao {
private final JPAQueryFactory queryFactory;

public Page<GuideProductDetailDto> findGuideProductsByFilter(Pageable pageable,
Long id,
String title,
String nickname,
String locationName) {
QUser qUser = QUser.user;
QGuideProduct qGuideProduct = QGuideProduct.guideProduct;

BooleanBuilder builder = createBooleanBuilder(id, title, nickname, locationName);


var guideProducts = queryFactory
.select(Projections.fields(GuideProductDetailDto.class,
qGuideProduct.id,
qGuideProduct.title,
qUser.nickname.as("nickname"),
qGuideProduct.description,
qGuideProduct.locationName,
qGuideProduct.price,
qGuideProduct.guideStart,
qGuideProduct.guideEnd,
qGuideProduct.guideTime,
qGuideProduct.createdAt,
qGuideProduct.updatedAt))
.from(qGuideProduct)
.where(builder)
.leftJoin(qGuideProduct.user, qUser)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

long total = Optional.ofNullable(queryFactory.select(qGuideProduct.count())
.from(qGuideProduct)
.where(builder)
.fetchOne()).orElse(0L);

return new PageImpl<>(guideProducts, pageable, total);
}

private BooleanBuilder createBooleanBuilder(Long id,
String title,
String nickname,
String locationName) {
BooleanBuilder builder = new BooleanBuilder();
if (id != null) {
builder.and(QGuideProduct.guideProduct.id.eq(id));
}

if (StringUtils.hasText(title)) {
builder.and(QGuideProduct.guideProduct.title.contains(title));
}

if (StringUtils.hasText(nickname)) {
builder.and(QUser.user.nickname.contains(nickname));
}

if (StringUtils.hasText(locationName)) {
builder.and(QGuideProduct.guideProduct.locationName.contains(locationName));
}

return builder;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.swygbro.trip.backend.domain.admin.dao;

import com.swygbro.trip.backend.domain.admin.dto.ReservationDetailDto;
import com.swygbro.trip.backend.global.status.PayStatus;
import com.swygbro.trip.backend.global.status.ReservationStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface ReservationDao {
Page<ReservationDetailDto> findReservationsByFilter(Pageable pageable,
Long id,
String merchantUid,
Long productId,
String client,
String guide,
PayStatus payStatus,
ReservationStatus reservationStatus);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.swygbro.trip.backend.domain.admin.dao;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.swygbro.trip.backend.domain.admin.dto.ReservationDetailDto;
import com.swygbro.trip.backend.domain.guideProduct.domain.QGuideProduct;
import com.swygbro.trip.backend.domain.reservation.domain.QReservation;
import com.swygbro.trip.backend.domain.user.domain.QUser;
import com.swygbro.trip.backend.global.status.PayStatus;
import com.swygbro.trip.backend.global.status.ReservationStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Optional;

@Repository
@RequiredArgsConstructor
public class ReservationDaoImpl implements ReservationDao {

QReservation qReservation = QReservation.reservation;
QGuideProduct qGuideProduct = QGuideProduct.guideProduct;
QUser qUser = QUser.user;

private final JPAQueryFactory queryFactory;

public Page<ReservationDetailDto> findReservationsByFilter(Pageable pageable,
Long id,
String merchantUid,
Long productId,
String client,
String guide,
PayStatus payStatus,
ReservationStatus reservationStatus) {

QUser qUserClient = new QUser("client");
QUser qUserGuide = new QUser("guide");

BooleanBuilder builder = createBooleanBuilder(id, merchantUid, productId, client, guide, payStatus, reservationStatus);

List<ReservationDetailDto> reservations = queryFactory
.select(Projections.fields(ReservationDetailDto.class,
qReservation.id,
qReservation.merchantUid,
qUserClient.nickname.as("client"),
qUserGuide.nickname.as("guide"),
qReservation.product.id.as("guideProductId"),
qReservation.guideStart,
qReservation.guideEnd,
qReservation.personnel,
qReservation.price,
qReservation.paymentStatus,
qReservation.reservationStatus,
qReservation.createdAt,
qReservation.updatedAt))
.from(qReservation)
.where(builder)
.leftJoin(qReservation.client, qUserClient)
.leftJoin(qReservation.guide, qUserGuide)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

long total = Optional.ofNullable(queryFactory.select(qReservation.count())
.from(qReservation)
.where(builder)
.leftJoin(qReservation.client, qUserClient)
.leftJoin(qReservation.guide, qUserGuide)
.fetchOne()).orElse(0L);

return new PageImpl<>(reservations, pageable, total);
}


private BooleanBuilder createBooleanBuilder(Long id,
String merchantUid,
Long productId,
String client,
String guide,
PayStatus payStatus,
ReservationStatus reservationStatus) {


BooleanBuilder builder = new BooleanBuilder();
if (id != null) {
builder.and(qReservation.id.eq(id));
}
if (StringUtils.hasText(merchantUid)) {
builder.and(qReservation.merchantUid.eq(merchantUid));
}
if (productId != null) {
builder.and(qReservation.product.id.eq(productId));
}
if (StringUtils.hasText(client)) {
builder.and(qReservation.client.nickname.eq(client));
}
if (StringUtils.hasText(guide)) {
builder.and(qReservation.guide.nickname.eq(guide));
}
if (payStatus != null) {
builder.and(qReservation.paymentStatus.eq(payStatus));
}
if (reservationStatus != null) {
builder.and(qReservation.reservationStatus.eq(reservationStatus));
}

return builder;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.swygbro.trip.backend.domain.admin.dao;

import com.swygbro.trip.backend.domain.admin.dto.ReviewDetailDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface ReviewDao {
Page<ReviewDetailDto> findReviewsByFilter(Pageable pageable,
Long id,
String reviewer,
Long guideProductId);
}
Loading