-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into contracts-commands-cache-implementation
- Loading branch information
Showing
60 changed files
with
920 additions
and
147 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
services/users/src/main/java/com/workup/users/commands/ClientGetPhotoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
services/users/src/main/java/com/workup/users/commands/ClientRegisterCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
services/users/src/main/java/com/workup/users/commands/ClientSetPhotoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.