-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mail): implement the mail history function
- Loading branch information
Showing
20 changed files
with
556 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package apply.application | ||
|
||
import apply.application.mail.MailData | ||
import apply.domain.mail.MailHistory | ||
import apply.domain.mail.MailHistoryRepository | ||
import apply.domain.mail.getById | ||
import apply.domain.user.UserRepository | ||
import org.springframework.stereotype.Service | ||
import javax.transaction.Transactional | ||
|
||
@Transactional | ||
@Service | ||
class MailHistoryService( | ||
private val mailHistoryRepository: MailHistoryRepository, | ||
private val userRepository: UserRepository | ||
) { | ||
fun save(request: MailData) { | ||
mailHistoryRepository.save( | ||
MailHistory( | ||
request.subject, | ||
request.body, | ||
request.sender, | ||
request.recipients, | ||
request.sentTime | ||
) | ||
) | ||
} | ||
|
||
fun findAll(): List<MailData> { | ||
return mailHistoryRepository.findAll().map { MailData(it) } | ||
} | ||
|
||
fun getById(mailHistoryId: Long): MailData { | ||
val mailHistory = mailHistoryRepository.getById(mailHistoryId) | ||
return MailData(mailHistory) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
package apply.application.mail | ||
|
||
import apply.domain.mail.MailHistory | ||
import java.time.LocalDateTime | ||
import javax.validation.constraints.NotEmpty | ||
import javax.validation.constraints.NotNull | ||
import javax.validation.constraints.Size | ||
|
||
data class MailData( | ||
@field:NotEmpty | ||
@field:Size(min = 1, max = 100) | ||
var subject: String = "", | ||
|
||
@field:NotEmpty | ||
var body: String = "", | ||
|
||
@field:NotEmpty | ||
var recipients: List<String> = emptyList() | ||
) | ||
@field:Size(min = 1, max = 100) | ||
var sender: String = "", | ||
|
||
@field:NotEmpty | ||
var recipients: List<String> = emptyList(), | ||
|
||
@field:NotNull | ||
var sentTime: LocalDateTime = LocalDateTime.now(), | ||
|
||
@field:NotNull | ||
var id: Long = 0L | ||
) { | ||
constructor(mailHistory: MailHistory) : this( | ||
mailHistory.subject, | ||
mailHistory.body, | ||
mailHistory.sender, | ||
mailHistory.recipients, | ||
mailHistory.sentTime, | ||
mailHistory.id | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package apply.domain.mail | ||
|
||
import support.domain.BaseEntity | ||
import support.domain.StringToListConverter | ||
import java.time.LocalDateTime | ||
import javax.persistence.Column | ||
import javax.persistence.Convert | ||
import javax.persistence.Entity | ||
import javax.persistence.Lob | ||
|
||
@Entity | ||
class MailHistory( | ||
@Column(nullable = false) | ||
val subject: String, | ||
|
||
@Column(nullable = false) | ||
@Lob | ||
val body: String, | ||
|
||
@Column(nullable = false) | ||
val sender: String, | ||
|
||
@Column(nullable = false) | ||
@Convert(converter = StringToListConverter::class) | ||
@Lob | ||
val recipients: List<String>, | ||
|
||
@Column(nullable = false) | ||
val sentTime: LocalDateTime = LocalDateTime.now(), | ||
id: Long = 0L | ||
) : BaseEntity(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package apply.domain.mail | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
|
||
fun MailHistoryRepository.getById(id: Long): MailHistory = findByIdOrNull(id) ?: throw NoSuchElementException() | ||
|
||
interface MailHistoryRepository : JpaRepository<MailHistory, Long> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.