Skip to content

Commit

Permalink
Merge branch 'mahmoud/users-logging' into users-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimaaBetah committed May 17, 2024
2 parents 788b518 + 36cb855 commit fe5c2a5
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import com.workup.users.db.Achievement;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AddFreelancerAchievementCommand
extends UserCommand<AddFreelancerAchievementRequest, AddFreelancerAchievementResponse> {
private static final Logger logger = LogManager.getLogger(AddFreelancerAchievementCommand.class);

@Override
public AddFreelancerAchievementResponse Run(AddFreelancerAchievementRequest request) {
logger.info("Add Freelancer Achievement - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return AddFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
Achievement newAchievement =
Achievement.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import com.workup.users.db.Education;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AddFreelancerEducationCommand
extends UserCommand<AddFreelancerEducationRequest, AddFreelancerEducationResponse> {
private static final Logger logger = LogManager.getLogger(AddFreelancerEducationCommand.class);

@Override
public AddFreelancerEducationResponse Run(AddFreelancerEducationRequest request) {
logger.info("Add Freelancer Education - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return AddFreelancerEducationResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
Education newEducation =
Education.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import com.workup.users.db.Experience;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AddFreelancerExperienceCommand
extends UserCommand<AddFreelancerExperienceRequest, AddFreelancerExperienceResponse> {
private static final Logger logger = LogManager.getLogger(AddFreelancerExperienceCommand.class);

@Override
public AddFreelancerExperienceResponse Run(AddFreelancerExperienceRequest request) {
logger.info("Add Freelancer Experience - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return AddFreelancerExperienceResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
Experience newExperience =
Experience.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import com.workup.users.db.Freelancer;
import java.util.ArrayList;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AddFreelancerLanguageCommand
extends UserCommand<AddFreelancerLanguageRequest, AddFreelancerLanguageResponse> {
private static final Logger logger = LogManager.getLogger(AddFreelancerLanguageCommand.class);

@Override
public AddFreelancerLanguageResponse Run(AddFreelancerLanguageRequest request) {
logger.info("Add Freelancer Language - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return AddFreelancerLanguageResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
if (freelancer.getLanguages() == null) freelancer.setLanguages(new ArrayList<>());
freelancer.getLanguages().add(request.getNewLanguage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AddFreelancerSkillCommand
extends UserCommand<AddFreelancerSkillRequest, AddFreelancerSkillResponse> {
private static final Logger logger = LogManager.getLogger(AddFreelancerSkillCommand.class);

@Override
public AddFreelancerSkillResponse Run(AddFreelancerSkillRequest request) {
logger.info("Add Freelancer Skill - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return AddFreelancerSkillResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
String newSkill = request.getNewSkill();
Freelancer freelancer = freelancerOptional.get();
if (freelancer.getSkills() == null) freelancer.setSkills(new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerAchievementsCommand
extends UserCommand<GetFreelancerAchievementsRequest, GetFreelancerAchievementsResponse> {
private static final Logger logger = LogManager.getLogger(GetFreelancerAchievementsCommand.class);

@Override
public GetFreelancerAchievementsResponse Run(GetFreelancerAchievementsRequest request) {
logger.info("Get Freelancer Achievements - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return GetFreelancerAchievementsResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
List<AchievementView> achievements = convertToAchievementViewList(freelancer.getAchievements());
return GetFreelancerAchievementsResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerEducationsCommand
extends UserCommand<GetFreelancerEducationsRequest, GetFreelancerEducationsResponse> {
private static final Logger logger = LogManager.getLogger(GetFreelancerEducationsCommand.class);

@Override
public GetFreelancerEducationsResponse Run(GetFreelancerEducationsRequest request) {
logger.info("Get Freelancer Educations - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return GetFreelancerEducationsResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
List<EducationView> educations = convertToEducationViewList(freelancer.getEducations());
return GetFreelancerEducationsResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerExperiencesCommand
extends UserCommand<GetFreelancerExperiencesRequest, GetFreelancerExperiencesResponse> {
private static final Logger logger = LogManager.getLogger(GetFreelancerExperiencesCommand.class);

@Override
public GetFreelancerExperiencesResponse Run(GetFreelancerExperiencesRequest request) {
logger.info("Get Freelancer Experiences - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return GetFreelancerExperiencesResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
List<ExperienceView> experiences = convertToExperienceViewList(freelancer.getExperiences());
return GetFreelancerExperiencesResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import com.workup.users.db.Freelancer;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerLanguagesCommand
extends UserCommand<GetFreelancerLanguagesRequest, GetFreelancerLanguagesResponse> {
private static final Logger logger = LogManager.getLogger(GetFreelancerLanguagesCommand.class);

@Override
public GetFreelancerLanguagesResponse Run(GetFreelancerLanguagesRequest request) {
logger.info("Get Freelancer Languages - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return GetFreelancerLanguagesResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
List<String> languages = freelancer.getLanguages();
return GetFreelancerLanguagesResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import com.workup.users.db.Freelancer;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerSkillsCommand
extends UserCommand<GetFreelancerSkillsRequest, GetFreelancerSkillsResponse> {
private static final Logger logger = LogManager.getLogger(GetFreelancerSkillsCommand.class);

@Override
public GetFreelancerSkillsResponse Run(GetFreelancerSkillsRequest request) {
logger.info("Get Freelancer Skills - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return GetFreelancerSkillsResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
List<String> skills = freelancer.getSkills();
return GetFreelancerSkillsResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import com.workup.users.db.Achievement;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class RemoveFreelancerAchievementCommand
extends UserCommand<RemoveFreelancerAchievementRequest, RemoveFreelancerAchievementResponse> {
private static final Logger logger =
LogManager.getLogger(RemoveFreelancerAchievementCommand.class);

@Override
public RemoveFreelancerAchievementResponse Run(RemoveFreelancerAchievementRequest request) {
logger.info("Remove Freelancer Achievement - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return RemoveFreelancerAchievementResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
freelancer
.getAchievements()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import com.workup.users.db.Education;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class RemoveFreelancerEducationCommand
extends UserCommand<RemoveFreelancerEducationRequest, RemoveFreelancerEducationResponse> {
private static final Logger logger = LogManager.getLogger(RemoveFreelancerEducationCommand.class);

@Override
public RemoveFreelancerEducationResponse Run(RemoveFreelancerEducationRequest request) {
logger.info("Remove Freelancer Education - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return RemoveFreelancerEducationResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
freelancer
.getEducations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import com.workup.users.db.Experience;
import com.workup.users.db.Freelancer;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class RemoveFreelancerExperienceCommand
extends UserCommand<RemoveFreelancerExperienceRequest, RemoveFreelancerExperienceResponse> {
private static final Logger logger =
LogManager.getLogger(RemoveFreelancerExperienceCommand.class);

@Override
public RemoveFreelancerExperienceResponse Run(RemoveFreelancerExperienceRequest request) {
logger.info("Remove Freelancer Experience - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return RemoveFreelancerExperienceResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
freelancer
.getExperiences()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
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 RemoveFreelancerLanguageCommand
extends UserCommand<RemoveFreelancerLanguageRequest, RemoveFreelancerLanguageResponse> {
private static final Logger logger = LogManager.getLogger(RemoveFreelancerLanguageCommand.class);

@Override
public RemoveFreelancerLanguageResponse Run(RemoveFreelancerLanguageRequest request) {
logger.info("Remove Freelancer Language - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return RemoveFreelancerLanguageResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
freelancer.getLanguages().remove(request.getLanguageToRemove());
freelancerRepository.save(freelancer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
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 RemoveFreelancerSkillCommand
extends UserCommand<RemoveFreelancerSkillRequest, RemoveFreelancerSkillResponse> {
private static final Logger logger = LogManager.getLogger(RemoveFreelancerSkillCommand.class);

@Override
public RemoveFreelancerSkillResponse Run(RemoveFreelancerSkillRequest request) {
logger.info("Remove Freelancer Skill - Freelancer ID: " + request.getUserId());
Optional<Freelancer> freelancerOptional = freelancerRepository.findById(request.getUserId());
if (freelancerOptional.isEmpty())
if (freelancerOptional.isEmpty()) {
logger.error("Freelancer Not Found - Freelancer ID: " + request.getUserId());
return RemoveFreelancerSkillResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Freelancer Doesn't Exist")
.build();
}
Freelancer freelancer = freelancerOptional.get();
freelancer.getSkills().remove(request.getSkillToRemove());
freelancerRepository.save(freelancer);
Expand Down
Loading

0 comments on commit fe5c2a5

Please sign in to comment.