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

main <- dev #182

Merged
merged 11 commits into from
Jun 20, 2023
48 changes: 48 additions & 0 deletions src/docs/asciidoc/house.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
== House API

==== 1. 빈집 게시글 작성하기
===== Request
include::{snippets}/save-house/http-request.adoc[]
====== Request fields
include::{snippets}/save-house/request-fields.adoc[]
===== Response
include::{snippets}/save-house/http-response.adoc[]
===== Response fields
include::{snippets}/save-house/response-fields.adoc[]

==== 2. 빈집 게시글 수정하기
===== Request
include::{snippets}/update-house/http-request.adoc[]
===== Request Fields
include::{snippets}/update-house/request-fields.adoc[]

===== Response
include::{snippets}/update-house/http-response.adoc[]

==== 3. 빈집 게시글 삭제하기
삭제 시, 빈집 게시글 아이디를 path-variable로 넘겨주세요.

===== Request
include::{snippets}/delete-house/http-request.adoc[]
===== Response
include::{snippets}/delete-house/http-response.adoc[]


==== 4. 빈집 게시글 목록 조회
===== Request
include::{snippets}/get-house-all/http-request.adoc[]
====== Request Fields
include::{snippets}/get-house-all/request-parameters.adoc[]

====== Response
include::{snippets}/get-house-all/http-response.adoc[]
====== Response Fields
include::{snippets}/get-house-all/response-fields-data.adoc[]

