Skip to content

Commit

Permalink
Handled not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ImLewel committed Dec 21, 2023
1 parent 723a35d commit 96d6e2d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CompanyRestController {

fun createVacancy(vacancy: Vacancy, company: String): ResponseEntity<Int>

fun upgradeVacancy(id: Int, vacancy: Vacancy): ResponseEntity<Vacancy>
fun upgradeVacancy(id: Int, vacancy: Vacancy): ResponseEntity<Any>

fun deleteVacancy(id: Int, company: String): ResponseEntity<List<Vacancy>>
fun deleteVacancy(id: Int, company: String): ResponseEntity<Any>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class CompanyRestControllerImpl(@Autowired private val service: GeneralService)
}

@PutMapping("/upgrade/{id}")
override fun upgradeVacancy(@PathVariable("id") id: Int, @RequestBody @Validated vacancy: Vacancy): ResponseEntity<Vacancy> {
service.upgradeVacancy(id, vacancy)
return ResponseEntity.ok(service.getVacancyById(id))
override fun upgradeVacancy(@PathVariable("id") id: Int, @RequestBody @Validated vacancy: Vacancy): ResponseEntity<Any> {
val rows = service.upgradeVacancy(id, vacancy)
return if (rows > 0) ResponseEntity.ok(service.getVacancyById(id)) else ResponseEntity.notFound().build()
}

@DeleteMapping("/delete/{id}")
override fun deleteVacancy(@PathVariable("id") id: Int, @PathVariable("company") company: String): ResponseEntity<List<Vacancy>> {
service.deleteVacancy(id)
return ResponseEntity.ok(service.getCompanyVacancies(company))
override fun deleteVacancy(@PathVariable("id") id: Int, @PathVariable("company") company: String): ResponseEntity<Any> {
val rows = service.deleteVacancy(id)
return if (rows > 0) ResponseEntity.ok(service.getCompanyVacancies(company)) else ResponseEntity.notFound().build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.springcourse.findjob.models.Vacancy
interface GeneralRepository {

fun createVacancy(vacancy: Vacancy): Int
fun upgradeVacancy(id: Int, vacancy: Vacancy)
fun deleteVacancy(id: Int)
fun upgradeVacancy(id: Int, vacancy: Vacancy): Int
fun deleteVacancy(id: Int) : Int
fun getAllVacancies(): List<Vacancy>
fun getByKeyWordVacancy(keyWord: String): List<Vacancy>
fun getByFilter(vacancyFilter: Vacancy): List<Vacancy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.springcourse.findjob.models.VacancyDescription
import com.springcourse.findjob.models.VacancyRequirements
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.jdbc.core.query
import org.springframework.stereotype.Repository

@Repository
Expand All @@ -32,8 +31,8 @@ class GeneralRepositoryImpl(@Autowired private val jdbcTemplate: JdbcTemplate) :
return id
}

override fun upgradeVacancy(id: Int, vacancy: Vacancy) {
jdbcTemplate.update(
override fun upgradeVacancy(id: Int, vacancy: Vacancy): Int {
return jdbcTemplate.update(
"UPDATE vacancy SET title = ?, company = ?, schedule = ?, phoneNum = ?, age = ?, experienceAge = ?, educationDegree = ?, otherReqs = ? WHERE id = ?",
vacancy.title,
vacancy.description?.company,
Expand All @@ -47,8 +46,8 @@ class GeneralRepositoryImpl(@Autowired private val jdbcTemplate: JdbcTemplate) :
)
}

override fun deleteVacancy(id: Int) {
jdbcTemplate.update(
override fun deleteVacancy(id: Int): Int {
return jdbcTemplate.update(
"DELETE FROM vacancy WHERE id = ?",
id,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.springcourse.findjob.models.Vacancy

interface GeneralService{
fun createVacancy(vacancy: Vacancy): Int
fun upgradeVacancy(id: Int, vacancy: Vacancy)
fun deleteVacancy(id: Int)
fun upgradeVacancy(id: Int, vacancy: Vacancy): Int
fun deleteVacancy(id: Int): Int
fun getAllVacancies(): List<Vacancy>
fun getCompanyVacancies(name: String): List<Vacancy>
fun getVacancyById(id: Int): Vacancy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.springcourse.findjob.models.Vacancy
import com.springcourse.findjob.repository.GeneralRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.TransactionDefinition
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
Expand All @@ -20,9 +19,9 @@ class GeneralServiceImpl(@Autowired private val generalRepository: GeneralReposi
return generalRepository.createVacancy(vacancy)
}

override fun upgradeVacancy(id: Int, vacancy: Vacancy) {
override fun upgradeVacancy(id: Int, vacancy: Vacancy): Int {
vacancy.checkForValidity()
generalRepository.upgradeVacancy(id, vacancy)
return generalRepository.upgradeVacancy(id, vacancy)
}

override fun deleteVacancy(id: Int) = generalRepository.deleteVacancy(id)
Expand Down

0 comments on commit 96d6e2d

Please sign in to comment.