Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Jul 28, 2024
1 parent cd0122f commit a84862a
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.models.JwtUser;
import java.util.List;
import javax.security.auth.Subject;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import javax.security.auth.Subject;
import java.util.List;

public class UserAuthenticationToken extends AbstractAuthenticationToken {

private final JwtUser user;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.RDS.skilltree.annotations;

import com.RDS.skilltree.enums.UserRoleEnum;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import com.RDS.skilltree.viewmodels.EndorsementViewModel;
import com.RDS.skilltree.viewmodels.SkillViewModel;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.exceptions.ForbiddenException;
import com.RDS.skilltree.models.JwtUser;
import java.lang.reflect.Method;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class AuthorizedRolesAspect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.RDS.skilltree.Authentication.CustomAccessDeniedHandler;
import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.utils.JWTAuthenticationFilter;
import java.util.Arrays;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
Expand All @@ -18,9 +20,6 @@
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;
import java.util.List;

@EnableWebSecurity
@Configuration
public class SecurityConfig {
Expand Down
12 changes: 6 additions & 6 deletions skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public class Skill extends TrackedProperties {
@Enumerated(value = EnumType.STRING)
private SkillTypeEnum type = SkillTypeEnum.ATOMIC;

// @ManyToOne
// @JoinColumn(name = "created_by", nullable = false)
// private RdsUserViewModel createdBy;
// @ManyToOne
// @JoinColumn(name = "created_by", nullable = false)
// private RdsUserViewModel createdBy;

@Column(name = "created_by", nullable = false)
private String createdBy;

// @ManyToOne
// @JoinColumn(name = "updated_by")
// private RdsUserViewModel updatedBy;
// @ManyToOne
// @JoinColumn(name = "updated_by")
// private RdsUserViewModel updatedBy;

@Column(name = "updated_by")
private String updateBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.RDS.skilltree.enums.UserSkillStatusEnum;
import com.RDS.skilltree.models.UserSkills;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserSkillRepository extends JpaRepository<UserSkills, Integer> {
List<UserSkills> findByStatus(UserSkillStatusEnum status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import com.RDS.skilltree.repositories.UserSkillRepository;
import com.RDS.skilltree.services.external.RdsService;
import com.RDS.skilltree.viewmodels.*;
import java.util.*;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@RequiredArgsConstructor
public class EndorsementServiceImplementation implements EndorsementService {
Expand All @@ -32,39 +31,43 @@ public class EndorsementServiceImplementation implements EndorsementService {

@Override
public List<EndorsementViewModel> getAllEndorsementsBySkillId(Integer skillId) {
// endorsements.forEach(endorsement -> {
// RdsGetUserDetailsResDto userDetails = rdsService.getUserDetails(endorsement.)
// });
// endorsements.forEach(endorsement -> {
// RdsGetUserDetailsResDto userDetails = rdsService.getUserDetails(endorsement.)
// });

List<Endorsement> endorsements = endorsementRepository.findBySkillId(skillId);

// store all users data that are a part of this request
Map<String, UserViewModel> userDetails = new HashMap<>();

return endorsements.stream().map(endorsement -> {
String endorseId = endorsement.getEndorseId();
String endorserId = endorsement.getEndorserId();

if (!userDetails.containsKey(endorseId)) {
RdsGetUserDetailsResDto endorseDetails = rdsService.getUserDetails(endorsement.getEndorseId());
userDetails.put(endorseId, UserViewModel.toViewModel(endorseDetails.getUser()));
}

if (!userDetails.containsKey(endorserId)) {
RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(endorserId);
userDetails.put(endorserId, UserViewModel.toViewModel(endorserDetails.getUser()));
}

UserViewModel endorseDetails = userDetails.get(endorseId);
UserViewModel endorserDetails = userDetails.get(endorserId);

return new EndorsementViewModel(
endorsement.getId(),
SkillViewModel.toViewModel(endorsement.getSkill()),
endorseDetails, endorserDetails,
endorsement.getMessage()
);
}).toList();
return endorsements.stream()
.map(
endorsement -> {
String endorseId = endorsement.getEndorseId();
String endorserId = endorsement.getEndorserId();

if (!userDetails.containsKey(endorseId)) {
RdsGetUserDetailsResDto endorseDetails =
rdsService.getUserDetails(endorsement.getEndorseId());
userDetails.put(endorseId, UserViewModel.toViewModel(endorseDetails.getUser()));
}

if (!userDetails.containsKey(endorserId)) {
RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(endorserId);
userDetails.put(endorserId, UserViewModel.toViewModel(endorserDetails.getUser()));
}

UserViewModel endorseDetails = userDetails.get(endorseId);
UserViewModel endorserDetails = userDetails.get(endorserId);

return new EndorsementViewModel(
endorsement.getId(),
SkillViewModel.toViewModel(endorsement.getSkill()),
endorseDetails,
endorserDetails,
endorsement.getMessage());
})
.toList();
}

@Override
Expand All @@ -79,9 +82,9 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod

String endorserId = jwtDetails.getRdsUserId();


if (Objects.equals(endorseId, endorserId)) {
log.error("Self endorsement nto allowed, endorseId: {}, endorserId: {}", endorseId, endorserId);
log.error(
"Self endorsement nto allowed, endorseId: {}, endorserId: {}", endorseId, endorserId);
throw new SelfEndorsementNotAllowedException("Self endorsement not allowed");
}

Expand All @@ -99,20 +102,19 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod
List<UserSkills> userSkillEntry =
userSkillRepository.findByUserIdAndSkillId(endorseId, skillId);

Endorsement endorsement = Endorsement.builder()
.skill(skillDetails.get())
.message(message)
.endorseId(endorseId)
.endorserId(endorserId)
.build();
Endorsement endorsement =
Endorsement.builder()
.skill(skillDetails.get())
.message(message)
.endorseId(endorseId)
.endorserId(endorserId)
.build();

// If a skill request is not created then create one
// This is because there is no specific api to create a skill request at the time of writing
if (userSkillEntry.isEmpty()) {
UserSkills userSkills = UserSkills.builder()
.userId(endorseId)
.skill(skillDetails.get())
.build();
UserSkills userSkills =
UserSkills.builder().userId(endorseId).skill(skillDetails.get()).build();

userSkillRepository.save(userSkills);
}
Expand All @@ -122,8 +124,7 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod
return EndorsementViewModel.toViewModel(
newEndorsement,
UserViewModel.toViewModel(endorseDetails.getUser()),
UserViewModel.toViewModel(endorserDetails.getUser())
);
UserViewModel.toViewModel(endorserDetails.getUser()));
}

@Override
Expand All @@ -143,13 +144,14 @@ public EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewM
}

Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement);
RdsGetUserDetailsResDto endorseDetails = rdsService.getUserDetails(savedEndorsementDetails.getEndorseId());
RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(savedEndorsementDetails.getEndorserId());
RdsGetUserDetailsResDto endorseDetails =
rdsService.getUserDetails(savedEndorsementDetails.getEndorseId());
RdsGetUserDetailsResDto endorserDetails =
rdsService.getUserDetails(savedEndorsementDetails.getEndorserId());

return EndorsementViewModel.toViewModel(
savedEndorsementDetails,
UserViewModel.toViewModel(endorseDetails.getUser()),
UserViewModel.toViewModel(endorserDetails.getUser())
);
UserViewModel.toViewModel(endorserDetails.getUser()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import com.RDS.skilltree.viewmodels.SkillRequestViewModel;
import com.RDS.skilltree.viewmodels.SkillViewModel;
import com.RDS.skilltree.viewmodels.UserViewModel;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
Expand All @@ -43,8 +42,7 @@ public List<SkillViewModel> getAll() {

@Override
public SkillRequestsDto getAllRequests() {
List<UserSkills> pendingSkills =
userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING);
List<UserSkills> pendingSkills = userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING);

// store all users data that are a part of this request
Map<String, UserViewModel> userDetails = new HashMap<>();
Expand Down Expand Up @@ -72,8 +70,10 @@ public SkillRequestsDto getAllRequests() {

endorsements.forEach(
endorsement -> {
// String endorserId = endorsement.getEndorser().getId();
// String endorserRdsUserId = endorsement.getEndorser().getId();
// String endorserId =
// endorsement.getEndorser().getId();
// String endorserRdsUserId =
// endorsement.getEndorser().getId();

String endorserId = endorsement.getEndorserId();

Expand All @@ -93,12 +93,13 @@ public SkillRequestsDto getAllRequests() {
return SkillRequestsDto.toDto(skillRequests, userDetails.values().stream().toList());
}

private static UserViewModel getUserModalFromRdsDetails(String id, RdsGetUserDetailsResDto rdsDetails) {
private static UserViewModel getUserModalFromRdsDetails(
String id, RdsGetUserDetailsResDto rdsDetails) {
String firstName =
rdsDetails.getUser().getFirst_name() != null ? rdsDetails.getUser().getFirst_name() : "";
String lastName =
rdsDetails.getUser().getLast_name() != null ? rdsDetails.getUser().getLast_name() : "";

return UserViewModel.builder().id(id).name(firstName + ' ' + lastName).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class EndorsementViewModel {
private UserViewModel endorser;
private String message;

public static EndorsementViewModel toViewModel(Endorsement endorsement, UserViewModel endorse, UserViewModel endorser) {
// EndorsementViewModel viewModel = new EndorsementViewModel();
// BeanUtils.copyProperties(endorsement, viewModel);
public static EndorsementViewModel toViewModel(
Endorsement endorsement, UserViewModel endorse, UserViewModel endorser) {
// EndorsementViewModel viewModel = new EndorsementViewModel();
// BeanUtils.copyProperties(endorsement, viewModel);

// viewModel.setSkill(SkillViewModel.toViewModel(endorsement.getSkill()));
// viewModel.setEndorse(endorse);
// viewModel.setEndorser(endorser);
// viewModel.setSkill(SkillViewModel.toViewModel(endorsement.getSkill()));
// viewModel.setEndorse(endorse);
// viewModel.setEndorser(endorser);

return new EndorsementViewModel(
endorsement.getId(),
SkillViewModel.toViewModel(endorsement.getSkill()),
endorse,
endorser,
endorsement.getMessage()
);
endorsement.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class MinimalEndorsementViewModel {
private String message;

public static MinimalEndorsementViewModel toViewModel(Endorsement endorsement) {
// MinimalEndorsementViewModel endorsementViewModel = new MinimalEndorsementViewModel();
// MinimalEndorsementViewModel endorsementViewModel = new MinimalEndorsementViewModel();

// endorsementViewModel.setId(endorsement.getId());
// endorsementViewModel.setMessage(endorsement.getMessage());
// endorsementViewModel.setEndorsementDate(endorsement.getCreatedAt().toString());
// endorsementViewModel.setEndorserId(endorsement.getEndorserId());
// endorsementViewModel.setId(endorsement.getId());
// endorsementViewModel.setMessage(endorsement.getMessage());
// endorsementViewModel.setEndorsementDate(endorsement.getCreatedAt().toString());
// endorsementViewModel.setEndorserId(endorsement.getEndorserId());

return MinimalEndorsementViewModel.builder()
.id(endorsement.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class RdsUserViewModel {
private long updated_at;
private long created_at;


@Getter
@Setter
public static class Roles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.RDS.skilltree.models.Endorsement;
import com.RDS.skilltree.models.Skill;
import com.RDS.skilltree.models.UserSkills;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;
import lombok.Data;

@Data
public class SkillRequestViewModel {
Expand Down

0 comments on commit a84862a

Please sign in to comment.