diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt index c3f67c4f..b8f73ce4 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt @@ -43,4 +43,12 @@ class NoticeController( noticeService.deleteNotice(noticeId) return ResponseEntity("삭제되었습니다. (noticeId: $noticeId)", HttpStatus.OK) } + + @PostMapping("/tag") + fun enrollTag( + @RequestBody tagName: Map + ) : ResponseEntity { + noticeService.enrollTag(tagName["name"]!!) + return ResponseEntity("등록되었습니다. (tagName: ${tagName["name"]})", HttpStatus.OK) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeTagEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeTagEntity.kt new file mode 100644 index 00000000..0a469814 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeTagEntity.kt @@ -0,0 +1,20 @@ +package com.wafflestudio.csereal.core.notice.database + +import com.wafflestudio.csereal.common.config.BaseTimeEntity +import jakarta.persistence.CascadeType +import jakarta.persistence.Entity +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne + +@Entity(name="noticeTag") +class NoticeTagEntity( + @ManyToOne(cascade = [CascadeType.ALL]) + @JoinColumn(name = "notice_id") + val notice: NoticeEntity, + + @ManyToOne(cascade = [CascadeType.ALL]) + @JoinColumn(name = "tag_id") + val tag: TagEntity, + + ) : BaseTimeEntity() { +} \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagEntity.kt new file mode 100644 index 00000000..7a24b634 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagEntity.kt @@ -0,0 +1,10 @@ +package com.wafflestudio.csereal.core.notice.database + +import com.wafflestudio.csereal.common.config.BaseTimeEntity +import jakarta.persistence.Entity + +@Entity(name = "tag") +class TagEntity( + var name: String +) : BaseTimeEntity() { +} \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagRepository.kt new file mode 100644 index 00000000..34a50416 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/TagRepository.kt @@ -0,0 +1,6 @@ +package com.wafflestudio.csereal.core.notice.database + +import org.springframework.data.jpa.repository.JpaRepository + +interface TagRepository : JpaRepository { +} \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/CreateNoticeRequest.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/CreateNoticeRequest.kt index 1e8c89ae..4a41c66b 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/CreateNoticeRequest.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/CreateNoticeRequest.kt @@ -8,5 +8,7 @@ data class CreateNoticeRequest( @NotBlank(message = "내용은 비어있을 수 없습니다") val description: String, + + val tag: List = emptyList() ) { } \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt index 265c08d7..f37b8200 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt @@ -3,6 +3,8 @@ package com.wafflestudio.csereal.core.notice.service import com.wafflestudio.csereal.common.CserealException import com.wafflestudio.csereal.core.notice.database.NoticeEntity import com.wafflestudio.csereal.core.notice.database.NoticeRepository +import com.wafflestudio.csereal.core.notice.database.TagEntity +import com.wafflestudio.csereal.core.notice.database.TagRepository import com.wafflestudio.csereal.core.notice.dto.CreateNoticeRequest import com.wafflestudio.csereal.core.notice.dto.NoticeDto import com.wafflestudio.csereal.core.notice.dto.UpdateNoticeRequest @@ -15,11 +17,13 @@ interface NoticeService { fun createNotice(request: CreateNoticeRequest): NoticeDto fun updateNotice(noticeId: Long, request: UpdateNoticeRequest) : NoticeDto fun deleteNotice(noticeId: Long) + fun enrollTag(tagName: String) } @Service class NoticeServiceImpl( private val noticeRepository: NoticeRepository, + private val tagRepository: TagRepository, ) : NoticeService { @Transactional(readOnly = true) @@ -65,4 +69,11 @@ class NoticeServiceImpl( notice.isDeleted = true } + + override fun enrollTag(tagName: String) { + val newTag = TagEntity( + name = tagName + ) + tagRepository.save(newTag) + } } \ No newline at end of file