Skip to content

Commit

Permalink
feat: Add all freelancer profile CRUD operations (#54)
Browse files Browse the repository at this point in the history
* feat: Add freelancer skills CRUD

* feat: Add Freelancer language CRUD

* feat: Add freelancer education CRUD

* feat: Add freelancer experiences CRUD

* feat: Add freelancer achievement CRUD

* fix: Add db repositories

* fix: Add repositories to the user command and add document collections

* lint: Use linting

* fix: Change withSuccess to withStatusCode

* Payments `GetWallet` and `CreateWallet` unit testing  (#58)

* Added `GetWallet` request and response

* Added `CreatePaymentRequest` request/response

* Added inheritance from the Command Request and Response class to the

* Added  request/response

* Added `createWallet` and `getWallet` unit testing

---------

Co-authored-by: AhmedNasserG <ahmednasser217217@gmail.com>
Co-authored-by: Abdulaziz-Hassan <abdulazizhza@gmail.com>

* fix: Update user profile CRUD

Update the user profile CRUD for better information hiding and move the requests and responses into the shared folder

* fix: Remove duplicate files

---------

Co-authored-by: Abdullah Ahmad Fouad <57245606+Abdullah204@users.noreply.github.com>
Co-authored-by: AhmedNasserG <ahmednasser217217@gmail.com>
Co-authored-by: Abdulaziz-Hassan <abdulazizhza@gmail.com>
  • Loading branch information
4 people authored May 5, 2024
1 parent 1f34452 commit d8f600b
Show file tree
Hide file tree
Showing 73 changed files with 1,270 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import com.workup.payments.commands.PaymentCommandMap;
import com.workup.payments.commands.paymentrequest.CreatePaymentRequestCommand;
import com.workup.payments.commands.wallet.CreateWalletCommand;
import com.workup.payments.commands.wallet.GetWalletCommand;
import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest;
import com.workup.shared.commands.payments.paymentrequest.responses.CreatePaymentRequestResponse;
import com.workup.shared.commands.payments.wallet.requests.CreateWalletRequest;
import com.workup.shared.commands.payments.wallet.requests.GetWalletRequest;
import com.workup.shared.commands.payments.wallet.responses.CreateWalletResponse;
import com.workup.shared.commands.payments.wallet.responses.GetWalletResponse;
import com.workup.shared.enums.ServiceQueueNames;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
Expand All @@ -20,4 +26,14 @@ public class RabbitMQListener {
public CreatePaymentRequestResponse receive(CreatePaymentRequestRequest in) throws Exception {
return ((CreatePaymentRequestCommand) commandMap.getCommand("CreatePaymentRequest")).Run(in);
}

@RabbitHandler
public CreateWalletResponse receive(CreateWalletRequest in) throws Exception {
return ((CreateWalletCommand) commandMap.getCommand("CreateWallet")).Run(in);
}

@RabbitHandler
public GetWalletResponse receive(GetWalletRequest in) throws Exception {
return ((GetWalletCommand) commandMap.getCommand("GetWallet")).Run(in);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import com.workup.payments.repositories.WalletTransactionRepository;
import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest;
import com.workup.shared.commands.payments.paymentrequest.responses.CreatePaymentRequestResponse;
import com.workup.shared.commands.payments.wallet.requests.CreateWalletRequest;
import com.workup.shared.commands.payments.wallet.requests.GetWalletRequest;
import com.workup.shared.commands.payments.wallet.responses.CreateWalletResponse;
import com.workup.shared.commands.payments.wallet.responses.GetWalletResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.shared.enums.ServiceQueueNames;
import java.util.UUID;
Expand Down Expand Up @@ -98,4 +102,62 @@ void testCreatePaymentRequest() {
},
() -> fail("Payment request not found"));
}

@Test
void testCreateWalletCommand() {

CreateWalletRequest createWalletRequest =
CreateWalletRequest.builder().withFreelancerId("1").build();
CreateWalletResponse response =
(CreateWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createWalletRequest);
assertNotNull(response);
assertEquals(HttpStatusCode.CREATED, response.getStatusCode());
}

@Test
void testCreateDuplicateWalletIsInvalid() {
CreateWalletRequest createWalletRequest =
CreateWalletRequest.builder().withFreelancerId("1").build();
CreateWalletResponse response =
(CreateWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createWalletRequest);
assertNotNull(response);
assertEquals(HttpStatusCode.CREATED, response.getStatusCode());

CreateWalletResponse response2 =
(CreateWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createWalletRequest);
assertNotNull(response2);
assertEquals(HttpStatusCode.BAD_REQUEST, response2.getStatusCode());
}

@Test
void testGetValidWallet() {
CreateWalletRequest createWalletRequest =
CreateWalletRequest.builder().withFreelancerId("1").build();
CreateWalletResponse response =
(CreateWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createWalletRequest);
assertNotNull(response);
assertEquals(HttpStatusCode.CREATED, response.getStatusCode());

GetWalletRequest getWalletRequest = GetWalletRequest.builder().withFreelancerId("1").build();
GetWalletResponse getWalletResponse =
(GetWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, getWalletRequest);
assertNotNull(getWalletResponse);
assertEquals(HttpStatusCode.OK, getWalletResponse.getStatusCode());
assertEquals(0, getWalletResponse.getBalance());
}

@Test
void testGetInvalidWallet() {
GetWalletRequest getWalletRequest = GetWalletRequest.builder().withFreelancerId("1").build();
GetWalletResponse getWalletResponse =
(GetWalletResponse)
template.convertSendAndReceive(ServiceQueueNames.PAYMENTS, getWalletRequest);
assertNotNull(getWalletResponse);
assertEquals(HttpStatusCode.NOT_FOUND, getWalletResponse.getStatusCode());
}
}
1 change: 1 addition & 0 deletions services/users/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
2 changes: 1 addition & 1 deletion services/users/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>3.2.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>org.example</groupId>
<groupId>com.workup</groupId>
<artifactId>users</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>users</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.workup.users.commands;

import com.workup.shared.commands.users.requests.AddFreelancerAchievementRequest;
import com.workup.shared.commands.users.responses.AddFreelancerAchievementResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Achievement;
import com.workup.users.db.Freelancer;
import java.util.Optional;

public class AddFreelancerAchievementCommand
extends UserCommand<AddFreelancerAchievementRequest, AddFreelancerAchievementResponse> {
@Override
public AddFreelancerAchievementResponse Run(AddFreelancerAchievementRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
if (freelancerOptional.isEmpty())
return AddFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
Freelancer freelancer = freelancerOptional.get();
Achievement newAchievement =
Achievement.builder()
.withAchievement_description(request.getAchievement_description())
.withAchievement_name(request.getAchievement_name())
.withAward_date(request.getAward_date())
.withAwarded_by(request.getAwarded_by())
.build();
newAchievement = achievementRepository.save(newAchievement);
freelancer.getAchievements().add(newAchievement);
freelancerRepository.save(freelancer);
return AddFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.CREATED)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.workup.users.commands;

import com.workup.shared.commands.users.requests.AddFreelancerEducationRequest;
import com.workup.shared.commands.users.responses.AddFreelancerEducationResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Education;
import com.workup.users.db.Freelancer;
import java.util.Optional;

public class AddFreelancerEducationCommand
extends UserCommand<AddFreelancerEducationRequest, AddFreelancerEducationResponse> {

@Override
public AddFreelancerEducationResponse Run(AddFreelancerEducationRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
if (freelancerOptional.isEmpty())
return AddFreelancerEducationResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
Freelancer freelancer = freelancerOptional.get();
Education newEducation =
Education.builder()
.withCity(request.getCity())
.withDegree(request.getDegree())
.withEducation_description(request.getEducation_description())
.withEducation_start_date(request.getEducation_start_date())
.withEnd_date(request.getEnd_date())
.withGrade(request.getGrade())
.withMajor(request.getMajor())
.withSchool_name(request.getSchool_name())
.build();
newEducation = educationRepository.save(newEducation);
freelancer.getEducations().add(newEducation);
freelancerRepository.save(freelancer);
return AddFreelancerEducationResponse.builder().withStatusCode(HttpStatusCode.CREATED).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.workup.users.commands;

import com.workup.shared.commands.users.requests.AddFreelancerExperienceRequest;
import com.workup.shared.commands.users.responses.AddFreelancerExperienceResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Experience;
import com.workup.users.db.Freelancer;
import java.util.Optional;

public class AddFreelancerExperienceCommand
extends UserCommand<AddFreelancerExperienceRequest, AddFreelancerExperienceResponse> {
@Override
public AddFreelancerExperienceResponse Run(AddFreelancerExperienceRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancerId());
if (freelancerOptional.isEmpty())
return AddFreelancerExperienceResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
Freelancer freelancer = freelancerOptional.get();
Experience newExperience =
Experience.builder()
.withExperience_description(request.getExperience_description())
.withCity(request.getCity())
.withCompany_name(request.getCompany_name())
.withEmployment_end(request.getEmployment_end())
.withEmployment_start(request.getEmployment_start())
.withJob_title(request.getJob_title())
.build();
newExperience = experienceRepository.save(newExperience);
freelancer.getExperiences().add(newExperience);
freelancerRepository.save(freelancer);
return AddFreelancerExperienceResponse.builder().withStatusCode(HttpStatusCode.CREATED).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.workup.users.commands;

import com.workup.shared.commands.users.requests.AddFreelancerLanguageRequest;
import com.workup.shared.commands.users.responses.AddFreelancerLanguageResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;

public class AddFreelancerLanguageCommand
extends UserCommand<AddFreelancerLanguageRequest, AddFreelancerLanguageResponse> {

@Override
public AddFreelancerLanguageResponse Run(AddFreelancerLanguageRequest request) {
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUser_id());
if (freelancerOptional.isEmpty())
return AddFreelancerLanguageResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
Freelancer freelancer = freelancerOptional.get();
freelancer.getLanguages().add(request.getNewLanguage());
freelancerRepository.save(freelancer);
return AddFreelancerLanguageResponse.builder().withStatusCode(HttpStatusCode.CREATED).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.workup.users.commands;

import com.workup.shared.commands.users.requests.AddFreelancerSkillRequest;
import com.workup.shared.commands.users.responses.AddFreelancerSkillResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.List;
import java.util.Optional;

public class AddFreelancerSkillCommand
extends UserCommand<AddFreelancerSkillRequest, AddFreelancerSkillResponse> {

@Override
public AddFreelancerSkillResponse Run(AddFreelancerSkillRequest request) {
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUser_id());
if (freelancerOptional.isEmpty())
return AddFreelancerSkillResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
String newSkill = request.getNewSkill();
Freelancer freelancer = freelancerOptional.get();
List<String> skills = freelancer.getSkills();
if (!skills.contains(newSkill)) skills.add(newSkill);
freelancerRepository.save(freelancer);
return AddFreelancerSkillResponse.builder().withStatusCode(HttpStatusCode.CREATED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ClientGetProfileCommand

@Override
public ClientGetProfileResponse Run(ClientGetProfileRequest request) {
Optional<Client> clientOptional = clientRepository.findById(request.user_id);
Optional<Client> clientOptional = clientRepository.findById(request.getUser_id());

if (!clientOptional.isPresent()) {
return ClientGetProfileResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ public ClientSetProfileResponse Run(ClientSetProfileRequest request) {

Client client;

if (request.user_id == null) {
if (request.getUser_id() == null) {
client = Client.builder().build();
} else {
Optional<Client> clientOption = clientRepository.findById(request.user_id);
Optional<Client> clientOption = clientRepository.findById(request.getUser_id());
if (!clientOption.isPresent()) {
throw new RuntimeException("User not found");
}
client = clientOption.get();
}

if (request.name != null) {
client.setClient_name(request.name);
if (request.getName() != null) {
client.setClient_name(request.getName());
}
if (request.email != null) {
client.setEmail(request.email);
if (request.getEmail() != null) {
client.setEmail(request.getEmail());
}
if (request.city != null) {
client.setCity(request.city);
if (request.getCity() != null) {
client.setCity(request.getCity());
}
if (request.description != null) {
client.setClient_description(request.description);
if (request.getDescription() != null) {
client.setClient_description(request.getDescription());
}
if (request.industry != null) {
client.setIndustry(request.industry);
if (request.getIndustry() != null) {
client.setIndustry(request.getIndustry());
}
if (request.employee_count != null) {
client.setEmployee_count(request.employee_count);
if (request.getEmployee_count() != null) {
client.setEmployee_count(request.getEmployee_count());
}

clientRepository.save(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class FreelancerGetPhotoCommand

@Override
public FreelancerGetPhotoResponse Run(FreelancerGetPhotoRequest request) {
Optional<Client> clientOptional = clientRepository.findById(request.user_id);
Optional<Client> clientOptional = clientRepository.findById(request.getUser_id());

if (!clientOptional.isPresent()) {
return FreelancerGetPhotoResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
}
String name = PHOTO_BUCKET + request.user_id;
String name = PHOTO_BUCKET + request.getUser_id();

byte[] bytesArr;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FreelancerGetProfileBriefCommand

@Override
public FreelancerGetProfileBriefResponse Run(FreelancerGetProfileBriefRequest request) {
Optional<Freelancer> freelancer = freelancerRepository.findById(request.user_id);
Optional<Freelancer> freelancer = freelancerRepository.findById(request.getUser_id());

if (!freelancer.isPresent()) {
return FreelancerGetProfileBriefResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FreelancerGetProfileCommand

@Override
public FreelancerGetProfileResponse Run(FreelancerGetProfileRequest request) {
Optional<Freelancer> freelancer = freelancerRepository.findById(request.user_id);
Optional<Freelancer> freelancer = freelancerRepository.findById(request.getUser_id());

if (!freelancer.isPresent()) {
return FreelancerGetProfileResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public FreelancerSetProfileResponse Run(FreelancerSetProfileRequest request) {
}

freelancerRepository.save(freelancer);

return FreelancerSetProfileResponse.builder().withStatusCode(HttpStatusCode.OK).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class FreelancerSetResumeCommand
@Override
public FreelancerSetResumeResponse Run(FreelancerSetResumeRequest request) {

String name = RESUME_BUCKET + request.user_id;
String name = RESUME_BUCKET + request.getUser_id();

byte[] resume_byes_arr = Base64.getDecoder().decode(request.resume_encoded);
byte[] resume_byes_arr = Base64.getDecoder().decode(request.getResume_encoded());

try {
gridFsTemplate.store(new ByteArrayInputStream(resume_byes_arr), name);
Expand Down
Loading

0 comments on commit d8f600b

Please sign in to comment.