Skip to content

Commit

Permalink
광야 게시물 생성 후 게시물 반환 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajeu committed Dec 4, 2023
1 parent e156482 commit a5c9598
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class GwangyaController(
fun generateGwangya(
@RequestHeader("gwangyaToken") gwangyaToken: String,
@Valid @RequestBody gwangyaDto: GwangyaPostsRegistrationDto
): ResponseEntity<Void> {
): ResponseEntity<GwangyaPostsDto> {
checkGwangyaAuthentication(gwangyaToken)
generateGwangyaPostsService.execute(gwangyaDto)
return ResponseEntity.status(HttpStatus.CREATED).build()
val gwangyaPost = generateGwangyaPostsService.execute(gwangyaDto)
return ResponseEntity.status(HttpStatus.CREATED).body(gwangyaPost)
}

private fun checkGwangyaAuthentication(gwangyaToken: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.themoment.gsmNetworking.domain.gwangya.service
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.themoment.gsmNetworking.domain.gwangya.domain.Gwangya
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostsDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostsRegistrationDto
import team.themoment.gsmNetworking.domain.gwangya.repository.GwangyaRepository
import java.time.LocalDateTime
Expand All @@ -13,13 +14,19 @@ class GenerateGwangyaPostsService(
private val gwangyaRepository: GwangyaRepository
) {

fun execute(gwangyaPostsDto: GwangyaPostsRegistrationDto) {
fun execute(gwangyaPostsDto: GwangyaPostsRegistrationDto): GwangyaPostsDto {

val gwangyaPosts = Gwangya(
content = gwangyaPostsDto.content,
createdAt = LocalDateTime.now()
)

gwangyaRepository.save(gwangyaPosts)
val savedGwangyaPost = gwangyaRepository.save(gwangyaPosts)

return GwangyaPostsDto(
savedGwangyaPost.gwangyaId,
savedGwangyaPost.content,
savedGwangyaPost.createdAt
)
}
}

0 comments on commit a5c9598

Please sign in to comment.