Skip to content

Commit

Permalink
removed logging for user profile but kep logging for all other endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandemic1617 committed May 16, 2024
1 parent 6b9c3a3 commit 16cd872
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Client;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ClientGetPhotoCommand
extends UserCommand<ClientGetPhotoRequest, ClientGetPhotoResponse> {
private static final Logger logger = LogManager.getLogger(ClientGetPhotoCommand.class);

@Override
public ClientGetPhotoResponse Run(ClientGetPhotoRequest request) {
logger.info("[i] Getting Photo for Client with id: " + request.getUserId());
Optional<Client> clientOptional = clientRepository.findById(request.getUserId());

if (!clientOptional.isPresent()) {
logger.error("[x] Client Doesn't Exist");
return ClientGetPhotoResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Client;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ClientGetProfileCommand
extends UserCommand<ClientGetProfileRequest, ClientGetProfileResponse> {
private static final Logger logger = LogManager.getLogger(ClientGetProfileCommand.class);

@Override
public ClientGetProfileResponse Run(ClientGetProfileRequest request) {
logger.info("[i] Getting Profile for Client with id: " + request.getUserId());
Optional<Client> clientOptional = clientRepository.findById(request.getUserId());

if (!clientOptional.isPresent()) {
logger.error("[x] Client Doesn't Exist");
return ClientGetProfileResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import com.workup.shared.enums.users.UserType;
import com.workup.users.db.Client;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ClientRegisterCommand extends UserCommand<ClientRegisterRequest, SignUpAndInResponse> {
private static final Logger logger = LogManager.getLogger(ClientRegisterCommand.class);

@Override
public SignUpAndInResponse Run(ClientRegisterRequest request) {
logger.info("[i] Registering Client with Email: " + request.getEmail());
if (Objects.isNull(request.getEmail())
|| Objects.isNull(request.getPassword())
|| Objects.isNull(request.getClientName())) {
logger.error("[x] Missing Required Fields");
return SignUpAndInResponse.builder()
.withStatusCode(HttpStatusCode.BAD_REQUEST)
.withSuccess(false)
Expand All @@ -42,6 +47,7 @@ public SignUpAndInResponse Run(ClientRegisterRequest request) {
.withStatusCode(HttpStatusCode.OK)
.build();
} catch (Exception e) {
logger.error("[x] Error Registering Client: " + e.getMessage());
return SignUpAndInResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.withSuccess(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Client;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ClientSetPhotoCommand
extends UserCommand<ClientSetPhotoRequest, ClientSetPhotoResponse> {
private static final Logger logger = LogManager.getLogger(ClientSetPhotoCommand.class);

@Override
public ClientSetPhotoResponse Run(ClientSetPhotoRequest request) {

logger.info("[i] Setting Photo for Client with id: " + request.getUserId());
Optional<Client> clientOption = clientRepository.findById(request.getUserId());

if (!clientOption.isPresent()) {
logger.error("[x] Client Doesn't Exist");
throw new RuntimeException("User not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Client;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ClientSetProfileCommand
extends UserCommand<ClientSetProfileRequest, ClientSetProfileResponse> {
private static final Logger logger = LogManager.getLogger(ClientSetProfileCommand.class);

@Override
public ClientSetProfileResponse Run(ClientSetProfileRequest request) {

logger.info("[i] Setting Profile for Client with id: " + request.getUserId());
Client client;

if (request.getUserId() == null) {
client = Client.builder().build();
} else {
Optional<Client> clientOption = clientRepository.findById(request.getUserId());
if (!clientOption.isPresent()) {
logger.error("[x] Client Doesn't Exist");
throw new RuntimeException("User not found");
}
client = clientOption.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerGetPhotoCommand
extends UserCommand<FreelancerGetPhotoRequest, FreelancerGetPhotoResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerGetPhotoCommand.class);

@Override
public FreelancerGetPhotoResponse Run(FreelancerGetPhotoRequest request) {
logger.info("[i] Getting Photo for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());

if (!freelancerOptional.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
return FreelancerGetPhotoResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerGetProfileBriefCommand
extends UserCommand<FreelancerGetProfileBriefRequest, FreelancerGetProfileBriefResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerGetProfileBriefCommand.class);

@Override
public FreelancerGetProfileBriefResponse Run(FreelancerGetProfileBriefRequest request) {
logger.info("[i] Getting Profile Brief for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancer = freelancerRepository.findById(request.getUserId());

if (!freelancer.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
return FreelancerGetProfileBriefResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerGetProfileCommand
extends UserCommand<FreelancerGetProfileRequest, FreelancerGetProfileResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerGetProfileCommand.class);

@Override
public FreelancerGetProfileResponse Run(FreelancerGetProfileRequest request) {
logger.info("[i] Getting Profile for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancer = freelancerRepository.findById(request.getUserId());

if (!freelancer.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
return FreelancerGetProfileResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerGetResumeCommand
extends UserCommand<FreelancerGetResumeRequest, FreelancerGetResumeResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerGetResumeCommand.class);

@Override
public FreelancerGetResumeResponse Run(FreelancerGetResumeRequest request) {
logger.info("[i] Getting Resume for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());

if (!freelancerOptional.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
return FreelancerGetResumeResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
import com.workup.shared.enums.users.UserType;
import com.workup.users.db.Freelancer;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerRegisterCommand
extends UserCommand<FreelancerRegisterRequest, SignUpAndInResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerRegisterCommand.class);

@Override
public SignUpAndInResponse Run(FreelancerRegisterRequest request) {
logger.info("[i] Registering Freelancer with Email: " + request.getEmail());
if (Objects.isNull(request.getEmail())
|| Objects.isNull(request.getPassword())
|| Objects.isNull(request.getFullName())) {
logger.error("[x] Missing Required Fields");
return SignUpAndInResponse.builder()
.withStatusCode(HttpStatusCode.BAD_REQUEST)
.withSuccess(false)
Expand Down Expand Up @@ -50,6 +55,7 @@ public SignUpAndInResponse Run(FreelancerRegisterRequest request) {
.withStatusCode(HttpStatusCode.OK)
.build();
} catch (Exception e) {
logger.error("[x] Error Registering Freelancer: " + e.getMessage());
return SignUpAndInResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.withSuccess(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerSetPhotoCommand
extends UserCommand<FreelancerSetPhotoRequest, FreelancerSetPhotoResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerSetPhotoCommand.class);

@Override
public FreelancerSetPhotoResponse Run(FreelancerSetPhotoRequest request) {

logger.info("[i] Setting Photo for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancerOption = freelancerRepository.findById(request.getUserId());

if (!freelancerOption.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
throw new RuntimeException("User not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerSetProfileCommand
extends UserCommand<FreelancerSetProfileRequest, FreelancerSetProfileResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerSetProfileCommand.class);

@Override
public FreelancerSetProfileResponse Run(FreelancerSetProfileRequest request) {

logger.info("[i] Setting Profile for Freelancer with id: " + request.getUserId());
Freelancer freelancer;
if (request.getUserId() == null) {
freelancer = Freelancer.builder().withId(null).build();
} else {

Optional<Freelancer> freelancerOption = freelancerRepository.findById(request.getUserId());
if (!freelancerOption.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
throw new RuntimeException("User not found");
}
freelancer = freelancerOption.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FreelancerSetResumeCommand
extends UserCommand<FreelancerSetResumeRequest, FreelancerSetResumeResponse> {
private static final Logger logger = LogManager.getLogger(FreelancerSetResumeCommand.class);

@Override
public FreelancerSetResumeResponse Run(FreelancerSetResumeRequest request) {

logger.info("[i] Setting Resume for Freelancer with id: " + request.getUserId());
Optional<Freelancer> freelancerOption = freelancerRepository.findById(request.getUserId());

if (!freelancerOption.isPresent()) {
logger.error("[x] Freelancer Doesn't Exist");
throw new RuntimeException("User not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
import com.workup.users.db.Client;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LoginCommand extends UserCommand<LoginRequest, SignUpAndInResponse> {
private static final Logger logger = LogManager.getLogger(LoginCommand.class);

@Override
public SignUpAndInResponse Run(LoginRequest request) {
logger.info("[i] Logging in user with email: " + request.getEmail());
String email = request.getEmail();
String password = request.getPassword();
try {
Expand Down Expand Up @@ -42,12 +46,14 @@ public SignUpAndInResponse Run(LoginRequest request) {
}
}

logger.error("[x] User not found or password incorrect");
// return unauthorized
return SignUpAndInResponse.builder()
.withSuccess(false)
.withStatusCode(HttpStatusCode.UNAUTHORIZED)
.build();
} catch (Exception e) {
logger.error("[x] Error Logging in user: " + e.getMessage());
return SignUpAndInResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
.withSuccess(false)
Expand Down

0 comments on commit 16cd872

Please sign in to comment.