Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add_description_to_slide
Browse files Browse the repository at this point in the history
  • Loading branch information
huGgW authored Sep 19, 2023
2 parents 91fe352 + 70eef9c commit 78c3021
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NewsEntity(
@Column(columnDefinition = "mediumtext")
var plainTextDescription: String,

var date: LocalDateTime?,
var date: LocalDateTime,
var isPrivate: Boolean,
var isSlide: Boolean,
var isImportant: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ import java.time.LocalDateTime

interface NewsRepository : JpaRepository<NewsEntity, Long>, CustomNewsRepository {
fun findAllByIsImportant(isImportant: Boolean): List<NewsEntity>
fun findFirstByCreatedAtLessThanOrderByCreatedAtDesc(timestamp: LocalDateTime): NewsEntity?
fun findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(timestamp: LocalDateTime): NewsEntity?
fun findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(timestamp: LocalDateTime): NewsEntity?
fun findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(timestamp: LocalDateTime): NewsEntity?
}

interface CustomNewsRepository {
fun searchNews(tag: List<String>?, keyword: String?, pageable: Pageable, usePageBtn: Boolean, isStaff: Boolean): NewsSearchResponse
fun searchNews(
tag: List<String>?,
keyword: String?,
pageable: Pageable,
usePageBtn: Boolean,
isStaff: Boolean
): NewsSearchResponse

fun searchTotalNews(
keyword: String,
number: Int,
amount: Int,
imageUrlCreator: (MainImageEntity?) -> String?,
keyword: String,
number: Int,
amount: Int,
imageUrlCreator: (MainImageEntity?) -> String?,
): NewsTotalSearchDto
}

Expand Down Expand Up @@ -95,7 +102,7 @@ class NewsRepositoryImpl(
}

val newsEntityList = jpaQuery
.orderBy(newsEntity.createdAt.desc())
.orderBy(newsEntity.date.desc())
.offset(pageRequest.offset)
.limit(pageRequest.pageSize.toLong())
.distinct()
Expand All @@ -118,10 +125,10 @@ class NewsRepositoryImpl(
}

override fun searchTotalNews(
keyword: String,
number: Int,
amount: Int,
imageUrlCreator: (MainImageEntity?) -> String?,
keyword: String,
number: Int,
amount: Int,
imageUrlCreator: (MainImageEntity?) -> String?,
): NewsTotalSearchDto {
val doubleTemplate = commonRepository.searchFullDoubleTextTemplate(
keyword,
Expand All @@ -130,50 +137,50 @@ class NewsRepositoryImpl(
)

val searchResult = queryFactory.select(
newsEntity.id,
newsEntity.title,
newsEntity.date,
newsEntity.plainTextDescription,
mainImageEntity,
).from(newsEntity)
newsEntity.id,
newsEntity.title,
newsEntity.date,
newsEntity.plainTextDescription,
mainImageEntity,
).from(newsEntity)
.leftJoin(mainImageEntity)
.where(doubleTemplate.gt(0.0))
.limit(number.toLong())
.fetch()

val searchResultTags = queryFactory.select(
newsTagEntity.news.id,
newsTagEntity.tag.name,
).from(newsTagEntity)
newsTagEntity.news.id,
newsTagEntity.tag.name,
).from(newsTagEntity)
.rightJoin(newsEntity)
.leftJoin(tagInNewsEntity)
.where(newsTagEntity.news.id.`in`(searchResult.map { it[newsEntity.id] }))
.distinct()
.fetch()

val total = queryFactory.select(newsEntity.countDistinct())
.from(newsEntity)
.where(doubleTemplate.gt(0.0))
.fetchOne()!!
.from(newsEntity)
.where(doubleTemplate.gt(0.0))
.fetchOne()!!

return NewsTotalSearchDto(
total.toInt(),
searchResult.map {
NewsTotalSearchElement(
id = it[newsEntity.id]!!,
title = it[newsEntity.title]!!,
date = it[newsEntity.date],
tags = searchResultTags.filter {
tag -> tag[newsTagEntity.news.id] == it[newsEntity.id]
}.map {
tag -> tag[newsTagEntity.tag.name]!!.krName
},
imageUrl = imageUrlCreator(it[mainImageEntity]),
description = it[newsEntity.plainTextDescription]!!,
keyword = keyword,
amount = amount,
)
}
total.toInt(),
searchResult.map {
NewsTotalSearchElement(
id = it[newsEntity.id]!!,
title = it[newsEntity.title]!!,
date = it[newsEntity.date],
tags = searchResultTags.filter { tag ->
tag[newsTagEntity.news.id] == it[newsEntity.id]
}.map { tag ->
tag[newsTagEntity.tag.name]!!.krName
},
imageUrl = imageUrlCreator(it[mainImageEntity]),
description = it[newsEntity.plainTextDescription]!!,
keyword = keyword,
amount = amount,
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class NewsDto(
val tags: List<String>,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val date: LocalDateTime?,
val date: LocalDateTime,
val isPrivate: Boolean,
val isSlide: Boolean,
val isImportant: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class NewsServiceImpl(

@Transactional(readOnly = true)
override fun searchTotalNews(
keyword: String,
number: Int,
amount: Int,
keyword: String,
number: Int,
amount: Int,
) = newsRepository.searchTotalNews(
keyword,
number,
amount,
mainImageService::createImageURL,
keyword,
number,
amount,
mainImageService::createImageURL,
)

@Transactional(readOnly = true)
Expand All @@ -77,8 +77,10 @@ class NewsServiceImpl(
val imageURL = mainImageService.createImageURL(news.mainImage)
val attachmentResponses = attachmentService.createAttachmentResponses(news.attachments)

val prevNews = newsRepository.findFirstByCreatedAtLessThanOrderByCreatedAtDesc(news.createdAt!!)
val nextNews = newsRepository.findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(news.createdAt!!)
val prevNews =
newsRepository.findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(news.createdAt!!)
val nextNews =
newsRepository.findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(news.createdAt!!)

return NewsDto.of(news, imageURL, attachmentResponses, prevNews, nextNews)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import java.time.LocalDateTime

interface NoticeRepository : JpaRepository<NoticeEntity, Long>, CustomNoticeRepository {
fun findAllByIsImportant(isImportant: Boolean): List<NoticeEntity>
fun findFirstByCreatedAtLessThanOrderByCreatedAtDesc(timestamp: LocalDateTime): NoticeEntity?
fun findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(timestamp: LocalDateTime): NoticeEntity?
fun findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(timestamp: LocalDateTime): NoticeEntity?
fun findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(timestamp: LocalDateTime): NoticeEntity?
}

interface CustomNoticeRepository {
Expand All @@ -40,40 +40,40 @@ class NoticeRepositoryImpl(
private val commonRepository: CommonRepository,
) : CustomNoticeRepository {
override fun totalSearchNotice(
keyword: String,
number: Int,
stringLength: Int,
keyword: String,
number: Int,
stringLength: Int,
): NoticeTotalSearchResponse {
val doubleTemplate = commonRepository.searchFullDoubleTextTemplate(
keyword,
noticeEntity.title,
noticeEntity.plainTextDescription
keyword,
noticeEntity.title,
noticeEntity.plainTextDescription
)

val query = queryFactory.select(
noticeEntity.id,
noticeEntity.title,
noticeEntity.createdAt,
noticeEntity.plainTextDescription
).from(noticeEntity)
noticeEntity.id,
noticeEntity.title,
noticeEntity.createdAt,
noticeEntity.plainTextDescription
).from(noticeEntity)
.where(doubleTemplate.gt(0.0))

val total = query.clone().select(noticeEntity.countDistinct()).fetchOne()!!

val searchResult = query.limit(number.toLong()).fetch()

return NoticeTotalSearchResponse(
total.toInt(),
searchResult.map {
NoticeTotalSearchElement(
it[noticeEntity.id]!!,
it[noticeEntity.title]!!,
it[noticeEntity.createdAt]!!,
it[noticeEntity.plainTextDescription]!!,
keyword,
stringLength,
)
}
total.toInt(),
searchResult.map {
NoticeTotalSearchElement(
it[noticeEntity.id]!!,
it[noticeEntity.title]!!,
it[noticeEntity.createdAt]!!,
it[noticeEntity.plainTextDescription]!!,
keyword,
stringLength,
)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class NoticeServiceImpl(

val attachmentResponses = attachmentService.createAttachmentResponses(notice.attachments)

val prevNotice = noticeRepository.findFirstByCreatedAtLessThanOrderByCreatedAtDesc(notice.createdAt!!)
val nextNotice = noticeRepository.findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(notice.createdAt!!)
val prevNotice =
noticeRepository.findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(notice.createdAt!!)
val nextNotice =
noticeRepository.findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(notice.createdAt!!)

return NoticeDto.of(notice, attachmentResponses, prevNotice, nextNotice)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReservationController(
) {

@GetMapping("/month")
@AuthenticatedForReservation
// @AuthenticatedForReservation TODO: CBT 끝나면 주석 제거
fun getMonthlyReservations(
@RequestParam roomId: Long,
@RequestParam year: Int,
Expand All @@ -36,7 +36,7 @@ class ReservationController(
}

@GetMapping("/week")
@AuthenticatedForReservation
// @AuthenticatedForReservation
fun getWeeklyReservations(
@RequestParam roomId: Long,
@RequestParam year: Int,
Expand All @@ -49,7 +49,7 @@ class ReservationController(
}

@GetMapping("/{reservationId}")
@AuthenticatedForReservation
// @AuthenticatedForReservation
fun getReservation(@PathVariable reservationId: Long): ResponseEntity<ReservationDto> {
return ResponseEntity.ok(reservationService.getReservation(reservationId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ class ReservationServiceImpl(
val reservationEntity =
reservationRepository.findByIdOrNull(reservationId) ?: throw CserealException.Csereal404("예약을 찾을 수 없습니다.")

val user = RequestContextHolder.getRequestAttributes()?.getAttribute(
"loggedInUser",
RequestAttributes.SCOPE_REQUEST
) as UserEntity

if (user.role == Role.ROLE_STAFF) {
return ReservationDto.of(reservationEntity)
} else {
return ReservationDto.forNormalUser(reservationEntity)
}
// val user = RequestContextHolder.getRequestAttributes()?.getAttribute(
// "loggedInUser",
// RequestAttributes.SCOPE_REQUEST
// ) as UserEntity
//
// if (user.role == Role.ROLE_STAFF) {
// return ReservationDto.of(reservationEntity)
// } else {
return ReservationDto.forNormalUser(reservationEntity)
// }
}

override fun cancelSpecific(reservationId: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import java.time.LocalDateTime

interface SeminarRepository : JpaRepository<SeminarEntity, Long>, CustomSeminarRepository {
fun findAllByIsImportant(isImportant: Boolean): List<SeminarEntity>
fun findFirstByCreatedAtLessThanOrderByCreatedAtDesc(timestamp: LocalDateTime): SeminarEntity?
fun findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(timestamp: LocalDateTime): SeminarEntity?
fun findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(timestamp: LocalDateTime): SeminarEntity?
fun findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(timestamp: LocalDateTime): SeminarEntity?
}

interface CustomSeminarRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ class SeminarServiceImpl(
val imageURL = mainImageService.createImageURL(seminar.mainImage)
val attachmentResponses = attachmentService.createAttachmentResponses(seminar.attachments)

val prevSeminar = seminarRepository.findFirstByCreatedAtLessThanOrderByCreatedAtDesc(seminar.createdAt!!)
val nextSeminar = seminarRepository.findFirstByCreatedAtGreaterThanOrderByCreatedAtAsc(seminar.createdAt!!)
val prevSeminar =
seminarRepository.findFirstByCreatedAtLessThanAndIsPrivateFalseOrderByCreatedAtDesc(seminar.createdAt!!)
val nextSeminar =
seminarRepository.findFirstByCreatedAtGreaterThanAndIsPrivateFalseOrderByCreatedAtAsc(seminar.createdAt!!)

return SeminarDto.of(seminar, imageURL, attachmentResponses, prevSeminar, nextSeminar)
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ server:
servlet:
session:
timeout: 7200 # 2시간
forward-headers-strategy: native

springdoc:
paths-to-match:
Expand Down
Loading

0 comments on commit 78c3021

Please sign in to comment.