diff --git a/.idea/compiler.xml b/.idea/compiler.xml index a0c6be67..c2c4090a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,7 +2,9 @@ - + + + diff --git a/Makefile b/Makefile index 46d23f5e..b4f16b94 100644 --- a/Makefile +++ b/Makefile @@ -9,4 +9,7 @@ up: reload: mvn -DskipTests package - docker compose up --detach --build \ No newline at end of file + docker compose up --detach --build + +format: + mvn git-code-format:format-code -Dgcf.globPattern=**/* \ No newline at end of file diff --git a/services/users/pom.xml b/services/users/pom.xml index ff215d4a..59fb0d78 100644 --- a/services/users/pom.xml +++ b/services/users/pom.xml @@ -103,6 +103,32 @@ 1.19.7 test + + + org.mindrot + jbcrypt + 0.4 + + + + io.jsonwebtoken + jjwt-api + 0.11.2 + + + + io.jsonwebtoken + jjwt-impl + 0.11.2 + runtime + + + + io.jsonwebtoken + jjwt-jackson + 0.11.2 + runtime + diff --git a/services/users/src/main/java/com/workup/users/RabbitMQListener.java b/services/users/src/main/java/com/workup/users/RabbitMQListener.java index f5798da2..f859347d 100644 --- a/services/users/src/main/java/com/workup/users/RabbitMQListener.java +++ b/services/users/src/main/java/com/workup/users/RabbitMQListener.java @@ -63,6 +63,16 @@ public ClientGetProfileResponse receive(ClientGetProfileRequest in) throws Excep return ((ClientGetProfileCommand) commandMap.getCommand("ClientGetProfile")).Run(in); } + @RabbitHandler + public ClientSetPhotoResponse receive(ClientSetPhotoRequest in) throws Exception { + return ((ClientSetPhotoCommand) commandMap.getCommand("ClientSetPhoto")).Run(in); + } + + @RabbitHandler + public ClientGetPhotoResponse receive(ClientGetPhotoRequest in) throws Exception { + return ((ClientGetPhotoCommand) commandMap.getCommand("ClientGetPhoto")).Run(in); + } + @RabbitHandler public AddFreelancerAchievementResponse receive(AddFreelancerAchievementRequest in) throws Exception { @@ -180,4 +190,19 @@ public RemoveFreelancerLanguageResponse receive(RemoveFreelancerLanguageRequest return ((RemoveFreelancerLanguageCommand) commandMap.getCommand("RemoveFreelancerLanguage")) .Run(in); } + + @RabbitHandler + public SignUpAndInResponse receive(LoginRequest in) throws Exception { + return ((LoginCommand) commandMap.getCommand("Login")).Run(in); + } + + @RabbitHandler + public SignUpAndInResponse receive(FreelancerRegisterRequest in) throws Exception { + return ((FreelancerRegisterCommand) commandMap.getCommand("FreelancerRegister")).Run(in); + } + + @RabbitHandler + public SignUpAndInResponse receive(ClientRegisterRequest in) throws Exception { + return ((ClientRegisterCommand) commandMap.getCommand("ClientRegister")).Run(in); + } } diff --git a/services/users/src/main/java/com/workup/users/commands/ClientGetPhotoCommand.java b/services/users/src/main/java/com/workup/users/commands/ClientGetPhotoCommand.java new file mode 100644 index 00000000..43c1fd7b --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/ClientGetPhotoCommand.java @@ -0,0 +1,29 @@ +package com.workup.users.commands; + +import com.workup.shared.commands.users.requests.ClientGetPhotoRequest; +import com.workup.shared.commands.users.responses.ClientGetPhotoResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.users.db.Client; +import java.util.Optional; + +public class ClientGetPhotoCommand + extends UserCommand { + + @Override + public ClientGetPhotoResponse Run(ClientGetPhotoRequest request) { + Optional clientOptional = clientRepository.findById(request.getUserId()); + + if (!clientOptional.isPresent()) { + return ClientGetPhotoResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .build(); + } + + Client client = clientOptional.get(); + + return ClientGetPhotoResponse.builder() + .withStatusCode(HttpStatusCode.OK) + .withPhotoLink(client.getPhoto_link()) + .build(); + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/ClientGetProfileCommand.java b/services/users/src/main/java/com/workup/users/commands/ClientGetProfileCommand.java index dcac4ef7..882e2017 100644 --- a/services/users/src/main/java/com/workup/users/commands/ClientGetProfileCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/ClientGetProfileCommand.java @@ -11,7 +11,7 @@ public class ClientGetProfileCommand @Override public ClientGetProfileResponse Run(ClientGetProfileRequest request) { - Optional clientOptional = clientRepository.findById(request.getUser_id()); + Optional clientOptional = clientRepository.findById(request.getUserId()); if (!clientOptional.isPresent()) { return ClientGetProfileResponse.builder() @@ -28,7 +28,7 @@ public ClientGetProfileResponse Run(ClientGetProfileRequest request) { .withCity(client.getCity()) .withDescription(client.getClient_description()) .withIndustry(client.getIndustry()) - .withEmployee_count(client.getEmployee_count()) + .withEmployeeCount(client.getEmployee_count()) .build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/ClientRegisterCommand.java b/services/users/src/main/java/com/workup/users/commands/ClientRegisterCommand.java new file mode 100644 index 00000000..016a2b1e --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/ClientRegisterCommand.java @@ -0,0 +1,51 @@ +package com.workup.users.commands; + +import static com.workup.users.commands.utils.PasswordHasher.hashPassword; + +import com.workup.shared.commands.users.requests.ClientRegisterRequest; +import com.workup.shared.commands.users.responses.SignUpAndInResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.users.UserType; +import com.workup.users.db.Client; +import java.util.Objects; + +public class ClientRegisterCommand extends UserCommand { + + @Override + public SignUpAndInResponse Run(ClientRegisterRequest request) { + if (Objects.isNull(request.getEmail()) + || Objects.isNull(request.getPassword()) + || Objects.isNull(request.getClientName())) { + return SignUpAndInResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withSuccess(false) + .build(); + } + try { + Client client = + Client.builder() + .withEmail(request.getEmail()) + .withPassword_hash(hashPassword(request.getPassword())) + .withClient_name(request.getClientName()) + .withIndustry(request.getIndustry()) + .withClient_description(request.getDescription()) + .withEmployee_count(request.getEmployeeCount()) + .withCity(request.getCity()) + .build(); + Client savedClient = clientRepository.save(client); + + return SignUpAndInResponse.builder() + .withSuccess(true) + .withUserName(savedClient.getEmail()) + .withUserId(savedClient.getId().toString()) + .withUserType(UserType.CLIENT) + .withStatusCode(HttpStatusCode.OK) + .build(); + } catch (Exception e) { + return SignUpAndInResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withSuccess(false) + .build(); + } + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/ClientSetPhotoCommand.java b/services/users/src/main/java/com/workup/users/commands/ClientSetPhotoCommand.java new file mode 100644 index 00000000..e1b71cd8 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/ClientSetPhotoCommand.java @@ -0,0 +1,29 @@ +package com.workup.users.commands; + +import com.workup.shared.commands.users.requests.ClientSetPhotoRequest; +import com.workup.shared.commands.users.responses.ClientSetPhotoResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.users.db.Client; +import java.util.Optional; + +public class ClientSetPhotoCommand + extends UserCommand { + + @Override + public ClientSetPhotoResponse Run(ClientSetPhotoRequest request) { + + Optional clientOption = clientRepository.findById(request.getUserId()); + + if (!clientOption.isPresent()) { + throw new RuntimeException("User not found"); + } + + Client client = clientOption.get(); + + client.setPhoto_link(request.photoLink); + + clientRepository.save(client); + + return ClientSetPhotoResponse.builder().withStatusCode(HttpStatusCode.OK).build(); + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/ClientSetProfileCommand.java b/services/users/src/main/java/com/workup/users/commands/ClientSetProfileCommand.java index 2f8db954..3341bcc1 100644 --- a/services/users/src/main/java/com/workup/users/commands/ClientSetProfileCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/ClientSetProfileCommand.java @@ -14,10 +14,10 @@ public ClientSetProfileResponse Run(ClientSetProfileRequest request) { Client client; - if (request.getUser_id() == null) { + if (request.getUserId() == null) { client = Client.builder().build(); } else { - Optional clientOption = clientRepository.findById(request.getUser_id()); + Optional clientOption = clientRepository.findById(request.getUserId()); if (!clientOption.isPresent()) { throw new RuntimeException("User not found"); } @@ -39,8 +39,8 @@ public ClientSetProfileResponse Run(ClientSetProfileRequest request) { if (request.getIndustry() != null) { client.setIndustry(request.getIndustry()); } - if (request.getEmployee_count() != null) { - client.setEmployee_count(request.getEmployee_count()); + if (request.getEmployeeCount() != null) { + client.setEmployee_count(request.getEmployeeCount()); } clientRepository.save(client); diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerGetPhotoCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerGetPhotoCommand.java index a0203e51..99867f8a 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerGetPhotoCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerGetPhotoCommand.java @@ -3,8 +3,7 @@ import com.workup.shared.commands.users.requests.FreelancerGetPhotoRequest; import com.workup.shared.commands.users.responses.FreelancerGetPhotoResponse; import com.workup.shared.enums.HttpStatusCode; -import com.workup.users.db.Client; -import java.util.Base64; +import com.workup.users.db.Freelancer; import java.util.Optional; public class FreelancerGetPhotoCommand @@ -12,29 +11,19 @@ public class FreelancerGetPhotoCommand @Override public FreelancerGetPhotoResponse Run(FreelancerGetPhotoRequest request) { - Optional clientOptional = clientRepository.findById(request.getUser_id()); + Optional freelancerOptional = freelancerRepository.findById(request.getUserId()); - if (!clientOptional.isPresent()) { + if (!freelancerOptional.isPresent()) { return FreelancerGetPhotoResponse.builder() .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) .build(); } - String name = PHOTO_BUCKET + request.getUser_id(); - byte[] bytesArr; - try { - bytesArr = gridFsTemplate.getResource(name).getInputStream().readAllBytes(); - } catch (Exception e) { - return FreelancerGetPhotoResponse.builder() - .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) - .build(); - } - - String base64Encoded = Base64.getEncoder().encodeToString(bytesArr); + Freelancer freelancer = freelancerOptional.get(); return FreelancerGetPhotoResponse.builder() .withStatusCode(HttpStatusCode.OK) - .withPhotoEncoded(base64Encoded) + .withPhotoLink(freelancer.getPhoto_link()) .build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileBriefCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileBriefCommand.java index e23c7483..fddec877 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileBriefCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileBriefCommand.java @@ -11,7 +11,7 @@ public class FreelancerGetProfileBriefCommand @Override public FreelancerGetProfileBriefResponse Run(FreelancerGetProfileBriefRequest request) { - Optional freelancer = freelancerRepository.findById(request.getUser_id()); + Optional freelancer = freelancerRepository.findById(request.getUserId()); if (!freelancer.isPresent()) { return FreelancerGetProfileBriefResponse.builder() @@ -22,7 +22,7 @@ public FreelancerGetProfileBriefResponse Run(FreelancerGetProfileBriefRequest re return FreelancerGetProfileBriefResponse.builder() .withStatusCode(HttpStatusCode.OK) .withEmail(freelancer.get().getEmail()) - .withFull_name(freelancer.get().getFull_name()) + .withFullName(freelancer.get().getFullName()) .build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileCommand.java index 14de14a3..384fca09 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerGetProfileCommand.java @@ -11,7 +11,7 @@ public class FreelancerGetProfileCommand @Override public FreelancerGetProfileResponse Run(FreelancerGetProfileRequest request) { - Optional freelancer = freelancerRepository.findById(request.getUser_id()); + Optional freelancer = freelancerRepository.findById(request.getUserId()); if (!freelancer.isPresent()) { return FreelancerGetProfileResponse.builder() @@ -21,12 +21,12 @@ public FreelancerGetProfileResponse Run(FreelancerGetProfileRequest request) { return FreelancerGetProfileResponse.builder() .withStatusCode(HttpStatusCode.OK) - .withBirth_date(freelancer.get().getBirthdate()) + .withBirthDate(freelancer.get().getBirthdate()) .withCity(freelancer.get().getCity()) .withDescription(freelancer.get().getDescription()) .withEmail(freelancer.get().getEmail()) - .withFull_name(freelancer.get().getFull_name()) - .withJob_title(freelancer.get().getJob_title()) + .withFullName(freelancer.get().getFullName()) + .withJobTitle(freelancer.get().getJob_title()) .withLanguages(freelancer.get().getLanguages()) .withSkills(freelancer.get().getSkills()) .build(); diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerGetResumeCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerGetResumeCommand.java index 82058cfe..ef11b3ea 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerGetResumeCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerGetResumeCommand.java @@ -3,8 +3,7 @@ import com.workup.shared.commands.users.requests.FreelancerGetResumeRequest; import com.workup.shared.commands.users.responses.FreelancerGetResumeResponse; import com.workup.shared.enums.HttpStatusCode; -import com.workup.users.db.Client; -import java.util.Base64; +import com.workup.users.db.Freelancer; import java.util.Optional; public class FreelancerGetResumeCommand @@ -12,29 +11,19 @@ public class FreelancerGetResumeCommand @Override public FreelancerGetResumeResponse Run(FreelancerGetResumeRequest request) { - Optional clientOptional = clientRepository.findById(request.user_id); + Optional freelancerOptional = freelancerRepository.findById(request.getUserId()); - if (!clientOptional.isPresent()) { + if (!freelancerOptional.isPresent()) { return FreelancerGetResumeResponse.builder() .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) .build(); } - String name = RESUME_BUCKET + request.user_id; - byte[] bytesArr; - try { - bytesArr = gridFsTemplate.getResource(name).getInputStream().readAllBytes(); - } catch (Exception e) { - return FreelancerGetResumeResponse.builder() - .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) - .build(); - } - - String base64Encoded = Base64.getEncoder().encodeToString(bytesArr); + Freelancer freelancer = freelancerOptional.get(); return FreelancerGetResumeResponse.builder() .withStatusCode(HttpStatusCode.OK) - .withResumeEncoded(base64Encoded) + .withResumeLink(freelancer.getResume_link()) .build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerRegisterCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerRegisterCommand.java new file mode 100644 index 00000000..ff0c0a39 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerRegisterCommand.java @@ -0,0 +1,59 @@ +package com.workup.users.commands; + +import static com.workup.users.commands.utils.PasswordHasher.hashPassword; + +import com.workup.shared.commands.payments.wallet.requests.CreateWalletRequest; +import com.workup.shared.commands.users.requests.FreelancerRegisterRequest; +import com.workup.shared.commands.users.responses.SignUpAndInResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.ServiceQueueNames; +import com.workup.shared.enums.users.UserType; +import com.workup.users.db.Freelancer; +import java.util.Objects; + +public class FreelancerRegisterCommand + extends UserCommand { + + @Override + public SignUpAndInResponse Run(FreelancerRegisterRequest request) { + if (Objects.isNull(request.getEmail()) + || Objects.isNull(request.getPassword()) + || Objects.isNull(request.getFullName())) { + return SignUpAndInResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withSuccess(false) + .build(); + } + try { + Freelancer freelancer = + Freelancer.builder() + .withEmail(request.getEmail()) + .withPassword_hash(hashPassword(request.getPassword())) + .withFullName(request.getFullName()) + .withJob_title(request.getJobTitle()) + .withCity(request.getCity()) + .build(); + Freelancer savedFreelancer = freelancerRepository.save(freelancer); + // create wallet + CreateWalletRequest createWalletRequest = + CreateWalletRequest.builder() + .withUserId(savedFreelancer.getId().toString()) + .withFreelancerId(savedFreelancer.getId().toString()) + .build(); + rabbitTemplate.convertSendAndReceive(ServiceQueueNames.PAYMENTS, createWalletRequest); + + return SignUpAndInResponse.builder() + .withSuccess(true) + .withUserName(savedFreelancer.getEmail()) + .withUserId(savedFreelancer.getId().toString()) + .withUserType(UserType.FREELANCER) + .withStatusCode(HttpStatusCode.OK) + .build(); + } catch (Exception e) { + return SignUpAndInResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withSuccess(false) + .build(); + } + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerSetPhotoCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerSetPhotoCommand.java index 2014943a..13aa1acb 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerSetPhotoCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerSetPhotoCommand.java @@ -3,8 +3,8 @@ import com.workup.shared.commands.users.requests.FreelancerSetPhotoRequest; import com.workup.shared.commands.users.responses.FreelancerSetPhotoResponse; import com.workup.shared.enums.HttpStatusCode; -import java.io.ByteArrayInputStream; -import java.util.Base64; +import com.workup.users.db.Freelancer; +import java.util.Optional; public class FreelancerSetPhotoCommand extends UserCommand { @@ -12,17 +12,18 @@ public class FreelancerSetPhotoCommand @Override public FreelancerSetPhotoResponse Run(FreelancerSetPhotoRequest request) { - String name = PHOTO_BUCKET + request.user_id; + Optional freelancerOption = freelancerRepository.findById(request.getUserId()); - byte[] photo_bytes_arr = Base64.getDecoder().decode(request.photo_encoded); - - try { - gridFsTemplate.store(new ByteArrayInputStream(photo_bytes_arr), name); - } catch (Exception e) { - return FreelancerSetPhotoResponse.builder() - .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) - .build(); + if (!freelancerOption.isPresent()) { + throw new RuntimeException("User not found"); } + + Freelancer freelancer = freelancerOption.get(); + + freelancer.setPhoto_link(request.photoLink); + + freelancerRepository.save(freelancer); + return FreelancerSetPhotoResponse.builder().withStatusCode(HttpStatusCode.OK).build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerSetProfileCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerSetProfileCommand.java index edbe91f5..6e2622a6 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerSetProfileCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerSetProfileCommand.java @@ -13,31 +13,31 @@ public class FreelancerSetProfileCommand public FreelancerSetProfileResponse Run(FreelancerSetProfileRequest request) { Freelancer freelancer; - if (request.user_id == null) { + if (request.getUserId() == null) { freelancer = Freelancer.builder().withId(null).build(); } else { - Optional freelancerOption = freelancerRepository.findById(request.user_id); + Optional freelancerOption = freelancerRepository.findById(request.getUserId()); if (!freelancerOption.isPresent()) { throw new RuntimeException("User not found"); } freelancer = freelancerOption.get(); } - if (request.birth_date != null) { - freelancer.setBirthdate(request.birth_date); + if (request.getBirthDate() != null) { + freelancer.setBirthdate(request.getBirthDate()); } if (request.description != null) { freelancer.setDescription(request.description); } - if (request.job_title != null) { - freelancer.setJob_title(request.job_title); + if (request.getJobTitle() != null) { + freelancer.setJob_title(request.getJobTitle()); } if (request.city != null) { freelancer.setCity(request.city); } - if (request.full_name != null) { - freelancer.setFull_name(request.full_name); + if (request.fullName != null) { + freelancer.setFullName(request.fullName); } if (request.email != null) { freelancer.setEmail(request.email); diff --git a/services/users/src/main/java/com/workup/users/commands/FreelancerSetResumeCommand.java b/services/users/src/main/java/com/workup/users/commands/FreelancerSetResumeCommand.java index 3fe74def..d1fc0a9a 100644 --- a/services/users/src/main/java/com/workup/users/commands/FreelancerSetResumeCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/FreelancerSetResumeCommand.java @@ -3,8 +3,8 @@ import com.workup.shared.commands.users.requests.FreelancerSetResumeRequest; import com.workup.shared.commands.users.responses.FreelancerSetResumeResponse; import com.workup.shared.enums.HttpStatusCode; -import java.io.ByteArrayInputStream; -import java.util.Base64; +import com.workup.users.db.Freelancer; +import java.util.Optional; public class FreelancerSetResumeCommand extends UserCommand { @@ -12,17 +12,18 @@ public class FreelancerSetResumeCommand @Override public FreelancerSetResumeResponse Run(FreelancerSetResumeRequest request) { - String name = RESUME_BUCKET + request.getUser_id(); + Optional freelancerOption = freelancerRepository.findById(request.getUserId()); - byte[] resume_byes_arr = Base64.getDecoder().decode(request.getResume_encoded()); - - try { - gridFsTemplate.store(new ByteArrayInputStream(resume_byes_arr), name); - } catch (Exception e) { - return FreelancerSetResumeResponse.builder() - .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) - .build(); + if (!freelancerOption.isPresent()) { + throw new RuntimeException("User not found"); } + + Freelancer freelancer = freelancerOption.get(); + + freelancer.setResume_link(request.resumeLink); + + freelancerRepository.save(freelancer); + return FreelancerSetResumeResponse.builder().withStatusCode(HttpStatusCode.OK).build(); } } diff --git a/services/users/src/main/java/com/workup/users/commands/LoginCommand.java b/services/users/src/main/java/com/workup/users/commands/LoginCommand.java new file mode 100644 index 00000000..6fc9183c --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/LoginCommand.java @@ -0,0 +1,57 @@ +package com.workup.users.commands; + +import com.workup.shared.commands.users.requests.LoginRequest; +import com.workup.shared.commands.users.responses.SignUpAndInResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.users.UserType; +import com.workup.users.commands.utils.PasswordHasher; +import com.workup.users.db.Client; +import com.workup.users.db.Freelancer; +import java.util.Optional; + +public class LoginCommand extends UserCommand { + + @Override + public SignUpAndInResponse Run(LoginRequest request) { + String email = request.getEmail(); + String password = request.getPassword(); + try { + Optional client = clientRepository.findByEmail(email); + if (client.isPresent()) { + if (PasswordHasher.checkPassword(password, client.get().getPassword_hash())) { + return SignUpAndInResponse.builder() + .withSuccess(true) + .withUserName(client.get().getEmail()) + .withUserId(client.get().getId().toString()) + .withUserType(UserType.CLIENT) + .withStatusCode(HttpStatusCode.OK) + .build(); + } + } + // check if freelancer + Optional freelancer = freelancerRepository.findByEmail(email); + if (freelancer.isPresent()) { + if (PasswordHasher.checkPassword(password, freelancer.get().getPassword_hash())) { + return SignUpAndInResponse.builder() + .withSuccess(true) + .withUserName(freelancer.get().getEmail()) + .withUserId(freelancer.get().getId().toString()) + .withUserType(UserType.FREELANCER) + .withStatusCode(HttpStatusCode.OK) + .build(); + } + } + + // return unauthorized + return SignUpAndInResponse.builder() + .withSuccess(false) + .withStatusCode(HttpStatusCode.UNAUTHORIZED) + .build(); + } catch (Exception e) { + return SignUpAndInResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withSuccess(false) + .build(); + } + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/UserCommand.java b/services/users/src/main/java/com/workup/users/commands/UserCommand.java index efb85fb9..0f7d7f5c 100644 --- a/services/users/src/main/java/com/workup/users/commands/UserCommand.java +++ b/services/users/src/main/java/com/workup/users/commands/UserCommand.java @@ -7,6 +7,7 @@ import com.workup.users.repositories.ExperienceRepository; import com.workup.users.repositories.FreelancerRepository; import lombok.Setter; +import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.gridfs.GridFsTemplate; @@ -28,5 +29,6 @@ public abstract class UserCommand< @Setter ClientRepository clientRepository; + @Setter AmqpTemplate rabbitTemplate; @Autowired GridFsTemplate gridFsTemplate; } diff --git a/services/users/src/main/java/com/workup/users/commands/UserCommandMap.java b/services/users/src/main/java/com/workup/users/commands/UserCommandMap.java index 91e984b6..70e4139f 100644 --- a/services/users/src/main/java/com/workup/users/commands/UserCommandMap.java +++ b/services/users/src/main/java/com/workup/users/commands/UserCommandMap.java @@ -4,6 +4,7 @@ import com.workup.shared.commands.CommandRequest; import com.workup.shared.commands.CommandResponse; import com.workup.users.repositories.*; +import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ public class UserCommandMap @Autowired ClientRepository clientRepository; @Autowired EducationRepository educationRepository; @Autowired AchievementRepository achievementRepository; + @Autowired AmqpTemplate rabbitTemplate; public void registerCommands() { @@ -32,6 +34,9 @@ public void registerCommands() { commands.put("ClientGetProfile", ClientGetProfileCommand.class); commands.put("ClientSetProfile", ClientSetProfileCommand.class); + commands.put("ClientGetPhoto", ClientGetPhotoCommand.class); + commands.put("ClientSetPhoto", ClientSetPhotoCommand.class); + commands.put("AddFreelancerAchievement", AddFreelancerAchievementCommand.class); commands.put("AddFreelancerEducation", AddFreelancerEducationCommand.class); commands.put("AddFreelancerExperience", AddFreelancerExperienceCommand.class); @@ -53,6 +58,10 @@ public void registerCommands() { commands.put("UpdateFreelancerAchievement", UpdateFreelancerAchievementCommand.class); commands.put("UpdateFreelancerEducation", UpdateFreelancerEducationCommand.class); commands.put("UpdateFreelancerExperience", UpdateFreelancerExperienceCommand.class); + + commands.put("Login", LoginCommand.class); + commands.put("FreelancerRegister", FreelancerRegisterCommand.class); + commands.put("ClientRegister", ClientRegisterCommand.class); // NEW_COMMAND_BOILERPLATE } @@ -64,5 +73,6 @@ public void setupCommand( command.setClientRepository(clientRepository); command.setEducationRepository(educationRepository); command.setAchievementRepository(achievementRepository); + command.setRabbitTemplate(rabbitTemplate); } } diff --git a/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerAchievementsResponse.java b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerAchievementsResponse.java new file mode 100644 index 00000000..10ce5eb2 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerAchievementsResponse.java @@ -0,0 +1,15 @@ +package com.workup.users.commands.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.users.db.Achievement; +import java.util.List; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetFreelancerAchievementsResponse extends CommandResponse { + List achievements; +} diff --git a/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerEducationsResponse.java b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerEducationsResponse.java new file mode 100644 index 00000000..4b5608b7 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerEducationsResponse.java @@ -0,0 +1,15 @@ +package com.workup.users.commands.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.users.db.Education; +import java.util.List; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetFreelancerEducationsResponse extends CommandResponse { + List educations; +} diff --git a/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerExperiencesResponse.java b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerExperiencesResponse.java new file mode 100644 index 00000000..b6930462 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/responses/GetFreelancerExperiencesResponse.java @@ -0,0 +1,15 @@ +package com.workup.users.commands.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.users.db.Experience; +import java.util.List; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetFreelancerExperiencesResponse extends CommandResponse { + private List experiences; +} diff --git a/services/users/src/main/java/com/workup/users/commands/utils/AuthTokenHandler.java b/services/users/src/main/java/com/workup/users/commands/utils/AuthTokenHandler.java new file mode 100644 index 00000000..475546ea --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/utils/AuthTokenHandler.java @@ -0,0 +1,27 @@ +package com.workup.users.commands.utils; + +import io.jsonwebtoken.*; +import java.util.Date; + +public class AuthTokenHandler { + private static final String SECRET_KEY = System.getenv("SECRET_KEY"); + private static final JwtParser parser = Jwts.parserBuilder().setSigningKey(SECRET_KEY).build(); + + public static String generateToken(String email) { + Date now = new Date(); + Date expiryDate = new Date(now.getTime() + 3600000); // Token expires in 1 hour + + return Jwts.builder() + .setSubject(email) + .setIssuedAt(now) + .setExpiration(expiryDate) + .signWith(SignatureAlgorithm.HS512, SECRET_KEY) + .compact(); + } + + public static String decodeToken(String token) { + Jws claimsJws = parser.parseClaimsJws(token); + Claims body = claimsJws.getBody(); + return body.getSubject(); + } +} diff --git a/services/users/src/main/java/com/workup/users/commands/utils/PasswordHasher.java b/services/users/src/main/java/com/workup/users/commands/utils/PasswordHasher.java new file mode 100644 index 00000000..87bebe26 --- /dev/null +++ b/services/users/src/main/java/com/workup/users/commands/utils/PasswordHasher.java @@ -0,0 +1,13 @@ +package com.workup.users.commands.utils; + +import org.mindrot.jbcrypt.BCrypt; + +public class PasswordHasher { + public static String hashPassword(String password) { + return BCrypt.hashpw(password, BCrypt.gensalt()); + } + + public static boolean checkPassword(String inputPassword, String hashedPassword) { + return BCrypt.checkpw(inputPassword, hashedPassword); + } +} diff --git a/services/users/src/main/java/com/workup/users/db/Client.java b/services/users/src/main/java/com/workup/users/db/Client.java index 214acfd7..acff0d3c 100644 --- a/services/users/src/main/java/com/workup/users/db/Client.java +++ b/services/users/src/main/java/com/workup/users/db/Client.java @@ -15,14 +15,16 @@ @Document public class Client { @Id private ObjectId id; - @Indexed private String email; + + @Indexed(unique = true) + private String email; private String password_hash; private Date created_at; private String client_name; private String industry; private String city; - private String photo_id; + private String photo_link; private String client_description; private Integer employee_count; } diff --git a/services/users/src/main/java/com/workup/users/db/Freelancer.java b/services/users/src/main/java/com/workup/users/db/Freelancer.java index ba00ba2c..a51f4a7e 100644 --- a/services/users/src/main/java/com/workup/users/db/Freelancer.java +++ b/services/users/src/main/java/com/workup/users/db/Freelancer.java @@ -17,16 +17,18 @@ @Document(collection = "Freelancer") public class Freelancer { @Id private ObjectId id; - @Indexed private String email; + + @Indexed(unique = true) + private String email; private String password_hash; private Date created_at; - private String full_name; + private String fullName; private Date birthdate; - private String resume_id; + private String resume_link; private String city; private String job_title; - private String photo_id; + private String photo_link; private String description; private List skills; private List languages; diff --git a/services/users/src/main/java/com/workup/users/repositories/ClientRepository.java b/services/users/src/main/java/com/workup/users/repositories/ClientRepository.java index 59d0ca4a..b3af5feb 100644 --- a/services/users/src/main/java/com/workup/users/repositories/ClientRepository.java +++ b/services/users/src/main/java/com/workup/users/repositories/ClientRepository.java @@ -1,6 +1,10 @@ package com.workup.users.repositories; import com.workup.users.db.Client; +import java.util.Optional; import org.springframework.data.mongodb.repository.MongoRepository; -public interface ClientRepository extends MongoRepository {} +public interface ClientRepository extends MongoRepository { + // find by clientEmail + Optional findByEmail(String email); +} diff --git a/services/users/src/main/java/com/workup/users/repositories/FreelancerRepository.java b/services/users/src/main/java/com/workup/users/repositories/FreelancerRepository.java index 87194732..74b38922 100644 --- a/services/users/src/main/java/com/workup/users/repositories/FreelancerRepository.java +++ b/services/users/src/main/java/com/workup/users/repositories/FreelancerRepository.java @@ -1,6 +1,10 @@ package com.workup.users.repositories; import com.workup.users.db.Freelancer; +import java.util.Optional; import org.springframework.data.mongodb.repository.MongoRepository; -public interface FreelancerRepository extends MongoRepository {} +public interface FreelancerRepository extends MongoRepository { + // find by freelancerEmail + Optional findByEmail(String email); +} diff --git a/services/users/src/main/resources/application.properties b/services/users/src/main/resources/application.properties index cbbffada..0a6f3603 100644 --- a/services/users/src/main/resources/application.properties +++ b/services/users/src/main/resources/application.properties @@ -8,3 +8,4 @@ spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest +SECRET_KEY=j4#BbFGfoc^2k*Bz diff --git a/services/users/src/test/java/com/workup/users/PaymentMockingListener.java b/services/users/src/test/java/com/workup/users/PaymentMockingListener.java new file mode 100644 index 00000000..fe06b055 --- /dev/null +++ b/services/users/src/test/java/com/workup/users/PaymentMockingListener.java @@ -0,0 +1,21 @@ +package com.workup.users; + +import com.workup.shared.commands.payments.wallet.requests.CreateWalletRequest; +import com.workup.shared.commands.payments.wallet.responses.CreateWalletResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.ServiceQueueNames; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Service; + +@Service +@RabbitListener(queues = ServiceQueueNames.PAYMENTS) +public class PaymentMockingListener { + + public static HttpStatusCode statusCodeToBeReturned; + + @RabbitHandler + public CreateWalletResponse receive(CreateWalletRequest in) throws Exception { + return CreateWalletResponse.builder().withStatusCode(statusCodeToBeReturned).build(); + } +} diff --git a/services/users/src/test/java/com/workup/users/RequestsAndResponsesTest.java b/services/users/src/test/java/com/workup/users/RequestsAndResponsesTest.java index f005e3a8..fc381b9c 100644 --- a/services/users/src/test/java/com/workup/users/RequestsAndResponsesTest.java +++ b/services/users/src/test/java/com/workup/users/RequestsAndResponsesTest.java @@ -4,13 +4,20 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.workup.shared.commands.users.requests.AuthenticationRequest; +import com.workup.shared.commands.users.requests.ClientRegisterRequest; import com.workup.shared.commands.users.requests.FreelancerRegisterRequest; -import com.workup.shared.commands.users.responses.FreelancerRegisterResponse; +import com.workup.shared.commands.users.requests.LoginRequest; +import com.workup.shared.commands.users.responses.SignUpAndInResponse; import org.junit.jupiter.api.Test; public class RequestsAndResponsesTest { private static Object[] testObjects = { // all requests/responses to be tested - FreelancerRegisterRequest.builder().build(), FreelancerRegisterResponse.builder().build(), + FreelancerRegisterRequest.builder().build(), + SignUpAndInResponse.builder().build(), + AuthenticationRequest.builder().build(), + ClientRegisterRequest.builder().build(), + LoginRequest.builder().build() }; @Test diff --git a/services/users/src/test/java/com/workup/users/TestConfigBase.java b/services/users/src/test/java/com/workup/users/TestConfigBase.java index d6a46e4e..b78185ba 100644 --- a/services/users/src/test/java/com/workup/users/TestConfigBase.java +++ b/services/users/src/test/java/com/workup/users/TestConfigBase.java @@ -9,7 +9,7 @@ public class TestConfigBase { @Bean - public Queue usersQueueMock() { - return new Queue(ServiceQueueNames.USERS); + public Queue payementQueueMock() { + return new Queue(ServiceQueueNames.PAYMENTS); } } diff --git a/services/users/src/test/java/com/workup/users/UsersApplicationTests.java b/services/users/src/test/java/com/workup/users/UsersApplicationTests.java index f87a82be..1404b271 100644 --- a/services/users/src/test/java/com/workup/users/UsersApplicationTests.java +++ b/services/users/src/test/java/com/workup/users/UsersApplicationTests.java @@ -1,18 +1,17 @@ package com.workup.users; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import com.workup.shared.commands.users.requests.*; import com.workup.shared.commands.users.responses.*; import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; +import com.workup.shared.enums.users.UserType; import com.workup.shared.views.users.AchievementView; import com.workup.shared.views.users.EducationView; import com.workup.shared.views.users.ExperienceView; -import com.workup.users.db.Achievement; -import com.workup.users.db.Education; -import com.workup.users.db.Experience; -import com.workup.users.db.Freelancer; +import com.workup.users.commands.utils.PasswordHasher; +import com.workup.users.db.*; import com.workup.users.repositories.*; import java.sql.Date; import java.time.Instant; @@ -51,6 +50,7 @@ class UsersApplicationTests { @Autowired private FreelancerRepository freelancerRepository; @Autowired private AchievementRepository achievementRepository; @Autowired private EducationRepository educationRepository; + @Autowired private ClientRepository clientRepository; @BeforeEach void clearAll() { @@ -80,22 +80,75 @@ static void setDatasourceProperties(DynamicPropertyRegistry registry) { } @Test - void testCreateUser() { - var freelancerObj = - Freelancer.builder() - .withEmail("ahmad45123@gmail.com") - .withPassword_hash("verysecurepassword") - .withFull_name("Mr. Mamdouh") - .withJob_title("Software Engineer") - .withCity("Cairo") - .withBirthdate(Date.from(Instant.now())) + public void testFreelancerRegister() { + Freelancer freelancer = UsersTestUtils.generateRandomFreelancer(); + FreelancerRegisterRequest request = + FreelancerRegisterRequest.builder() + .withEmail(freelancer.getEmail()) + .withPassword(freelancer.getPassword_hash()) + .withFullName(freelancer.getFullName()) + .withCity(freelancer.getCity()) + .withJobTitle(freelancer.getJob_title()) + .withBirthDate(freelancer.getBirthdate()) .build(); + SignUpAndInResponse response = + (SignUpAndInResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + UsersTestUtils.verifySignUpAndInResponse(response, freelancer.getEmail(), UserType.FREELANCER); + } - freelancerRepository.save(freelancerObj); + @Test + public void testFreelancerLogin() { + String password = "password"; + String hashedPassword = PasswordHasher.hashPassword(password); + Freelancer randomFreelancer = UsersTestUtils.generateRandomFreelancer(); + randomFreelancer.setPassword_hash(hashedPassword); + Freelancer freelancer = freelancerRepository.save(randomFreelancer); + LoginRequest request = + LoginRequest.builder().withEmail(freelancer.getEmail()).withPassword(password).build(); + SignUpAndInResponse response = + (SignUpAndInResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + UsersTestUtils.verifySignUpAndInResponse(response, freelancer.getEmail(), UserType.FREELANCER); + } + + @Test + public void testClientRegister() { + Client client = UsersTestUtils.generateRandomClient(); + ClientRegisterRequest request = + ClientRegisterRequest.builder() + .withEmail(client.getEmail()) + .withPassword(client.getPassword_hash()) + .withCity(client.getCity()) + .withDescription(client.getClient_description()) + .withClientName(client.getClient_name()) + .withEmployeeCount(client.getEmployee_count()) + .withIndustry(client.getIndustry()) + .build(); + SignUpAndInResponse response = + (SignUpAndInResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + UsersTestUtils.verifySignUpAndInResponse(response, client.getEmail(), UserType.CLIENT); + } + + @Test + public void testClientLogin() { + String password = "password"; + String hashedPassword = PasswordHasher.hashPassword(password); + Client randomClient = UsersTestUtils.generateRandomClient(); + randomClient.setPassword_hash(hashedPassword); + Client client = clientRepository.save(randomClient); + LoginRequest request = + LoginRequest.builder().withEmail(client.getEmail()).withPassword(password).build(); + SignUpAndInResponse response = + (SignUpAndInResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + UsersTestUtils.verifySignUpAndInResponse(response, client.getEmail(), UserType.CLIENT); + } + + @Test + void testGetProfileBrief() { + var freelancerObj = freelancerRepository.save(UsersTestUtils.generateRandomFreelancer()); FreelancerGetProfileBriefRequest request = FreelancerGetProfileBriefRequest.builder() - .withUser_id(freelancerObj.getId().toString()) + .withUserId(freelancerObj.getId().toString()) .build(); FreelancerGetProfileBriefResponse breifResponse = @@ -103,10 +156,163 @@ void testCreateUser() { template.convertSendAndReceive(ServiceQueueNames.USERS, request); assertEquals(breifResponse.getStatusCode(), (HttpStatusCode.OK)); - assertEquals(breifResponse.getFull_name(), (freelancerObj.getFull_name())); + assertEquals(breifResponse.getFullName(), (freelancerObj.getFullName())); assertEquals(breifResponse.getEmail(), (freelancerObj.getEmail())); } + @Test + void testFreelancerPhoto() { + String photoLink = "https://www.google.com"; + + var freelancerObj = freelancerRepository.save(UsersTestUtils.generateRandomFreelancer()); + + FreelancerGetPhotoRequest request = + FreelancerGetPhotoRequest.builder().withUserId(freelancerObj.getId().toString()).build(); + + FreelancerGetPhotoResponse photoResponse1 = + (FreelancerGetPhotoResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, request); + + assertEquals(photoResponse1.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(photoResponse1.getPhotoLink(), (freelancerObj.getPhoto_link())); + + freelancerObj.setPhoto_link(photoLink); + freelancerRepository.save(freelancerObj); + + FreelancerGetPhotoResponse photoResponse2 = + (FreelancerGetPhotoResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, request); + + assertEquals(photoResponse2.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(photoResponse2.getPhotoLink(), (photoLink)); + } + + @Test + void testFreelancerProfile() { + var freelancerObj = freelancerRepository.save(UsersTestUtils.generateRandomFreelancer()); + + FreelancerSetProfileRequest setRequest = + FreelancerSetProfileRequest.builder() + .withUserId(freelancerObj.getId().toString()) + .withFullName("John Doe") + .withJobTitle("Software Engineer") + .withCity("New York") + .withDescription("I am a software engineer") + .withBirthDate(Date.from(Instant.now())) + .withEmail("test@gmail.com") + .build(); + + FreelancerSetProfileResponse setResponse = + (FreelancerSetProfileResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, setRequest); + + FreelancerGetProfileRequest getRequest = + FreelancerGetProfileRequest.builder().withUserId(freelancerObj.getId().toString()).build(); + + FreelancerGetProfileResponse getResponse = + (FreelancerGetProfileResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, getRequest); + + assertEquals(setResponse.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(getResponse.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(getResponse.getFullName(), (setRequest.getFullName())); + assertEquals(getResponse.getJobTitle(), (setRequest.getJobTitle())); + assertEquals(getResponse.getCity(), (setRequest.getCity())); + assertEquals(getResponse.getDescription(), (setRequest.getDescription())); + assertEquals(getResponse.getBirthDate(), (setRequest.getBirthDate())); + assertEquals(getResponse.getEmail(), (setRequest.getEmail())); + } + + @Test + void testFreelancerResume() { + String resumeLink = "https://www.google.com"; + + var freelancerObj = freelancerRepository.save(UsersTestUtils.generateRandomFreelancer()); + + FreelancerSetResumeRequest setRequest = + FreelancerSetResumeRequest.builder() + .withUserId(freelancerObj.getId().toString()) + .withResumeLink(resumeLink) + .build(); + + FreelancerSetResumeResponse setResponse = + (FreelancerSetResumeResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, setRequest); + + assertEquals(setResponse.getStatusCode(), (HttpStatusCode.OK)); + + FreelancerGetResumeRequest getRequest = + FreelancerGetResumeRequest.builder().withUserId(freelancerObj.getId().toString()).build(); + + FreelancerGetResumeResponse getResponse = + (FreelancerGetResumeResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, getRequest); + + assertEquals(getResponse.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(getResponse.getResumeLink(), (resumeLink)); + } + + @Test + void testClientPhoto() { + String photoLink = "https://www.google.com"; + + var clientObj = paymentRequestRepository.save(UsersTestUtils.generateRandomClient()); + + ClientGetPhotoRequest request = + ClientGetPhotoRequest.builder().withUserId(clientObj.getId().toString()).build(); + + ClientGetPhotoResponse photoResponse1 = + (ClientGetPhotoResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + + assertEquals(photoResponse1.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(photoResponse1.getPhotoLink(), (clientObj.getPhoto_link())); + + clientObj.setPhoto_link(photoLink); + paymentRequestRepository.save(clientObj); + + ClientGetPhotoResponse photoResponse2 = + (ClientGetPhotoResponse) template.convertSendAndReceive(ServiceQueueNames.USERS, request); + + assertEquals(photoResponse2.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(photoResponse2.getPhotoLink(), (photoLink)); + } + + @Test + void testClientProfile() { + var clientObj = paymentRequestRepository.save(UsersTestUtils.generateRandomClient()); + + ClientSetProfileRequest setRequest = + ClientSetProfileRequest.builder() + .withUserId(clientObj.getId().toString()) + .withName("John Doe") + .withCity("New York") + .withIndustry("Software") + .withDescription("I am a software engineer") + .withEmployeeCount(10) + .withEmail("test@gmail.com") + .build(); + + ClientSetProfileResponse setResponse = + (ClientSetProfileResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, setRequest); + + ClientGetProfileRequest getRequest = + ClientGetProfileRequest.builder().withUserId(clientObj.getId().toString()).build(); + + ClientGetProfileResponse getResponse = + (ClientGetProfileResponse) + template.convertSendAndReceive(ServiceQueueNames.USERS, getRequest); + + assertEquals(setResponse.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(getResponse.getStatusCode(), (HttpStatusCode.OK)); + assertEquals(getResponse.getName(), (setRequest.getName())); + assertEquals(getResponse.getCity(), (setRequest.getCity())); + assertEquals(getResponse.getIndustry(), (setRequest.getIndustry())); + assertEquals(getResponse.getDescription(), (setRequest.getDescription())); + assertEquals(getResponse.getEmployeeCount(), (setRequest.getEmployeeCount())); + assertEquals(getResponse.getEmail(), (setRequest.getEmail())); + } + @Test void testAddAchievement() { Freelancer freelancerObj = freelancerRepository.save(UsersTestUtils.createTestFreelancer()); diff --git a/services/users/src/test/java/com/workup/users/UsersTestUtils.java b/services/users/src/test/java/com/workup/users/UsersTestUtils.java index 2493c8b0..07f4aa16 100644 --- a/services/users/src/test/java/com/workup/users/UsersTestUtils.java +++ b/services/users/src/test/java/com/workup/users/UsersTestUtils.java @@ -1,9 +1,15 @@ package com.workup.users; +import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.workup.shared.commands.users.responses.SignUpAndInResponse; +import com.workup.shared.enums.users.UserType; import com.workup.shared.views.users.AchievementView; import com.workup.shared.views.users.EducationView; import com.workup.shared.views.users.ExperienceView; import com.workup.users.db.Achievement; +import com.workup.users.db.Client; import com.workup.users.db.Education; import com.workup.users.db.Experience; import com.workup.users.db.Freelancer; @@ -17,7 +23,7 @@ public static Freelancer createTestFreelancer() { return Freelancer.builder() .withEmail("ahmad45123@gmail.com") .withPassword_hash("verysecurepassword") - .withFull_name("Mr. Mamdouh") + .withFullName("Mr. Mamdouh") .withJob_title("Software Engineer") .withCity("Cairo") .withBirthdate(Date.from(Instant.now())) @@ -119,4 +125,62 @@ public static void assertExperienceEquals(Experience expected, ExperienceView ac expected.getExperience_description(), actual.getExperience_description()); Assertions.assertEquals(expected.getCity(), actual.getCity()); } + + static String generateRandomString() { + return java.util.UUID.randomUUID().toString(); + } + + // generate a freelancer with random details + public static Freelancer generateRandomFreelancer() { + return Freelancer.builder() + .withEmail(generateRandomString() + "@gmail.com") + .withFullName(generateRandomString()) + .withJob_title(generateRandomString()) + .withCity(generateRandomString()) + .withBirthdate(Date.from(Instant.now())) + .withPassword_hash(generateRandomString()) + .build(); + } + + public static Client generateRandomClient() { + return Client.builder() + .withEmail(generateRandomString() + "@gmail.com") + .withClient_name(generateRandomString()) + .withCity(generateRandomString()) + .withIndustry(generateRandomString()) + .withPhoto_link(generateRandomString()) + .withClient_description(generateRandomString()) + .withEmployee_count(10) + .withPassword_hash(generateRandomString()) + .build(); + } + + public static void assertEqualFreelancer(Freelancer freelancer, Freelancer freelancerObj) { + assertEquals(freelancer.getEmail(), freelancerObj.getEmail()); + assertEquals(freelancer.getFullName(), freelancerObj.getFullName()); + assertEquals(freelancer.getJob_title(), freelancerObj.getJob_title()); + assertEquals(freelancer.getCity(), freelancerObj.getCity()); + assertEquals(freelancer.getBirthdate(), freelancerObj.getBirthdate()); + assertEquals(freelancer.getResume_link(), freelancerObj.getResume_link()); + assertEquals(freelancer.getPassword_hash(), freelancerObj.getPassword_hash()); + } + + public static void assertEqualClient(Client client, Client clientObj) { + assertEquals(client.getEmail(), clientObj.getEmail()); + assertEquals(client.getClient_name(), clientObj.getClient_name()); + assertEquals(client.getCity(), clientObj.getCity()); + assertEquals(client.getIndustry(), clientObj.getIndustry()); + assertEquals(client.getPhoto_link(), clientObj.getPhoto_link()); + assertEquals(client.getClient_description(), clientObj.getClient_description()); + assertEquals(client.getEmployee_count(), clientObj.getEmployee_count()); + assertEquals(client.getPassword_hash(), clientObj.getPassword_hash()); + } + + public static void verifySignUpAndInResponse( + SignUpAndInResponse response, String email, UserType userType) { + assertNotNull(response); + assertNotNull(response.getUserName()); + assertEquals(email, response.getUserName()); + assertEquals(userType, response.getUserType()); + } } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/AuthenticationRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/AuthenticationRequest.java new file mode 100644 index 00000000..79d9bbd5 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/AuthenticationRequest.java @@ -0,0 +1,13 @@ +package com.workup.shared.commands.users.requests; + +import com.workup.shared.commands.CommandRequest; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class AuthenticationRequest extends CommandRequest { + private String authToken; +} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetPhotoRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetPhotoRequest.java new file mode 100644 index 00000000..5ce53257 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetPhotoRequest.java @@ -0,0 +1,11 @@ +package com.workup.shared.commands.users.requests; + +import com.workup.shared.commands.CommandRequest; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class ClientGetPhotoRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetProfileRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetProfileRequest.java index 13b1a81c..21f6a11d 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetProfileRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientGetProfileRequest.java @@ -8,6 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class ClientGetProfileRequest extends CommandRequest { - public String user_id; -} +public class ClientGetProfileRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientRegisterRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientRegisterRequest.java new file mode 100644 index 00000000..02d7e209 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientRegisterRequest.java @@ -0,0 +1,19 @@ +package com.workup.shared.commands.users.requests; + +import com.workup.shared.commands.CommandRequest; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class ClientRegisterRequest extends CommandRequest { + private String email; + private String password; + private String clientName; + private String industry; + private String city; + private String description; + private Integer employeeCount; +} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetPhotoRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetPhotoRequest.java new file mode 100644 index 00000000..4f1e1375 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetPhotoRequest.java @@ -0,0 +1,13 @@ +package com.workup.shared.commands.users.requests; + +import com.workup.shared.commands.CommandRequest; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class ClientSetPhotoRequest extends CommandRequest { + public String photoLink; +} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetProfileRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetProfileRequest.java index bf5f8455..34a4e6c7 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetProfileRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/ClientSetProfileRequest.java @@ -9,11 +9,10 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class ClientSetProfileRequest extends CommandRequest { - public String user_id; public String name; public String email; public String city; public String description; public String industry; - public Integer employee_count; + public Integer employeeCount; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetPhotoRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetPhotoRequest.java index 6f23b206..0e77e423 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetPhotoRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetPhotoRequest.java @@ -8,6 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class FreelancerGetPhotoRequest extends CommandRequest { - public String user_id; -} +public class FreelancerGetPhotoRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileBriefRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileBriefRequest.java index 772dc9e0..6561fcd8 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileBriefRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileBriefRequest.java @@ -8,6 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class FreelancerGetProfileBriefRequest extends CommandRequest { - public final String user_id; -} +public class FreelancerGetProfileBriefRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileRequest.java index 41d58e6c..b35526da 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetProfileRequest.java @@ -8,6 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class FreelancerGetProfileRequest extends CommandRequest { - public String user_id; -} +public class FreelancerGetProfileRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetResumeRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetResumeRequest.java index e1c97991..0b49571a 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetResumeRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerGetResumeRequest.java @@ -8,6 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class FreelancerGetResumeRequest extends CommandRequest { - public String user_id; -} +public class FreelancerGetResumeRequest extends CommandRequest {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerRegisterRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerRegisterRequest.java index 98b75ecc..73fbe1de 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerRegisterRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerRegisterRequest.java @@ -10,10 +10,10 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerRegisterRequest extends CommandRequest { - public String email; - public String passwordHash; - public String fullName; - public String jobTitle; - public String city; - public Date birthDate; + private String email; + private String password; + private String fullName; + private String jobTitle; + private String city; + private Date birthDate; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetPhotoRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetPhotoRequest.java index 21941f94..ae8e2a13 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetPhotoRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetPhotoRequest.java @@ -9,6 +9,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerSetPhotoRequest extends CommandRequest { - public String user_id; - public String photo_encoded; // Base64 encoded photo + public String photoLink; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetProfileRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetProfileRequest.java index 39439eca..7cbbe1c7 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetProfileRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetProfileRequest.java @@ -10,11 +10,10 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerSetProfileRequest extends CommandRequest { - public String user_id; public String email; - public String full_name; + public String fullName; public String city; - public String job_title; + public String jobTitle; public String description; - public Date birth_date; + public Date birthDate; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetResumeRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetResumeRequest.java index 3961117f..07a73475 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetResumeRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/FreelancerSetResumeRequest.java @@ -9,6 +9,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerSetResumeRequest extends CommandRequest { - public String user_id; - public String resume_encoded; // Base64 encoded photo + public String resumeLink; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/requests/LoginRequest.java b/shared/src/main/java/com/workup/shared/commands/users/requests/LoginRequest.java new file mode 100644 index 00000000..ed7fc438 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/requests/LoginRequest.java @@ -0,0 +1,14 @@ +package com.workup.shared.commands.users.requests; + +import com.workup.shared.commands.CommandRequest; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class LoginRequest extends CommandRequest { + private String email; + private String password; +} diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/AuthenticationResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/AuthenticationResponse.java new file mode 100644 index 00000000..570f9a6a --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/AuthenticationResponse.java @@ -0,0 +1,15 @@ +package com.workup.shared.commands.users.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.shared.enums.users.UserType; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class AuthenticationResponse extends CommandResponse { + private String email; + private UserType userType; +} diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerRegisterResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetPhotoResponse.java similarity index 69% rename from shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerRegisterResponse.java rename to shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetPhotoResponse.java index 0dfabc7d..70d73203 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerRegisterResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetPhotoResponse.java @@ -8,7 +8,6 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class FreelancerRegisterResponse extends CommandResponse { - public boolean success; - public String authToken; +public class ClientGetPhotoResponse extends CommandResponse { + public String photoLink; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetProfileResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetProfileResponse.java index ba315605..b8b778f2 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetProfileResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientGetProfileResponse.java @@ -14,5 +14,5 @@ public class ClientGetProfileResponse extends CommandResponse { public String city; public String description; public String industry; - public Integer employee_count; + public Integer employeeCount; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/ClientSetPhotoResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientSetPhotoResponse.java new file mode 100644 index 00000000..c895433f --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/ClientSetPhotoResponse.java @@ -0,0 +1,11 @@ +package com.workup.shared.commands.users.responses; + +import com.workup.shared.commands.CommandResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class ClientSetPhotoResponse extends CommandResponse {} diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetPhotoResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetPhotoResponse.java index d47a35ec..819fbc5a 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetPhotoResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetPhotoResponse.java @@ -9,5 +9,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerGetPhotoResponse extends CommandResponse { - public String photoEncoded; // Base64 encoded photo + public String photoLink; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileBriefResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileBriefResponse.java index c96b72c1..7c5c3bca 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileBriefResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileBriefResponse.java @@ -10,5 +10,5 @@ @Jacksonized public class FreelancerGetProfileBriefResponse extends CommandResponse { public String email; - public String full_name; + public String fullName; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileResponse.java index 35946714..41a6baac 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetProfileResponse.java @@ -12,11 +12,11 @@ @Jacksonized public class FreelancerGetProfileResponse extends CommandResponse { public String email; - public String full_name; + public String fullName; public String city; - public String job_title; + public String jobTitle; public String description; - public Date birth_date; + public Date birthDate; public List languages; public List skills; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetResumeResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetResumeResponse.java index 92b2e4c3..3b444e95 100644 --- a/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetResumeResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/FreelancerGetResumeResponse.java @@ -9,5 +9,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class FreelancerGetResumeResponse extends CommandResponse { - public String resumeEncoded; // Base64 encoded resume + public String resumeLink; } diff --git a/shared/src/main/java/com/workup/shared/commands/users/responses/SignUpAndInResponse.java b/shared/src/main/java/com/workup/shared/commands/users/responses/SignUpAndInResponse.java new file mode 100644 index 00000000..710de121 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/users/responses/SignUpAndInResponse.java @@ -0,0 +1,17 @@ +package com.workup.shared.commands.users.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.shared.enums.users.UserType; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class SignUpAndInResponse extends CommandResponse { + boolean success; + String userName; + String userId; + UserType userType; +} diff --git a/shared/src/main/java/com/workup/shared/enums/users/UserType.java b/shared/src/main/java/com/workup/shared/enums/users/UserType.java new file mode 100644 index 00000000..0654d83d --- /dev/null +++ b/shared/src/main/java/com/workup/shared/enums/users/UserType.java @@ -0,0 +1,6 @@ +package com.workup.shared.enums.users; + +public enum UserType { + FREELANCER, + CLIENT +}