Skip to content

Commit

Permalink
feat: enrollTag 기능 추가, noticeTag 연관 엔티티 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
skfotakf committed Jul 26, 2023
1 parent 0382376 commit 3f2e94d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ class NoticeController(
noticeService.deleteNotice(noticeId)
return ResponseEntity<String>("삭제되었습니다. (noticeId: $noticeId)", HttpStatus.OK)
}

@PostMapping("/tag")
fun enrollTag(
@RequestBody tagName: Map<String, String>
) : ResponseEntity<String> {
noticeService.enrollTag(tagName["name"]!!)
return ResponseEntity<String>("등록되었습니다. (tagName: ${tagName["name"]})", HttpStatus.OK)
}
}
Original file line number Diff line number Diff line change
@@ -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() {
}
Original file line number Diff line number Diff line change
@@ -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() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.csereal.core.notice.database

import org.springframework.data.jpa.repository.JpaRepository

interface TagRepository : JpaRepository<TagEntity, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ data class CreateNoticeRequest(

@NotBlank(message = "내용은 비어있을 수 없습니다")
val description: String,

val tag: List<String> = emptyList()
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -65,4 +69,11 @@ class NoticeServiceImpl(
notice.isDeleted = true

}

override fun enrollTag(tagName: String) {
val newTag = TagEntity(
name = tagName
)
tagRepository.save(newTag)
}
}

0 comments on commit 3f2e94d

Please sign in to comment.