Skip to content

Commit

Permalink
Merge pull request #243 from ODOICHON/dev
Browse files Browse the repository at this point in the history
main <- dev (ODR-5)
  • Loading branch information
dldmsql authored Sep 12, 2023
2 parents 677cb22 + e66bf0f commit 7d3aad6
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ class AdminHouseController(
adminHouseService.updateReviewStatusReject(HouseReviewStatus.APPROVE, rejectForm, redirectAttributes)
return "redirect:/admin/house/apply"
}

@GetMapping("/review")
fun getHousesReview(
@ModelAttribute("searchForm") adminHouseSearch: AdminHouseSearch,
model: Model,
@PageableDefault(size=10, page=0) pageable: Pageable
): String {

// ์Šน์ธ ์š”์ฒญ๋œ ๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก ๋ฐ์ดํ„ฐ
val result = adminHouseService.getSearchReviewHouseResult(adminHouseSearch, pageable)
model.addAttribute("dealList", result)

// ํŽ˜์ด์ง• ๋ฐ์ดํ„ฐ
val pageCom = pageable.pageNumber / 5
model.addAttribute("pageCom", pageCom)
model.addAttribute("filterList", HouseSearchFilter.values())

return "house/houseReview"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.jhouse_server.admin.house.dto

import java.time.LocalDate


data class AdminHouseSearch(
val filter: HouseSearchFilter?,
Expand All @@ -24,6 +26,17 @@ data class AdminHouseDto(
val applied : Boolean
)

data class AdminDealDto(
val id : Long, // dealId
val nickName: String, // buyer
val title: String, // house
val score: Int,
val dealDate : LocalDate,
val contact : String,
val age: String,
val review : String?,
val houseId : Long
)
data class RejectForm(
val houseId : Long?,
val reason : String?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.example.jhouse_server.admin.house.service

import com.example.jhouse_server.admin.house.dto.AdminHouseApplyList
import com.example.jhouse_server.admin.house.dto.AdminHouseDto
import com.example.jhouse_server.admin.house.dto.AdminHouseSearch
import com.example.jhouse_server.admin.house.dto.RejectForm
import com.example.jhouse_server.admin.house.dto.*
import com.example.jhouse_server.domain.house.dto.HouseResOneDto
import com.example.jhouse_server.domain.house.dto.toDto
import com.example.jhouse_server.domain.house.entity.HouseReviewStatus
import com.example.jhouse_server.domain.house.repository.DealRepository
import com.example.jhouse_server.domain.house.repository.DealRepositoryCustom
import com.example.jhouse_server.domain.house.repository.HouseRepository
import com.example.jhouse_server.global.util.findByIdOrThrow
import org.springframework.data.domain.Page
Expand All @@ -18,7 +17,8 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes
@Service
@Transactional(readOnly = true)
class AdminHouseService(
val houseRepository: HouseRepository
val houseRepository: HouseRepository,
val dealRepository: DealRepository,
) {
/**
* ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ž‘์„ฑํ•œ ๋นˆ์ง‘ ๊ฒŒ์‹œ๊ธ€์€ ๋ฌด์กฐ๊ฑด APPLY ์ƒํƒœ
Expand Down Expand Up @@ -62,4 +62,11 @@ class AdminHouseService(

rejectForm.reason?.let { findHouse.rejectEntity(it) }
}

fun getSearchReviewHouseResult(
adminHouseSearch: AdminHouseSearch,
pageable: Pageable
): Page<AdminDealDto> {
return dealRepository.getReviewHouseListWithPaging(adminHouseSearch, pageable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class HouseController(
}

/**
<<<<<<< HEAD
* ๋นˆ์ง‘ ๋งค๋ฌผ ์ƒํƒœ ๋ณ€๊ฒฝ
*
* @author dldmsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package com.example.jhouse_server.domain.house.entity

import com.example.jhouse_server.domain.user.entity.User
import com.example.jhouse_server.global.entity.BaseEntity
import java.time.LocalDate
import java.util.Date
import javax.persistence.*

@Entity
class Deal(

var dealDate: Date,
var dealDate: LocalDate,

var score : Int,

var review: String?,

// TODO OneToOne ๊ด€๊ณ„๋กœ ๊ฐ€์ ธ๊ฐˆ๊นŒ PK๋งŒ FK๋กœ ๊ฐ–๊ณ  ์žˆ์„๊นŒ
var buyerId: Long?,
@OneToOne
var buyer: User,

@OneToOne
var house: House,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.example.jhouse_server.domain.house.entity.House
import org.springframework.data.jpa.repository.JpaRepository
import java.util.Optional

interface DealRepository : JpaRepository<Deal, Long>{
interface DealRepository : JpaRepository<Deal, Long>, DealRepositoryCustom{

fun findByHouseId(houseId: Long) : Optional<Deal>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.jhouse_server.domain.house.repository

import com.example.jhouse_server.admin.house.dto.AdminDealDto
import com.example.jhouse_server.admin.house.dto.AdminHouseSearch
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable

interface DealRepositoryCustom {
fun getReviewHouseListWithPaging(adminHouseSearch: AdminHouseSearch, pageable: Pageable): Page<AdminDealDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.example.jhouse_server.domain.house.repository

import com.example.jhouse_server.admin.house.dto.AdminDealDto
import com.example.jhouse_server.admin.house.dto.AdminHouseSearch
import com.example.jhouse_server.admin.house.dto.HouseSearchFilter
import com.example.jhouse_server.domain.house.entity.Deal
import com.example.jhouse_server.domain.house.entity.HouseReviewStatus
import com.example.jhouse_server.domain.house.entity.QDeal
import com.example.jhouse_server.domain.house.entity.QDeal.deal
import com.example.jhouse_server.domain.house.entity.QHouse
import com.example.jhouse_server.domain.house.entity.QHouse.house
import com.example.jhouse_server.domain.user.entity.QUser
import com.example.jhouse_server.domain.user.entity.QUser.user
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.support.PageableExecutionUtils
import java.time.LocalDate

class DealRepositoryImpl(
private var jpaQueryFactory: JPAQueryFactory
) : DealRepositoryCustom {


override fun getReviewHouseListWithPaging(
adminHouseSearch: AdminHouseSearch,
pageable: Pageable
): Page<AdminDealDto> {
val result = jpaQueryFactory
.selectFrom(QDeal.deal)
.leftJoin(QDeal.deal.house, house)
.leftJoin(QDeal.deal.buyer, user)
.where(
searchFilter(adminHouseSearch),
)
.orderBy(deal.id.asc())
.limit(pageable.pageSize.toLong())
.offset(pageable.offset)
.groupBy(deal)
.fetch()
val countQuery = jpaQueryFactory
.selectFrom(QDeal.deal)
.leftJoin(QDeal.deal.house, house)
.leftJoin(QDeal.deal.buyer, user)
.where(
searchFilter(adminHouseSearch),
)
.orderBy(deal.id.asc())
.groupBy(deal)
return PageableExecutionUtils.getPage(getDealDto(result), pageable) {countQuery.fetch().size.toLong()}
}

private fun getDealDto(result: List<Deal>): MutableList<AdminDealDto> {
val list = mutableListOf<AdminDealDto>()
result.forEach {
list.add(AdminDealDto(it.id, it.buyer.nickName, it.house.title, it.score, it.dealDate, it.buyer.phoneNum, it.buyer.age.value, it.review, it.house.id))
}
return list
}

/**
* ๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€ - ๋นˆ์ง‘ ๊ฑฐ๋ž˜ ์Šน์ธ
* ๊ฒŒ์‹œ๊ธ€ ์ œ๋ชฉ, ๋‚ด์šฉ, ์ž‘์„ฑ์ž ๊ฒ€์ƒ‰
* */
private fun searchFilter(adminHouseSearch: AdminHouseSearch): BooleanExpression? {
return when(adminHouseSearch.filter) {
HouseSearchFilter.TITLE -> QHouse.house.title.contains(adminHouseSearch.keyword)
HouseSearchFilter.CONTENT -> QHouse.house.content.contains(adminHouseSearch.keyword)
HouseSearchFilter.WRITER -> QUser.user.nickName.contains(adminHouseSearch.keyword)
else -> null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.sql.Date
import java.time.LocalDate
import kotlin.jvm.optionals.getOrElse

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -120,8 +122,8 @@ class HouseServiceImpl(
val house = houseRepository.findByIdOrThrow(houseId)
if(user !== house.user) throw ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION)
house.updateDealStatus()
val buyerId = if (dealReqDto.nickName != null && dealReqDto.nickName != "") userRepository.findByNickName(dealReqDto.nickName).get().id else null
val deal = Deal(Date.valueOf(dealReqDto.dealDate), dealReqDto.score, dealReqDto.review, buyerId, house)
val buyer = if (!dealReqDto.nickName.isNullOrBlank()) userRepository.findByNickName(dealReqDto.nickName).get() else throw ApplicationException(INVALID_VALUE_EXCEPTION)
val deal = Deal(LocalDate.parse(dealReqDto.dealDate), dealReqDto.score, dealReqDto.review, buyer, house)
dealRepository.save(deal)
}

Expand Down
149 changes: 149 additions & 0 deletions src/main/resources/templates/house/houseReview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<style>
.container {
max-width: 800px;
}

.dropdown-item:active {
background-color: #FFBE3C;
}
caption {
caption-side: top;
text-align: right;
}
a{
text-decoration: none;
color: #ffc107;
}
</style>
</head>
<body>
<div th:replace="fragments/nav :: nav"/>
<br>
<br>
<div class="container">

<form class="input-group" th:object="${searchForm}">
<div class="input-group row">
<div class="col-1">
</div>
<div class="col-3">
<select class="form-select btn-outline-info" th:field="${searchForm.filter}">
<option selected th:value="${filterList[0]}"
th:text="${filterList[2].value}">๊ฒŒ์‹œ๋ฌผ ์ž‘์„ฑ์ž
</option>
</select>
</div>
<div class="col-5">
<input type="text" class="form-control col-6" th:field="${searchForm.keyword}">
</div>
<div class="col-2" style="float: right;">
<button type="submit" class="btn btn-warning">๊ฒ€์ƒ‰</button>
</div>
<div class="col-1">
</div>
</div>
</form>

<br>

<table class="table" style="vertical-align: middle;">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">๊ฑฐ๋ž˜ ๋งŒ์กฑ๋„</th>
<th scope="col">๊ฑฐ๋ž˜ ๋‚ ์งœ(ํŒ”๋ฆฐ ๋‚ ์งœ)</th>
<th scope="col">๊ตฌ๋งค์ž ์ „ํ™”๋ฒˆํ˜ธ</th>
<th scope="col">๊ตฌ๋งค์ž ๋‹‰๋„ค์ž„</th>
<th scope="col">๊ตฌ๋งค์ž ์—ฐ๋ น</th>
<th scope="col">๊ฑฐ๋ž˜ ํ›„๊ธฐ</th>
<th scope="col">๋นˆ์ง‘ ๊ฒŒ์‹œ๊ธ€ ์ œ๋ชฉ</th>
</tr>
</thead>
<tbody>
<tr th:each="deal : ${dealList.content}">
<td th:text="${deal.id}">
1
</td>
<td th:text="${deal.score}">
5
</td>
<td th:text="${deal.dealDate}">
2023-09-01
</td>
<td th:text="${deal.contact}">
010-0000-0000
</td>
<td th:text="${deal.nickName}">
๊ด€๋ฆฌ์ž1
</td>
<td th:text="${deal.age}">
20๋Œ€
</td>
<td th:text="${deal.review}">
๊ฑฐ๋ž˜ ๋งŒ์กฑํ•ฉ๋‹ˆ๋‹ค.
</td>
<td>
<a th:href="@{/admin/house/{id}(id=${deal.houseId})}" th:text="${deal.title}">๊ฒŒ์‹œ๊ธ€ ์ œ๋ชฉ ๋ณด๊ธฐ</a>
</td>
</tr>
</tbody>
</table>


<nav aria-label="..." style="position:absolute; left: 50%; transform: translateX(-50%); bottom: 6%;">
<ul class="pagination pagination-sm">
<!-- ์ด์ „ ๋ฒ„ํŠผ-->
<li class="page-item" th:if="${pageCom gt 0}">
<a class="page-link"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=((5 *${pageCom})-1))}">
์ด์ „</a>
</li>
<!-- ๋ฐ์ดํ„ฐ ์กด์žฌ x ๊ฒฝ์šฐ-->
<li class="page-item" th:if="${dealList.totalPages eq 0}">
<a class="page-link active" href="#">1</a>
</li>
<!-- ๋งˆ์ง€๋ง‰ ํŽ˜์ด์ง€๊ฐ€ ์†ํ•ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ-->
<li class="page-item" th:if="${dealList.totalPages gt 5*(pageCom + 1) and dealList.totalPages gt 0}"
th:each="num : ${#numbers.sequence(pageCom*5 + 1 , 5*(pageCom + 1))}">
<a class="page-link active" th:if="${num eq dealList.pageable.pageNumber+1}"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=${num}-1)}"
th:text="${num}">num</a>
<a class="page-link" th:unless="${num eq dealList.pageable.pageNumber+1}"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=${num}-1)}"
th:text="${num}">num</a>
</li>
<!-- ๋งˆ์ง€๋ง‰ ํŽ˜์ด์ง€๊ฐ€ ์†ํ•ด์žˆ๋Š” ๊ฒฝ์šฐ-->
<li class="page-item" th:if="${dealList.totalPages le 5*(pageCom + 1) and dealList.totalPages gt 0}"
th:each="num : ${#numbers.sequence(pageCom*5 + 1, dealList.totalPages)}">
<a class="page-link active" th:if="${num eq dealList.pageable.pageNumber+1}"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=${num}-1)}"
th:text="${num}">num</a>
<a class="page-link" th:unless="${num eq dealList.pageable.pageNumber+1}"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=${num}-1)}"
th:text="${num}">num</a>
</li>
<!-- ๋‹ค์Œ ๋ฒ„ํŠผ-->
<li class="page-item" th:if="${(dealList.totalPages / (5.0 *(pageCom+1))) gt 1}">
<a class="page-link"
th:href="@{/admin/house/review(filter=${param.filter}, keyword=${param.keyword}, page=(5 *(${pageCom}+1)))}">
๋‹ค์Œ</a>
</li>
</ul>
</nav>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous">
</script>
<script th:inline="javascript">

</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/main/resources/templates/house/houses.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<!-- ์ด์ „ ๋ฒ„ํŠผ-->
<li class="page-item" th:if="${pageCom gt 0}">
<a class="page-link"
th:href="@{/admin/house(filter=${param.filter}, keyword=${param.keyword}, page=((5 *${pageCom})-1))}">
th:href="@{/admin/house/apply(filter=${param.filter}, keyword=${param.keyword}, page=((5 *${pageCom})-1))}">
์ด์ „</a>
</li>
<!-- ๋ฐ์ดํ„ฐ ์กด์žฌ x ๊ฒฝ์šฐ-->
Expand Down
Loading

0 comments on commit 7d3aad6

Please sign in to comment.