Skip to content

Commit

Permalink
Merge branch 'mahmoud/users-profile' into users-command-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandemic1617 committed May 9, 2024
2 parents a073daf + b78098a commit 332c81a
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class RemoveFreelancerAchievementCommand
extends UserCommand<RemoveFreelancerAchievementRequest, RemoveFreelancerAchievementResponse> {
@Override
public RemoveFreelancerAchievementResponse Run(RemoveFreelancerAchievementRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancerId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return RemoveFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class RemoveFreelancerEducationCommand

@Override
public RemoveFreelancerEducationResponse Run(RemoveFreelancerEducationRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return RemoveFreelancerEducationResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class RemoveFreelancerExperienceCommand
extends UserCommand<RemoveFreelancerExperienceRequest, RemoveFreelancerExperienceResponse> {
@Override
public RemoveFreelancerExperienceResponse Run(RemoveFreelancerExperienceRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return RemoveFreelancerExperienceResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RemoveFreelancerLanguageCommand
extends UserCommand<RemoveFreelancerLanguageRequest, RemoveFreelancerLanguageResponse> {
@Override
public RemoveFreelancerLanguageResponse Run(RemoveFreelancerLanguageRequest request) {
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUser_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return RemoveFreelancerLanguageResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RemoveFreelancerSkillCommand
extends UserCommand<RemoveFreelancerSkillRequest, RemoveFreelancerSkillResponse> {
@Override
public RemoveFreelancerSkillResponse Run(RemoveFreelancerSkillRequest request) {
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUser_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return RemoveFreelancerSkillResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class UpdateFreelancerAchievementCommand
extends UserCommand<UpdateFreelancerAchievementRequest, UpdateFreelancerAchievementResponse> {
@Override
public UpdateFreelancerAchievementResponse Run(UpdateFreelancerAchievementRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return UpdateFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class UpdateFreelancerEducationCommand

@Override
public UpdateFreelancerEducationResponse Run(UpdateFreelancerEducationRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return UpdateFreelancerEducationResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class UpdateFreelancerExperienceCommand
extends UserCommand<UpdateFreelancerExperienceRequest, UpdateFreelancerExperienceResponse> {
@Override
public UpdateFreelancerExperienceResponse Run(UpdateFreelancerExperienceRequest request) {
Optional<Freelancer> freelancerOptional =
freelancerRepository.findById(request.getFreelancer_id());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
return UpdateFreelancerExperienceResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,204 @@ void testGetFreelancerLanguages() {
Assertions.assertEquals(languages.size(), 1);
Assertions.assertEquals(language, languages.getFirst());
}

@Test
void testUpdateAchievement() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Achievement achievement = achievementRepository.save(UsersTestUtils.createTestAchievement());
freelancer.getAchievements().add(achievement);
freelancerRepository.save(freelancer);
String updatedName = "New Achievement Name";
String updatedAwardedBy = "New Awarded By";
UpdateFreelancerAchievementRequest request =
UpdateFreelancerAchievementRequest.builder()
.withUserId(freelancer.getId().toString())
.withAchievement_id(achievement.getId().toString())
.withNew_achievement_name(updatedName)
.withNew_awarded_by(updatedAwardedBy)
.build();
UpdateFreelancerAchievementResponse response =
(UpdateFreelancerAchievementResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);
Achievement expectedAchievement = UsersTestUtils.createTestAchievement();
expectedAchievement.setAchievement_name(updatedName);
expectedAchievement.setAwarded_by(updatedAwardedBy);
expectedAchievement.setAward_date(achievement.getAward_date());
Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Achievement updatedAchievement = freelancer.getAchievements().get(0);
UsersTestUtils.assertAchievementEquals(expectedAchievement, updatedAchievement);
}

@Test
void testUpdateEducation() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Education education = educationRepository.save(UsersTestUtils.createTestEducation());
freelancer.getEducations().add(education);
freelancerRepository.save(freelancer);

String updatedSchoolName = "New School Name";
String updatedDegree = "New Degree";
UpdateFreelancerEducationRequest request =
UpdateFreelancerEducationRequest.builder()
.withUserId(freelancer.getId().toString())
.withEducation_id(education.getId().toString())
.withNew_school_name(updatedSchoolName)
.withNew_degree(updatedDegree)
.build();
UpdateFreelancerEducationResponse response =
(UpdateFreelancerEducationResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);
Education expectedEducation = UsersTestUtils.createTestEducation();
expectedEducation.setSchool_name(updatedSchoolName);
expectedEducation.setDegree(updatedDegree);
expectedEducation.setEducation_start_date(education.getEducation_start_date());
expectedEducation.setEnd_date(education.getEnd_date());
Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Education updatedEducation = freelancer.getEducations().get(0);
UsersTestUtils.assertEducationEquals(expectedEducation, updatedEducation);
}

@Test
void testUpdateExperience() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Experience experience = experienceRepository.save(UsersTestUtils.createTestExperience());
freelancer.getExperiences().add(experience);
freelancerRepository.save(freelancer);
String updatedCompanyName = "New Company Name";
String updatedJobTitle = "New Job Title";
UpdateFreelancerExperienceRequest request =
UpdateFreelancerExperienceRequest.builder()
.withUserId(freelancer.getId().toString())
.withExperience_id(experience.getId().toString())
.withNew_company_name(updatedCompanyName)
.withNew_job_title(updatedJobTitle)
.build();
UpdateFreelancerExperienceResponse response =
(UpdateFreelancerExperienceResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);
Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
Experience expectedExperience = UsersTestUtils.createTestExperience();
expectedExperience.setCompany_name(updatedCompanyName);
expectedExperience.setJob_title(updatedJobTitle);
expectedExperience.setEmployment_start(experience.getEmployment_start());
expectedExperience.setEmployment_end(experience.getEmployment_end());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Experience updatedExperience = freelancer.getExperiences().get(0);
UsersTestUtils.assertExperienceEquals(expectedExperience, updatedExperience);
}

@Test
void testRemoveAchievement() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Achievement achievement = achievementRepository.save(UsersTestUtils.createTestAchievement());
freelancer.getAchievements().add(achievement);
freelancerRepository.save(freelancer);

RemoveFreelancerAchievementRequest request =
RemoveFreelancerAchievementRequest.builder()
.withUserId(freelancer.getId().toString())
.withAchievementId(achievement.getId().toString())
.build();
RemoveFreelancerAchievementResponse response =
(RemoveFreelancerAchievementResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);

Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Assertions.assertTrue(freelancer.getAchievements().isEmpty());
}

@Test
void testRemoveEducation() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Education education = educationRepository.save(UsersTestUtils.createTestEducation());
freelancer.getEducations().add(education);
freelancerRepository.save(freelancer);

RemoveFreelancerEducationRequest request =
RemoveFreelancerEducationRequest.builder()
.withUserId(freelancer.getId().toString())
.withEducation_id(education.getId().toString())
.build();
RemoveFreelancerEducationResponse response =
(RemoveFreelancerEducationResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);

Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Assertions.assertTrue(freelancer.getEducations().isEmpty());
}

@Test
void testRemoveExperience() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
Experience experience = experienceRepository.save(UsersTestUtils.createTestExperience());
freelancer.getExperiences().add(experience);
freelancerRepository.save(freelancer);

RemoveFreelancerExperienceRequest request =
RemoveFreelancerExperienceRequest.builder()
.withUserId(freelancer.getId().toString())
.withExperience_id(experience.getId().toString())
.build();
RemoveFreelancerExperienceResponse response =
(RemoveFreelancerExperienceResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);

Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Assertions.assertTrue(freelancer.getExperiences().isEmpty());
}

@Test
void testRemoveSkill() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
String skill = "Java";
freelancer.getSkills().add(skill);
freelancerRepository.save(freelancer);

RemoveFreelancerSkillRequest request =
RemoveFreelancerSkillRequest.builder()
.withUserId(freelancer.getId().toString())
.withSkillToRemove(skill)
.build();
RemoveFreelancerSkillResponse response =
(RemoveFreelancerSkillResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);

Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Assertions.assertTrue(freelancer.getSkills().isEmpty());
}

@Test
void testRemoveLanguage() {
Freelancer freelancer = freelancerRepository.save(UsersTestUtils.createTestFreelancer());
String language = "English";
freelancer.getLanguages().add(language);
freelancerRepository.save(freelancer);

RemoveFreelancerLanguageRequest request =
RemoveFreelancerLanguageRequest.builder()
.withUserId(freelancer.getId().toString())
.withLanguageToRemove(language)
.build();
RemoveFreelancerLanguageResponse response =
(RemoveFreelancerLanguageResponse)
template.convertSendAndReceive(ServiceQueueNames.USERS, request);

Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatusCode.OK, response.getStatusCode());
freelancer = freelancerRepository.findById(freelancer.getId().toString()).get();
Assertions.assertTrue(freelancer.getLanguages().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class RemoveFreelancerAchievementRequest extends CommandRequest {
String freelancerId;
String achievementId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class RemoveFreelancerEducationRequest extends CommandRequest {
String freelancer_id;
String education_id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class RemoveFreelancerExperienceRequest extends CommandRequest {
String freelancer_id;
String experience_id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class RemoveFreelancerLanguageRequest extends CommandRequest {
private String user_id;
private String languageToRemove;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class RemoveFreelancerSkillRequest extends CommandRequest {
String user_id;
String skillToRemove;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class UpdateFreelancerAchievementRequest extends CommandRequest {
String freelancer_id;
String achievement_id;
String new_achievement_name;
String new_awarded_by;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class UpdateFreelancerEducationRequest extends CommandRequest {
String freelancer_id;
String education_id;
String new_school_name;
String new_degree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class UpdateFreelancerExperienceRequest extends CommandRequest {
String freelancer_id;
String experience_id;
String new_company_name;
String new_job_title;
Expand Down

0 comments on commit 332c81a

Please sign in to comment.