Skip to content

Commit

Permalink
Add User profile tests for create and read (#75)
Browse files Browse the repository at this point in the history
* Created Users module, and added FreelancerRegister request and response

* Updated added builder annotation to FreelancerRegisterResponse and removed redundant @nonnull

* Removed the NonNull annotation to make the class compatible with the Builder annotation

* Addressed @Ahmad45123's comments and created a test to verify the serialization process.

* Added the DB Schema discussed in the meeting with all of its required dependencies

URL: https://docs.spring.io/spring-data/mongodb/reference/mongodb/mapping/document-references.html
Signed-off-by: Akram-Fahim <akramadel2001@gmail.com>

* Deleted commented file

Signed-off-by: Akram-Fahim <akramadel2001@gmail.com>

* Added Client Schema (I forgot about it last time :|)

Signed-off-by: Akram-Fahim <akramadel2001@gmail.com>

* Added Empty Lines to remove GitHub Warnings

Signed-off-by: Akram-Fahim <akramadel2001@gmail.com>

* added some commands

* organized imports

* added Client Get Profile

* added photo requests

* added resume command

* added user command map

* small fix

removed default value for success

* 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

* refactored requests and responses into shared folder

* fix: Change withSuccess to withStatusCode

* added tests template

* refactored code to use http satus code

* added rabbitmq listeners

* added env vars and small fixes

* reformat

* reformat

* builds successfully

* tests working using test containers

* 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

* feat: Add user profile commands to the command map

* feat: Add function handlers to RabbitMQ

* feat: Create UsersTestUtils to contain redundant testing logic

* feat: Add test for adding functionality

Added tests for the Adding operations and changed the implementation to use the userId in the CommandRequest class

* feat: Create views for education, experience and achievements

feat: Create views for education, experience and achievements and update the commands to use userId in the CommandRequest class

* fix: Update tests and commands to use userId in the CommandRequest class

* test: Add testing for the update requests

* fix: Change the update commands to use userId instead of freelancer_id

* test: Add tests for delete operations

Add tests for delete operations and change the commands to use userId instead of freelancer_id

---------

Signed-off-by: Akram-Fahim <akramadel2001@gmail.com>
Co-authored-by: Akram-Fahim <akramadel2001@gmail.com>
Co-authored-by: Pandemic1617 <43860275+Pandemic1617@users.noreply.github.com>
  • Loading branch information
3 people authored May 9, 2024
1 parent a62b1cd commit a8fc410
Show file tree
Hide file tree
Showing 107 changed files with 2,875 additions and 17 deletions.
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
41 changes: 39 additions & 2 deletions 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 All @@ -29,10 +29,15 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.workup</groupId>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -66,6 +71,38 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.11.1</version>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>rabbitmq</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
183 changes: 183 additions & 0 deletions services/users/src/main/java/com/workup/users/RabbitMQListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.workup.users;

import com.workup.shared.commands.users.requests.*;
import com.workup.shared.commands.users.responses.*;
import com.workup.shared.enums.ServiceQueueNames;
import com.workup.users.commands.*;
import com.workup.users.commands.UserCommandMap;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RabbitListener(queues = ServiceQueueNames.USERS)
public class RabbitMQListener {

@Autowired public UserCommandMap commandMap;

@RabbitHandler
public FreelancerGetProfileBriefResponse receive(FreelancerGetProfileBriefRequest in)
throws Exception {
return ((FreelancerGetProfileBriefCommand) commandMap.getCommand("FreelancerGetProfileBrief"))
.Run(in);
}

@RabbitHandler
public FreelancerGetProfileResponse receive(FreelancerGetProfileRequest in) throws Exception {
return ((FreelancerGetProfileCommand) commandMap.getCommand("FreelancerGetProfile")).Run(in);
}

@RabbitHandler
public FreelancerGetResumeResponse receive(FreelancerGetResumeRequest in) throws Exception {
return ((FreelancerGetResumeCommand) commandMap.getCommand("FreelancerGetResume")).Run(in);
}

@RabbitHandler
public FreelancerSetPhotoResponse receive(FreelancerSetPhotoRequest in) throws Exception {
return ((FreelancerSetPhotoCommand) commandMap.getCommand("FreelancerSetPhoto")).Run(in);
}

@RabbitHandler
public FreelancerSetProfileResponse receive(FreelancerSetProfileRequest in) throws Exception {
return ((FreelancerSetProfileCommand) commandMap.getCommand("FreelancerSetProfile")).Run(in);
}

@RabbitHandler
public FreelancerSetResumeResponse receive(FreelancerSetResumeRequest in) throws Exception {
return ((FreelancerSetResumeCommand) commandMap.getCommand("FreelancerSetResume")).Run(in);
}

@RabbitHandler
public FreelancerGetPhotoResponse receive(FreelancerGetPhotoRequest in) throws Exception {
return ((FreelancerGetPhotoCommand) commandMap.getCommand("FreelancerGetPhoto")).Run(in);
}

@RabbitHandler
public ClientSetProfileResponse receive(ClientSetProfileRequest in) throws Exception {
return ((ClientSetProfileCommand) commandMap.getCommand("ClientSetProfile")).Run(in);
}

@RabbitHandler
public ClientGetProfileResponse receive(ClientGetProfileRequest in) throws Exception {
return ((ClientGetProfileCommand) commandMap.getCommand("ClientGetProfile")).Run(in);
}

@RabbitHandler
public AddFreelancerAchievementResponse receive(AddFreelancerAchievementRequest in)
throws Exception {
return ((AddFreelancerAchievementCommand) commandMap.getCommand("AddFreelancerAchievement"))
.Run(in);
}

@RabbitHandler
public AddFreelancerEducationResponse receive(AddFreelancerEducationRequest in) throws Exception {
return ((AddFreelancerEducationCommand) commandMap.getCommand("AddFreelancerEducation"))
.Run(in);
}

@RabbitHandler
public AddFreelancerExperienceResponse receive(AddFreelancerExperienceRequest in)
throws Exception {
return ((AddFreelancerExperienceCommand) commandMap.getCommand("AddFreelancerExperience"))
.Run(in);
}

@RabbitHandler
public AddFreelancerSkillResponse receive(AddFreelancerSkillRequest in) throws Exception {
return ((AddFreelancerSkillCommand) commandMap.getCommand("AddFreelancerSkill")).Run(in);
}

@RabbitHandler
public AddFreelancerLanguageResponse receive(AddFreelancerLanguageRequest in) throws Exception {
return ((AddFreelancerLanguageCommand) commandMap.getCommand("AddFreelancerLanguage")).Run(in);
}

@RabbitHandler
public GetFreelancerAchievementsResponse receive(GetFreelancerAchievementsRequest in)
throws Exception {
return ((GetFreelancerAchievementsCommand) commandMap.getCommand("GetFreelancerAchievements"))
.Run(in);
}

@RabbitHandler
public GetFreelancerEducationsResponse receive(GetFreelancerEducationsRequest in)
throws Exception {
return ((GetFreelancerEducationsCommand) commandMap.getCommand("GetFreelancerEducations"))
.Run(in);
}

@RabbitHandler
public GetFreelancerExperiencesResponse receive(GetFreelancerExperiencesRequest in)
throws Exception {
return ((GetFreelancerExperiencesCommand) commandMap.getCommand("GetFreelancerExperiences"))
.Run(in);
}

@RabbitHandler
public GetFreelancerSkillsResponse receive(GetFreelancerSkillsRequest in) throws Exception {
return ((GetFreelancerSkillsCommand) commandMap.getCommand("GetFreelancerSkills")).Run(in);
}

@RabbitHandler
public GetFreelancerLanguagesResponse receive(GetFreelancerLanguagesRequest in) throws Exception {
return ((GetFreelancerLanguagesCommand) commandMap.getCommand("GetFreelancerLanguages"))
.Run(in);
}

@RabbitHandler
public UpdateFreelancerAchievementResponse receive(UpdateFreelancerAchievementRequest in)
throws Exception {
return ((UpdateFreelancerAchievementCommand)
commandMap.getCommand("UpdateFreelancerAchievement"))
.Run(in);
}

@RabbitHandler
public UpdateFreelancerEducationResponse receive(UpdateFreelancerEducationRequest in)
throws Exception {
return ((UpdateFreelancerEducationCommand) commandMap.getCommand("UpdateFreelancerEducation"))
.Run(in);
}

@RabbitHandler
public UpdateFreelancerExperienceResponse receive(UpdateFreelancerExperienceRequest in)
throws Exception {
return ((UpdateFreelancerExperienceCommand) commandMap.getCommand("UpdateFreelancerExperience"))
.Run(in);
}

@RabbitHandler
public RemoveFreelancerAchievementResponse receive(RemoveFreelancerAchievementRequest in)
throws Exception {
return ((RemoveFreelancerAchievementCommand)
commandMap.getCommand("RemoveFreelancerAchievement"))
.Run(in);
}

@RabbitHandler
public RemoveFreelancerEducationResponse receive(RemoveFreelancerEducationRequest in)
throws Exception {
return ((RemoveFreelancerEducationCommand) commandMap.getCommand("RemoveFreelancerEducation"))
.Run(in);
}

@RabbitHandler
public RemoveFreelancerExperienceResponse receive(RemoveFreelancerExperienceRequest in)
throws Exception {
return ((RemoveFreelancerExperienceCommand) commandMap.getCommand("RemoveFreelancerExperience"))
.Run(in);
}

@RabbitHandler
public RemoveFreelancerSkillResponse receive(RemoveFreelancerSkillRequest in) throws Exception {
return ((RemoveFreelancerSkillCommand) commandMap.getCommand("RemoveFreelancerSkill")).Run(in);
}

@RabbitHandler
public RemoveFreelancerLanguageResponse receive(RemoveFreelancerLanguageRequest in)
throws Exception {
return ((RemoveFreelancerLanguageCommand) commandMap.getCommand("RemoveFreelancerLanguage"))
.Run(in);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package com.workup.users;

import com.workup.shared.enums.ServiceQueueNames;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
// @EnableMongoRepositories(basePackageClasses = ClientRepository.class)
public class UsersApplication {

public static void main(String[] args) {

SpringApplication.run(UsersApplication.class, args);
}

@Bean
public Queue myQueue() {
return new Queue(ServiceQueueNames.USERS);
}

@Bean
public MessageConverter messageConverter() {
return new Jackson2JsonMessageConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.getUserId());
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,38 @@
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.getUserId());
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,35 @@
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.getUserId());
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();
}
}
Loading

0 comments on commit a8fc410

Please sign in to comment.