Last active
December 3, 2020 14:39
-
-
Save MafaldaLandeiro/4c79232a67d6db120d005ea294ef1e38 to your computer and use it in GitHub Desktop.
Human Resource Mutation
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 org.example.companyHumanResourcesAPI.mutation; | |
| import com.coxautodev.graphql.tools.GraphQLMutationResolver; | |
| import org.example.companyHumanResourcesAPI.dao.CompanyDAO; | |
| import org.example.companyHumanResourcesAPI.dao.HumanResourceDAO; | |
| import org.example.companyHumanResourcesAPI.domain.Company; | |
| import org.example.companyHumanResourcesAPI.domain.HumanResource; | |
| import java.util.Optional; | |
| public class HumanResourceMutation implements GraphQLMutationResolver { | |
| private HumanResourceDAO humanResourceDAO; | |
| private CompanyDAO companyDAO; | |
| public HumanResourceMutation(HumanResourceDAO humanResourceDAO, CompanyDAO companyDAO) { | |
| this.humanResourceDAO = humanResourceDAO; | |
| this.companyDAO = companyDAO; | |
| } | |
| public Optional<HumanResource> addHumanResource(String name, int age, String category, | |
| Float salary, String companyId) { | |
| Optional<Company> optionalCompany = companyDAO.getCompanyById(companyId); | |
| HumanResource humanResource = null; | |
| if (optionalCompany.isPresent()) { | |
| int id = humanResourceDAO.getNextHumanResourceId(); | |
| humanResource = new HumanResource(String.valueOf(id), name, age, category, salary, companyId); | |
| humanResourceDAO.addHumanResource(humanResource); | |
| } | |
| return (humanResource != null) ? Optional.of(humanResource) : Optional.empty(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment