Skip to content

Commit

Permalink
Added 409 code for news getting
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ghtF1re committed May 12, 2019
1 parent 25d3984 commit 10ad60f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/men/brakh/bsuirapi/controller/NewsServlet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ class NewsServlet : HttpServlet() {
val src =
srcRepo.find(type = body.source.type, name = body.source.name).firstOrNull() ?: srcRepo.add(body.source)

val news =
newsRepo.find(
title = body.title,
source = body.source,
url = body.url,
content = body.content,
urlToImage = body.urlToImage,
page = 1,
newsAtPage = 1
)
if(news.count() != 0) {
resp.writeError("This news already exist", HttpServletResponse.SC_CONFLICT)
return
}


newsRepo.add(body.copy(source = src))
resp.status = HttpServletResponse.SC_CREATED
}

/**
Expand Down

0 comments on commit 10ad60f

Please sign in to comment.