Skip to content

Commit

Permalink
Merge branch 'main' into contracts-commands-cache-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemosalamy committed May 12, 2024
2 parents 9968436 + 49af6a0 commit c697353
Show file tree
Hide file tree
Showing 60 changed files with 920 additions and 147 deletions.
4 changes: 3 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ up:

reload:
mvn -DskipTests package
docker compose up --detach --build
docker compose up --detach --build

format:
mvn git-code-format:format-code -Dgcf.globPattern=**/*
26 changes: 26 additions & 0 deletions services/users/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@
<version>1.19.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.4</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ClientGetPhotoRequest, ClientGetPhotoResponse> {

@Override
public ClientGetPhotoResponse Run(ClientGetPhotoRequest request) {
Optional<Client> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ClientGetProfileCommand

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

if (!clientOptional.isPresent()) {
return ClientGetProfileResponse.builder()
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<ClientRegisterRequest, SignUpAndInResponse> {

@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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ClientSetPhotoRequest, ClientSetPhotoResponse> {

@Override
public ClientSetPhotoResponse Run(ClientSetPhotoRequest request) {

Optional<Client> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client> clientOption = clientRepository.findById(request.getUser_id());
Optional<Client> clientOption = clientRepository.findById(request.getUserId());
if (!clientOption.isPresent()) {
throw new RuntimeException("User not found");
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,27 @@
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
extends UserCommand<FreelancerGetPhotoRequest, FreelancerGetPhotoResponse> {

@Override
public FreelancerGetPhotoResponse Run(FreelancerGetPhotoRequest request) {
Optional<Client> clientOptional = clientRepository.findById(request.getUser_id());
Optional<Freelancer> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FreelancerGetProfileBriefCommand

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

if (!freelancer.isPresent()) {
return FreelancerGetProfileBriefResponse.builder()
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FreelancerGetProfileCommand

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

if (!freelancer.isPresent()) {
return FreelancerGetProfileResponse.builder()
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,27 @@
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
extends UserCommand<FreelancerGetResumeRequest, FreelancerGetResumeResponse> {

@Override
public FreelancerGetResumeResponse Run(FreelancerGetResumeRequest request) {
Optional<Client> clientOptional = clientRepository.findById(request.user_id);
Optional<Freelancer> 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();
}
}
Loading

0 comments on commit c697353

Please sign in to comment.