Skip to content

Commit

Permalink
Merge pull request #27 from EntryDSM/feature/26-change-description-fi…
Browse files Browse the repository at this point in the history
…eld-from-String-list-to-object-list-with-Title-and-content

Feature/26 change description field from String list to object list with Title and content
  • Loading branch information
qkrwndnjs1075 authored Jan 26, 2025
2 parents c53f30e + 2b179d0 commit d516ba6
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entry.dsm.gitauth.equusgithubauth.domain.notice.command.dto.request

import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.DescriptionItem
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size

Expand All @@ -12,7 +13,7 @@ data class CreateNoticeCommand(
val keyWord: List<String>,
val titleImageUrl: String,
@NotBlank(message = "설명은 비워둘 수 없습니다")
val description: List<String>,
val description: List<DescriptionItem>,
val isFocusRecruit: Boolean,
val isImportant: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entry.dsm.gitauth.equusgithubauth.domain.notice.command.dto.request

import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.DescriptionItem
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size

Expand All @@ -11,7 +12,7 @@ data class UpdateNoticeCommand(
val keyWord: List<String>,
val titleImageUrl: String,
@NotBlank(message = "설명은 비워둘 수 없습니다")
val description: List<String>,
val description: List<DescriptionItem>,
val isFocusRecruit: Boolean,
val isImportant: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package entry.dsm.gitauth.equusgithubauth.domain.notice.command.service
import entry.dsm.gitauth.equusgithubauth.domain.notice.command.dto.request.CreateNoticeCommand
import entry.dsm.gitauth.equusgithubauth.domain.notice.command.repository.NoticeRepository
import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.Notice
import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.NoticeDescription
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -12,17 +13,27 @@ class CreateNoticeService(
) {
@Transactional
fun createNotice(command: CreateNoticeCommand) {
val notice =
Notice(
noticeId = command.noticeId,
title = command.title,
keyWord = command.keyWord,
titleImageUrl = command.titleImageUrl,
description = command.description,
isFocusRecruit = command.isFocusRecruit,
isImportant = command.isImportant,
reports = listOf(),

val notice = Notice(
noticeId = command.noticeId,
title = command.title,
keyWord = command.keyWord,
titleImageUrl = command.titleImageUrl,
descriptions = mutableListOf(),
isFocusRecruit = command.isFocusRecruit,
isImportant = command.isImportant,
reports = listOf()
)
command.description.forEach { descDto ->
notice.descriptions.add(
NoticeDescription(
title = descDto.title,
content = descDto.content,
notice = notice
)
)
}

noticeRepository.save(notice)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package entry.dsm.gitauth.equusgithubauth.domain.notice.entity

import jakarta.validation.constraints.NotBlank

data class DescriptionItem(
@NotBlank(message = "타이틀은 비워둘 수 없습니다")
val title: String,

@NotBlank(message = "내용은 비워둘 수 없습니다")
val content: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ package entry.dsm.gitauth.equusgithubauth.domain.notice.entity

import entry.dsm.gitauth.equusgithubauth.domain.notice.command.dto.request.UpdateNoticeCommand
import entry.dsm.gitauth.equusgithubauth.domain.report.entity.Report
import jakarta.persistence.CollectionTable
import jakarta.persistence.Column
import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.OneToMany
import jakarta.persistence.*

@Entity(name = "notice")
class Notice(
Expand All @@ -28,10 +18,8 @@ class Notice(
var keyWord: List<String>,
@Column(name = "title_image_url", nullable = false)
var titleImageUrl: String,
@ElementCollection
@CollectionTable(name = "notice_descriptions", joinColumns = [JoinColumn(name = "notice_id")])
@Column(name = "description", nullable = false)
var description: List<String>,
@OneToMany(mappedBy = "notice", cascade = [CascadeType.ALL], orphanRemoval = true)
var descriptions: MutableList<NoticeDescription> = mutableListOf(),
@Enumerated(EnumType.STRING)
@Column(name = "is_focus_recruit", nullable = false)
var isFocusRecruit: Boolean,
Expand All @@ -44,8 +32,19 @@ class Notice(
title = command.title
keyWord = command.keyWord
titleImageUrl = command.titleImageUrl
description = command.description
isFocusRecruit = command.isFocusRecruit
isImportant = command.isImportant


descriptions.clear()
command.description.forEach { descDto ->
descriptions.add(
NoticeDescription(
title = descDto.title,
content = descDto.content,
notice = this
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package entry.dsm.gitauth.equusgithubauth.domain.notice.entity

import jakarta.persistence.*

@Entity(name = "notice_description")
class NoticeDescription(
@Id
@GeneratedValue
val id: Long = 0,

@Column(nullable = false)
var title: String,

@Column(nullable = false, columnDefinition = "TEXT")
var content: String,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "notice_id")
var notice: Notice,
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package entry.dsm.gitauth.equusgithubauth.domain.notice.query.dto.response

import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.DescriptionItem
import entry.dsm.gitauth.equusgithubauth.domain.notice.entity.Notice

data class NoticeQueryResponse(
val noticeId: Long,
val title: String,
val keyWord: List<String>,
val titleImageUrl: String,
val description: List<String>,
val description: List<DescriptionItem>,
val isFocusRecruit: Boolean,
val isImportant: Boolean,
) {
Expand All @@ -18,7 +19,9 @@ data class NoticeQueryResponse(
title = notice.title,
keyWord = notice.keyWord,
titleImageUrl = notice.titleImageUrl,
description = notice.description,
description = notice.descriptions.map { // 엔티티 구조도 변경 필요
DescriptionItem(it.title, it.content)
},
isFocusRecruit = notice.isFocusRecruit,
isImportant = notice.isImportant,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package entry.dsm.gitauth.equusgithubauth.global.config
import entry.dsm.gitauth.equusgithubauth.global.oauth.GithubOAuth2LoginConfig
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
Expand All @@ -22,6 +23,7 @@ class SecurityConfig(
.authorizeHttpRequests { auth ->
auth
.requestMatchers("/", "/login", "/oauth2/**", "/error").permitAll()
.requestMatchers(HttpMethod.GET, "reports", "notice").permitAll()
.anyRequest().authenticated()
}

Expand Down

This file was deleted.

0 comments on commit d516ba6

Please sign in to comment.