Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import reactor.core.publisher.Mono
open class CompaniesController(private val companyService: CompanyService) {
@GetMapping
open fun getJobs(request: ServerHttpRequest): Flux<Company> {
return companyService.findAll(request.id)
return Flux.fromIterable(companyService.findAll(request.id))
}

@GetMapping("/{id}")
open fun getJob(
@PathVariable id: String,
request: ServerHttpRequest
): Mono<Company> {
return companyService.findOne(request.id, id)
return Mono.just(companyService.findOne(request.id, id))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.linkedout.backend.controller

import com.linkedout.backend.model.JobOffer
import com.linkedout.backend.service.JobOfferService
import org.springframework.http.server.reactive.ServerHttpRequest
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/api/v1/jobOffers")
class JobOffersController(private val jobOffersService: JobOfferService) {
@GetMapping
open fun getJobOffers(request: ServerHttpRequest): Flux<JobOffer> {
return Flux.fromIterable(jobOffersService.findAll(request.id))
}

@GetMapping("/{id}")
open fun getJobOffer(
@PathVariable id: String,
request: ServerHttpRequest
): Mono<JobOffer> {
return Mono.just(jobOffersService.findOne(request.id, id))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.linkedout.backend.model

data class Company(
val id: String,
val name: String,
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.linkedout.backend.model

import java.time.LocalDate
import java.util.*

data class JobOffer(
val id: String,
val title: String,
val description: String,
val startDate: LocalDate,
val endDate: LocalDate,
val geographicArea: String,
val job: Job,
val company: Company,
val salary: Int,
val status: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import com.linkedout.common.utils.RequestResponseFactory
import com.linkedout.proto.services.Jobs.GetCompanyRequest
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Service
class CompanyService(
private val natsService: NatsService,
@Value("\${app.services.companies.subjects.findAll}") private val findAllSubject: String,
@Value("\${app.services.companies.subjects.findOne}") private val findOneSubject: String
) {
fun findAll(requestId: String): Flux<Company> {
// Request compagnies from the jobs service
fun findAll(requestId: String): List<Company> {
// Request companies from the jobs service
val response = natsService.requestWithReply(findAllSubject, RequestResponseFactory.newRequest(requestId).build())

// Handle the response
Expand All @@ -26,14 +24,14 @@ class CompanyService(

val getCompaniesResponse = response.getCompaniesResponse

return Flux.fromIterable(getCompaniesResponse.companiesList)
return getCompaniesResponse.companiesList
.map { company ->
Company(company.id, company.name)
}
}

fun findOne(requestId: String, id: String): Mono<Company> {
// Request compagny from the jobs service
fun findOne(requestId: String, id: String): Company {
// Request company from the jobs service
val request = RequestResponseFactory.newRequest(requestId)
.setGetCompanyRequest(
GetCompanyRequest.newBuilder()
Expand All @@ -49,6 +47,6 @@ class CompanyService(
}

val getCompany = response.getCompanyResponse
return Mono.just(Company(getCompany.company.id, getCompany.company.name))
return Company(getCompany.company.id, getCompany.company.name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.linkedout.backend.service

import com.linkedout.backend.model.Company
import com.linkedout.backend.model.Job
import com.linkedout.backend.model.JobOffer
import com.linkedout.common.service.NatsService
import com.linkedout.common.utils.RequestResponseFactory
import com.linkedout.proto.services.Jobs
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.time.LocalDate

@Service
class JobOfferService(
private val natsService: NatsService,
private val jobService: JobService,
private val companyService: CompanyService,
@Value("\${app.services.jobOffers.subjects.findAll}") private val findAllSubject: String,
@Value("\${app.services.jobOffers.subjects.findOne}") private val findOneSubject: String
) {
fun findAll(requestId: String): List<JobOffer> {
// Request job offers from the job service
val response = natsService.requestWithReply(findAllSubject, RequestResponseFactory.newRequest(requestId).build())

// Handle the response
if (!response.hasGetJobOffersResponse()) {
throw Exception("Invalid response")
}

val getJobOffersResponse = response.getJobOffersResponse

// TODO: Implement status with join table
return getJobOffersResponse.jobOffersList.map { jobOffer ->
JobOffer(
jobOffer.id,
jobOffer.title,
jobOffer.description,
LocalDate.parse(jobOffer.startDate),
LocalDate.parse(jobOffer.endDate),
jobOffer.geographicArea,
Job(
jobOffer.job.id,
jobOffer.job.title,
jobOffer.job.category
),
Company(
jobOffer.company.id,
jobOffer.company.name
),
jobOffer.salary,
jobOffer.status
)
}
}

fun findOne(requestId: String, id: String): JobOffer {
// Request the job offer from the job offer service
val request = RequestResponseFactory.newRequest(requestId)
.setGetJobOfferRequest(
Jobs.GetJobOfferRequest.newBuilder()
.setId(id)
)
.build()

val response = natsService.requestWithReply(findOneSubject, request)

// Handle the response
if (!response.hasGetJobOfferResponse()) {
throw Exception("Invalid response")
}

// TODO: Implement status with join table

val getJobOfferResponse = response.getJobOfferResponse
return JobOffer(
getJobOfferResponse.jobOffer.id,
getJobOfferResponse.jobOffer.title,
getJobOfferResponse.jobOffer.description,
LocalDate.parse(getJobOfferResponse.jobOffer.startDate),
LocalDate.parse(getJobOfferResponse.jobOffer.endDate),
getJobOfferResponse.jobOffer.geographicArea,
Job(
getJobOfferResponse.jobOffer.job.id,
getJobOfferResponse.jobOffer.job.title,
getJobOfferResponse.jobOffer.job.category
),
Company(
getJobOfferResponse.jobOffer.company.id,
getJobOfferResponse.jobOffer.company.name
),
getJobOfferResponse.jobOffer.salary,
getJobOfferResponse.jobOffer.status
)
}
}
4 changes: 4 additions & 0 deletions backend/api_gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ app:
subjects:
findAll: jobs.findAll
findOne: jobs.findOne
jobOffers:
subjects:
findAll: jobs.findAllJobOffers
findOne: jobs.findOneJobOffer
jobCategories:
subjects:
findAll: jobs.findAllCategories
Expand Down
1 change: 0 additions & 1 deletion backend/jobs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework:spring-jdbc")
implementation("org.springframework.cloud:spring-cloud-stream:4.0.4")
implementation("io.nats:jnats:2.17.1")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.linkedout.jobs.dto

import org.springframework.data.relational.core.mapping.Column
import java.time.LocalDate

data class JobOfferWithJobAndCompany(
@Column("jobofferid")
val jobOfferId: String,
@Column("jobid")
val jobId: String,
@Column("companyid")
val companyId: String,
@Column("joboffertitle")
val title: String,
@Column("jobofferdescription")
val description: String,
@Column("jobofferstartdate")
val startDate: LocalDate,
@Column("jobofferenddate")
val endDate: LocalDate,
@Column("joboffergeographicarea")
val geographicArea: String,
@Column("companyname")
val companyName: String,
@Column("joboffersalary")
val salary: Int,
@Column("jobcategorytitle")
val jobCategoryTitle: String,
@Column("jobtitle")
val jobTitle: String,
@Column("status")
val jobOfferStatus: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ package com.linkedout.jobs.function.companies

import com.linkedout.common.utils.RequestResponseFactory
import com.linkedout.jobs.service.CompanyService
import com.linkedout.jobs.service.JobService
import com.linkedout.proto.RequestOuterClass.Request
import com.linkedout.proto.ResponseOuterClass.Response
import com.linkedout.proto.models.CompanyOuterClass
import com.linkedout.proto.models.JobOuterClass
import com.linkedout.proto.services.Jobs
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import java.util.UUID
import java.util.function.Function

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package com.linkedout.jobs.function.companies

import com.linkedout.common.utils.RequestResponseFactory
import com.linkedout.jobs.service.CompanyService
import com.linkedout.jobs.service.JobService
import com.linkedout.proto.RequestOuterClass.Request
import com.linkedout.proto.ResponseOuterClass.Response
import com.linkedout.proto.models.CompanyOuterClass
import com.linkedout.proto.models.JobOuterClass
import com.linkedout.proto.services.Jobs
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.linkedout.jobs.function.jobOffers

import com.linkedout.common.utils.RequestResponseFactory
import com.linkedout.jobs.service.JobOfferService
import com.linkedout.proto.RequestOuterClass.Request
import com.linkedout.proto.ResponseOuterClass.Response
import com.linkedout.proto.models.CompanyOuterClass
import com.linkedout.proto.models.JobOfferOuterClass
import com.linkedout.proto.models.JobOuterClass
import com.linkedout.proto.services.Jobs
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import java.util.UUID
import java.util.function.Function

@Component
class GetJobOffer(private val jobOfferService: JobOfferService) : Function<Request, Response> {
override fun apply(t: Request): Response {
// Get the job offer from the database
val responseMono = jobOfferService.findOne(UUID.fromString(t.getJobOfferRequest.id))
.map { jobOffer ->
JobOfferOuterClass.JobOffer.newBuilder()
.setId(jobOffer.jobOfferId)
.setTitle(jobOffer.title)
.setDescription(jobOffer.description)
.setStartDate(jobOffer.startDate.toString())
.setEndDate(jobOffer.endDate.toString())
.setGeographicArea(jobOffer.geographicArea)
.setSalary(jobOffer.salary)
.setCompany(
CompanyOuterClass.Company.newBuilder()
.setId(jobOffer.companyId)
.setName(jobOffer.companyName)
)
.setJob(
JobOuterClass.Job.newBuilder()
.setId(jobOffer.jobId)
.setTitle(jobOffer.jobTitle)
.setCategory(jobOffer.jobCategoryTitle)
)
.setStatus(jobOffer.jobOfferStatus)
.build()
}
.map { jobOffer ->
Jobs.GetJobOfferResponse.newBuilder()
.setJobOffer(jobOffer)
.build()
}

// Block until the response is ready
val response = try {
responseMono.block()
} catch (e: Exception) {
return RequestResponseFactory.newFailedResponse(e.message ?: "Unknown error").build()
}
?: return RequestResponseFactory.newFailedResponse("Job offer not found", HttpStatus.NOT_FOUND).build()

return RequestResponseFactory.newSuccessfulResponse()
.setGetJobOfferResponse(response)
.build()
}
}
Loading