Skip to content

Commit

Permalink
🧩:: 뉴스 업데이트 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Jul 17, 2024
1 parent 54c1e8b commit fe33709
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package scul.projectscul.domain.news.presentation

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import scul.projectscul.domain.news.presentation.request.NewsListRequest
import scul.projectscul.domain.news.presentation.response.NewsListResponse
import scul.projectscul.domain.news.service.GetNewsService
import scul.projectscul.domain.user.presentation.response.MyPageResponse
import scul.projectscul.domain.news.service.UpdateNewsService

@RequestMapping("/scul/news")
@RestController
class NewsController (
private val getNewsService: GetNewsService,
private val updateNewsService: UpdateNewsService

) {

@GetMapping("/list")
fun newsList() : NewsListResponse {
return getNewsService.execute()
}
}

@PostMapping("/update")
fun updateNews(request: NewsListRequest) {
updateNewsService.execute(request)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package scul.projectscul.domain.news.presentation.request

data class NewsListRequest(

val documents: List<NewsRequest>
) {
data class NewsRequest (
val title: String,
val provider: String,
val providerLinkPage : String
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package scul.projectscul.domain.news.service

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import scul.projectscul.domain.news.domain.News
import scul.projectscul.domain.news.domain.repository.NewsRepository
import scul.projectscul.domain.news.presentation.request.NewsListRequest

@Service
@Transactional
class UpdateNewsService (
private val newsRepository: NewsRepository
) {
fun execute(request: NewsListRequest) {
request.documents.forEach { newsRequest ->
val news = News(
id = 0,
title = newsRequest.title,
provider = newsRequest.provider,
providerLinkPage = newsRequest.providerLinkPage
)
newsRepository.save(news)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SolveQuizService (
val randomValue = (Math.random()) * (16 - 9) + 8
currentUser.score + randomValue.toInt()

currentUser.SolvedCounts+1
currentUser.solvedCounts+1

val solvedQuiz = SolvedQuiz(
id = 0,
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/scul/projectscul/domain/user/domain/User.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package scul.projectscul.domain.user.domain

import com.example.kotlinpractice.global.entity.BaseUUIDEntity
import javax.persistence.*
import scul.projectscul.domain.user.domain.Enum.Tier
import java.time.LocalDate
import java.util.*
import javax.persistence.*

@Entity
class User(
Expand All @@ -24,12 +24,17 @@ class User(

val todaySolvedCounts: Int = 0,

val SolvedCounts: Int = 0,
val solvedCounts: Int = 0,

val score: Int = 0,

@Enumerated(EnumType.STRING)
val tier: Tier

) : BaseUUIDEntity(id)
) : BaseUUIDEntity(id) {

fun updateImage(image: String) {
this.profileImage = image
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package scul.projectscul.domain.user.presentation.request

import javax.persistence.*
import java.time.LocalDate
import java.time.LocalDateTime
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Size

data class ProfileUpdateRequest(

val profileImage: String
val profileImage: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class ProfileUpdateService (
fun execute(request: ProfileUpdateRequest) {
val currentUser = userFacade.getCurrentUser()

currentUser.profileImage = request.profileImage
currentUser.updateImage(request.profileImage)
}
}

0 comments on commit fe33709

Please sign in to comment.