===== 5. 빈집 게시글 단일 조회
====== Request
include::{snippets}/get-house-one/http-request.adoc[]
====== Response
include::{snippets}/get-house-one/http-response.adoc[]
====== Response Fields
include::{snippets}/get-house-one/response-fields.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -88,42 +88,40 @@ class BoardServiceImpl(
override fun getCategory(name: String): List<CodeResDto> {
return BoardCategory.values().filter { it.superCategory.name == name }.map { CodeResDto(it.value, it.name) }
}


fun getContent(code: String): String {
var str = code
str = Normalizer.normalize(str, Normalizer.Form.NFKC)
var mat: Matcher

// <script> 파싱
val script = Pattern.compile("<(no)?script[^>]*>.*?</(no)?script>", Pattern.DOTALL)
mat = script.matcher(str)
str = mat.replaceAll("")

// <style> 파싱
val style = Pattern.compile("<style[^>]*>.*</style>", Pattern.DOTALL)
mat = style.matcher(str)
str = mat.replaceAll("")

// <tag> 파싱
val tag = Pattern.compile("<(\"[^\"]*\"|\'[^\']*\'|[^\'\">])*>")
mat = tag.matcher(str)
str = mat.replaceAll("")

// ntag 파싱
val ntag = Pattern.compile("<\\w+\\s+[^<]*\\s*>")
mat = ntag.matcher(str)
str = mat.replaceAll("")

// entity ref 처리
val entity = Pattern.compile("&[^;]+;")
mat = entity.matcher(str)
str = mat.replaceAll("")

// whitespace 처리
val wspace = Pattern.compile("\\s\\s+")
mat = wspace.matcher(str)
str = mat.replaceAll("")
return str
}
}
fun getContent(code: String): String {
var str = code
str = Normalizer.normalize(str, Normalizer.Form.NFKC)
var mat: Matcher

// <script> 파싱
val script = Pattern.compile("<(no)?script[^>]*>.*?</(no)?script>", Pattern.DOTALL)
mat = script.matcher(str)
str = mat.replaceAll("")

// <style> 파싱
val style = Pattern.compile("<style[^>]*>.*</style>", Pattern.DOTALL)
mat = style.matcher(str)
str = mat.replaceAll("")

// <tag> 파싱
val tag = Pattern.compile("<(\"[^\"]*\"|\'[^\']*\'|[^\'\">])*>")
mat = tag.matcher(str)
str = mat.replaceAll("")

// ntag 파싱
val ntag = Pattern.compile("<\\w+\\s+[^<]*\\s*>")
mat = ntag.matcher(str)
str = mat.replaceAll("")

// entity ref 처리
val entity = Pattern.compile("&[^;]+;")
mat = entity.matcher(str)
str = mat.replaceAll("")

// whitespace 처리
val wspace = Pattern.compile("\\s\\s+")
mat = wspace.matcher(str)
str = mat.replaceAll("")
return str
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.example.jhouse_server.domain.house.controller

import com.example.jhouse_server.domain.board.BoardListDto
import com.example.jhouse_server.domain.house.dto.HouseListDto
import com.example.jhouse_server.domain.house.dto.HouseReqDto
import com.example.jhouse_server.domain.house.dto.HouseResDto
import com.example.jhouse_server.domain.house.dto.HouseResOneDto
import com.example.jhouse_server.domain.house.service.HouseService
import com.example.jhouse_server.domain.user.entity.User
import com.example.jhouse_server.global.annotation.Auth
import com.example.jhouse_server.global.annotation.AuthUser
import com.example.jhouse_server.global.aop.EnableValidation
import com.example.jhouse_server.global.response.ApplicationResponse
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.web.PageableDefault
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*

@EnableValidation
@RestController
@RequestMapping("/api/v1/houses")
class HouseController(
val houseService: HouseService
) {

/**
* 빈집 게시글 작성
*
* @author dldmsql
* @param req HouseReqDto 빈집 게시글 작성 시, 입력되는 데이터
* @param user User RefreshToken 기반 인증/인가 처리된 사용자 데이터
* @return house_id 빈집 게시글 ID
* @exception INVALID_VALUE_EXCEPTION C0002 올바르지 않은 요청입니다. ( 유효성 검사 실패 시 )
* */
@Auth
@PostMapping
fun createHouse(
@RequestBody @Validated req: HouseReqDto,
@AuthUser user: User
) : ApplicationResponse<Long> {
return ApplicationResponse.ok(houseService.createHouse(req, user))
}

/**
* 빈집 게시글 수정
*
* @author dldmsql
* @param houseId Long 빈집 게시글 ID
* @param req HouseReqDto 빈집 게시글 작성 시, 입력되는 데이터
* @param user User RefreshToken 기반 인증/인가 처리된 사용자 데이터
* @return house_id 빈집 게시글 ID
* @exception INVALID_VALUE_EXCEPTION C0002 올바르지 않은 요청입니다. ( 유효성 검사 실패 시 )
* */
@Auth
@PutMapping("/{houseId}")
fun updateHouse(
@PathVariable houseId: Long,
@RequestBody @Validated req: HouseReqDto,
@AuthUser user: User
) : ApplicationResponse<Long> {
return ApplicationResponse.ok(houseService.updateHouse(houseId, req, user))
}

/**
* 빈집 게시글 삭제
*
* @author dldmsql
* @param houseId Long 빈집 게시글 ID
* @param user User
* */
@Auth
@DeleteMapping("/{houseId}")
fun deleteHouse(
@PathVariable houseId: Long,
@AuthUser user: User
) : ApplicationResponse<Nothing> {
houseService.deleteHouse(houseId, user)
return ApplicationResponse.ok()
}

/**
* 빈집 게시글 리스트 조회
*
* @author dldmsql
* @param houseListDto HouseListDto 게시글 조회를 위한 기본 검색 조건 ( 매물 타입, 도시, 검색어 )
* @param pageable Pageable 페이징처리를 위한 인터페이스
* @return Page<HouseResDto>
* */
@GetMapping
fun getHouseAll(
@ModelAttribute houseListDto: HouseListDto,
@PageableDefault(size=8, page=0) pageable: Pageable
) : ApplicationResponse<Page<HouseResDto>> {
return ApplicationResponse.ok(houseService.getHouseAll(houseListDto, pageable))
}

/**
* 빈집 게시글 상세 조회
*
* @author dldmsql
* @param houseId Long 빈집 게시글 ID
* @return HouseResOneDto
* */
@GetMapping("/{houseId}")
fun getHouseOne(
@PathVariable houseId: Long
) : ApplicationResponse<HouseResOneDto> {
return ApplicationResponse.ok(houseService.getHouseOne(houseId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.example.jhouse_server.domain.house.dto

import com.example.jhouse_server.domain.house.entity.House
import com.example.jhouse_server.domain.house.entity.RentalType
import java.sql.Timestamp
import java.util.*
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull

data class HouseReqDto(
@field:NotNull(message = "매매 타입은 필수값입니다.")
val rentalType: RentalType? = null,
@field:NotNull(message = "주소는 필수값입니다. ( 예: 서울/인천 ~ )")
val city: String?,
@field:NotNull(message = "우편번호는 필수값입니다.")
val zipCode: String?,
@field:NotNull(message = "집 크기는 필수값입니다. ( m^2 단위로 산정해서 작성할 것 )")
val size: String?,
@field:NotNull(message = "매물 목적/용도는 필수값입니다.")
val purpose: String?,
var floorNum: Int,
var sumFloor: Int,
@field:NotNull(message = "연락처는 필수값입니다.")
var contact: String?,
var createdDate: String,
@field:NotNull(message = "매물 가격은 필수값입니다.")
var price: Int?,
var monthlyPrice: Double,
val agentName : String,
val title: String,
val code: String,
val imageUrls: List<String>
)
data class HouseListDto(
val rentalType: String,
val city: String?,
val search: String?
)
data class HouseResDto(
val houseId: Long,
val rentalType: RentalType,
val city: String,
val price: Int,
val monthlyPrice: Double,
val nickName: String,
val createdAt: Date,
val isCompleted: Boolean
)
data class HouseResOneDto(
val houseId: Long,
val rentalType: RentalType,
val city: String,
val zipcode: String,
val purpose: String,
val floorNum: Int,
val sumFloor: Int,
val contact: String,
val createdDate: String, // 준공연도
val price: Int,
val monthlyPrice: Double,
val agentName: String, // 공인중개사명
val title: String,
val code: String,
val imageUrls: List<String>,
val nickName: String, // 게시글 작성자
val createdAt: Date,
val isCompleted: Boolean
)

fun toDto(house: House) : HouseResOneDto {
return HouseResOneDto(house.id, house.houseType, house.address.city,
house.address.zipcode, house.purpose, house.floorNum, house.sumFloor, house.contact,
house.createdDate, house.price, house.monthlyPrice,
house.agentName, house.title, house.code, house.imageUrls, house.user.nickName,
Timestamp.valueOf(house.createdAt), false)
}

fun toListDto(house: House) : HouseResDto {
return HouseResDto(house.id, house.houseType!!, house.address.city, house.price, house.monthlyPrice, house.user.nickName, Timestamp.valueOf(house.createdAt), false )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.jhouse_server.domain.house.entity

import javax.persistence.Column
import javax.persistence.Embeddable

@Embeddable
class Address(
@Column
var city: String, // 시도

@Column
var zipcode: String, // 우편번호
) {
fun updateEntity(city: String, zipCode: String) : Address {
this.city = city
this.zipcode = zipCode
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 javax.persistence.*

@Entity
class Deal(

@Convert(converter = DealStateConverter::class)
var dealState : DealState,

@OneToOne
var buyer: User,

@OneToOne
var house: House,

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id : Long = 0L
) : BaseEntity() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.jhouse_server.domain.house.entity

import javax.persistence.AttributeConverter
import javax.persistence.Converter

@Converter(autoApply = true)
class DealStateConverter : AttributeConverter<DealState, String> {
override fun convertToDatabaseColumn(attribute: DealState?): String? {
return attribute?.name
}

override fun convertToEntityAttribute(dbData: String?): DealState? {
return DealState.values().firstOrNull {it.name == dbData}
}
}

enum class DealState {
ONGOING,
COMPLETED,
}
Loading