Last active
May 31, 2020 14:08
-
-
Save dmi3coder/409db0bb851945110efce48a30590c52 to your computer and use it in GitHub Desktop.
Example of JobPostResource for React and Quarkus communication with Swagger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.quarkify.posts; | |
import net.quarkify.data.*; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.MediaType; | |
import java.util.List; | |
import org.eclipse.microprofile.openapi.annotations.Operation; | |
@Path("/posts") | |
@Produces(MediaType.APPLICATION_JSON) | |
@Consumes(MediaType.APPLICATION_JSON) | |
public class JobPostResource { | |
@GET | |
@Operation(operationId = "getPosts") | |
public List<JobPost> getAll() { | |
return JobPost.findAll().list(); | |
} | |
@POST | |
public JobPost submit(JobPost post) { | |
post.persistAndFlush(); | |
return post; | |
} | |
@GET | |
@Path("/{id}/proposals") | |
@Operation(operationId = "getJobProposals") | |
public List<JobProposal> getAllProposals(@PathParam("id") Long id) { | |
return JobProposal.find("job_post_id", id).list(); | |
} | |
@POST | |
@Path("/{id}/proposals") | |
public JobProposal submitProposal(@PathParam("id") Long id, JobProposal jobProposal) { | |
JobPost jobPost = JobPost.findById(id); | |
jobProposal.persistAndFlush(); | |
jobPost.proposals.add(jobProposal); | |
jobPost.persistAndFlush(); | |
return jobProposal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment