Skip to content

Commit

Permalink
[#49] 공지사항/펀시스템 조회수, 카테고리별 검색 추가 (#54)
Browse files Browse the repository at this point in the history
* fix : postgresql 방식으로 sql문 변경

* fix : response 필요한 데이터만 보내도록 수정

* feat : views로 조회수 기능 추가

* feat : 카테고리별 검색기능 추가

* fix : 전체/ 카테고리 접근 분리

* fix : query 어노테이션 제거

* fix : merge conflict 해결

* fix : sql문 삭제 무결성 유지

* fix : sql 무결성 해결
  • Loading branch information
JooHui-void authored Nov 11, 2023
1 parent 4c7d3e5 commit 4d57dc3
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ enum class FunSystemCategory(val categoryCode: String){
STARTUP_SUPPORT("창업지원"),
EMPLOYMENT_SUPPORT("취업지원");

companion object {
fun fromCode(categoryName: String): FunSystemCategory?{
return values().find{it.name == categoryName }
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ enum class NoticeCategory(val categoryCode: String) {
COVID_19("코로나19"),
UNDERGRADUATE("학부");

companion object {
fun fromCode(categoryName: String): NoticeCategory?{
return NoticeCategory.values().find{it.name == categoryName }
}
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.daitssuapi.domain.notice.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.domain.main.dto.request.CommentWriteRequest
import com.example.daitssuapi.domain.main.dto.response.CommentResponse
import com.example.daitssuapi.common.enums.FunSystemCategory
import com.example.daitssuapi.domain.notice.dto.FunSystemPageResponse
import com.example.daitssuapi.domain.notice.dto.FunSystemResponse
import com.example.daitssuapi.domain.notice.service.FunSystemService
import com.example.daitssuapi.domain.main.dto.request.CommentWriteRequest
import com.example.daitssuapi.domain.main.dto.response.CommentResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.web.bind.annotation.*
Expand All @@ -13,18 +15,33 @@ import org.springframework.web.bind.annotation.*
@RequestMapping("/funsystem")
class FunSystemController(
private val funSystemService: FunSystemService
) {

){

@GetMapping
fun getAllFunSystemList(
@RequestParam searchKeyword:String? = null
):Response<List<FunSystemResponse>>{
return Response(data = funSystemService.getAllFunSystemList(searchKeyword))
}

@GetMapping("/{category}")
fun getFunSystemList(
@PathVariable category: String
): Response<List<FunSystemResponse>> =
Response(data = funSystemService.getFunSystemList(category))
fun getFunSystemListWithCategory(
@PathVariable category:FunSystemCategory,
@RequestParam searchKeyword:String? = null,
): Response<List<FunSystemResponse>>{

return Response(data = funSystemService.getFunSystemList(category, searchKeyword))
}


@GetMapping("/page/{id}")
@GetMapping("/page/{id}") //
fun getFunSystemPage(
@PathVariable id: Long,
): Response<FunSystemResponse> =
Response(data = funSystemService.getFunSystemPage(id))
@PathVariable id : Long,
):Response<FunSystemPageResponse>{
funSystemService.updateViews(id)
return Response(data = funSystemService.getFunSystemPage(id))
}

@Operation(
summary = "댓글 작성",
Expand Down Expand Up @@ -54,4 +71,7 @@ class FunSystemController(
fun getComments(
@PathVariable funSystemId: Long
): Response<List<CommentResponse>> = Response(data = funSystemService.getComments(funSystemId = funSystemId))


}

Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
package com.example.daitssuapi.domain.notice.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.domain.main.dto.request.CommentWriteRequest
import com.example.daitssuapi.domain.main.dto.response.CommentResponse
import com.example.daitssuapi.common.enums.NoticeCategory
import com.example.daitssuapi.domain.notice.dto.NoticeResponse
import com.example.daitssuapi.domain.notice.service.NoticeService
import org.springframework.web.bind.annotation.*
import com.example.daitssuapi.domain.main.dto.request.CommentWriteRequest
import com.example.daitssuapi.domain.main.dto.response.CommentResponse
import com.example.daitssuapi.domain.notice.dto.NoticePageResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.web.bind.annotation.*


@RestController
@RequestMapping("/notice")
class NoticeController(
private val noticeService: NoticeService,
) {

class NoticeController (
private val noticeService : NoticeService,
){
@GetMapping
fun getAllNoticeList(
@RequestParam searchKeyword:String? = null
): Response<List<NoticeResponse>>{
return Response(data = noticeService.getAllNoticeList(searchKeyword))
}
@GetMapping("/{category}")
fun getNoticeList(
@PathVariable category: String
): Response<List<NoticeResponse>> =
Response(data = noticeService.getNoticeList(category))
fun getNoticeListWithCategory(
@PathVariable category: NoticeCategory,
@RequestParam searchKeyword:String? = null,
): Response<List<NoticeResponse>>{
return Response(data = noticeService.getNoticeList(category, searchKeyword))
}

@GetMapping("/page/{id}")
fun getNoticePage(
@PathVariable id: Long,
): Response<NoticeResponse> =
Response(data = noticeService.getNoticePage(id))
): Response<NoticePageResponse> {
noticeService.updateViews(id)
return Response(data = noticeService.getNoticePage(id))
}

@Operation(
summary = "댓글 작성",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.daitssuapi.domain.notice.dto

import com.example.daitssuapi.common.enums.FunSystemCategory
import com.example.daitssuapi.domain.notice.model.entity.FunSystem
import java.time.LocalDateTime

data class FunSystemPageResponse (
val id: Long?,
val title: String,
val content: String,
val category: FunSystemCategory?,
val imageUrl: String?,
val url: String?,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val views : Int,
){
companion object {
fun fromFunSystem(funSystem: FunSystem): FunSystemPageResponse {
return FunSystemPageResponse(
id = funSystem.id,
title = funSystem.title,
content = funSystem.content,
category = funSystem.category,
imageUrl = funSystem.imageUrl,
url = funSystem.url,
createdAt = funSystem.createdAt,
updatedAt = funSystem.updatedAt,
views = funSystem.views,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ import java.time.LocalDateTime
data class FunSystemResponse (
val id: Long?,
val title: String,
val content: String,
val category: FunSystemCategory?,
val imageUrl: String?,
val url: String?,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val views : Int,
){
companion object {
fun fromFunSystem(funSystem: FunSystem): FunSystemResponse {
return FunSystemResponse(
id = funSystem.id,
title = funSystem.title,
content = funSystem.content,
category = funSystem.category,
imageUrl = funSystem.imageUrl,
url = funSystem.url,
createdAt = funSystem.createdAt,
updatedAt = funSystem.updatedAt
views = funSystem.views,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.daitssuapi.domain.notice.dto

import com.example.daitssuapi.common.enums.NoticeCategory
import com.example.daitssuapi.domain.notice.model.entity.Notice
import java.time.LocalDateTime

data class NoticePageResponse(
val id: Long?,
val title: String,
val departmentId: Int,
val content: String,
val category: NoticeCategory?,
val imageUrl: String?,
val fileUrl: String?,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val views : Int,
) {
companion object {
fun fromNotice(notice: Notice): NoticePageResponse {
return NoticePageResponse(
id = notice.id,
title = notice.title,
departmentId = notice.departmentId,
content = notice.content,
category = notice.category,
imageUrl = notice.imageUrl,
fileUrl = notice.fileUrl,
createdAt = notice.createdAt,
updatedAt = notice.updatedAt,
views = notice.views,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ import java.time.LocalDateTime
data class NoticeResponse(
val id: Long?,
val title: String,
val departmentId: Int,
val content: String,
val category: NoticeCategory?,
val imageUrl: String?,
val fileUrl: String?,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val views : Int,
) {
companion object {
fun fromNotice(notice: Notice): NoticeResponse {
return NoticeResponse(
id = notice.id,
title = notice.title,
departmentId = notice.departmentId,
content = notice.content,
category = notice.category,
imageUrl = notice.imageUrl,
fileUrl = notice.fileUrl,
createdAt = notice.createdAt,
updatedAt = notice.updatedAt
views = notice.views,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ class FunSystem (
@Column(name = "url", nullable = false)
val url : String,

// view 빠짐
@Column(name = "views", nullable = false)
var views : Int,
):BaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Notice (
@Column(name = "file_url")
val fileUrl : String,

// view 빠짐
@Column(name = "views", nullable = false)
var views : Int,

): BaseEntity(){

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ package com.example.daitssuapi.domain.notice.model.repository
import com.example.daitssuapi.common.enums.FunSystemCategory
import com.example.daitssuapi.domain.notice.model.entity.FunSystem
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
interface FunSystemRepository :JpaRepository<FunSystem, Long> {

fun findByCategory(category: FunSystemCategory):
List<FunSystem>
fun findByCategoryAndTitleContaining(category: FunSystemCategory, title :String):
List<FunSystem>
fun findByTitleContaining(searchKeyword: String):
List<FunSystem>

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package com.example.daitssuapi.domain.notice.model.repository

import com.example.daitssuapi.common.enums.NoticeCategory
import com.example.daitssuapi.domain.notice.model.entity.Notice
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
interface NoticeRepository :JpaRepository<Notice, Long>{
fun findByCategory(category:NoticeCategory):
List<Notice>
fun findByCategoryAndTitleContaining(category:NoticeCategory,title :String):
List<Notice>
fun findByTitleContaining(searchKeyword: String):
List<Notice>

}
Loading

0 comments on commit 4d57dc3

Please sign in to comment.