Skip to content

Commit

Permalink
Merge pull request #141 from Real-Dev-Squad/yash/endorsement-api
Browse files Browse the repository at this point in the history
remove user table to user rdsUserId instead
  • Loading branch information
prakashchoudhary07 authored Aug 5, 2024
2 parents 2a569f3 + aee4b16 commit 56e4ac3
Show file tree
Hide file tree
Showing 37 changed files with 317 additions and 523 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.RDS.skilltree.Authentication;

import com.RDS.skilltree.User.JwtUserModel;
import com.RDS.skilltree.User.UserRoleEnum;
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;

public class UserAuthenticationToken extends AbstractAuthenticationToken {

private final JwtUserModel user;
private final JwtUser user;

public UserAuthenticationToken(String role, String rdsUserId) {
super(List.of(new SimpleGrantedAuthority(UserRoleEnum.fromString(role).name())));

this.user = new JwtUserModel(rdsUserId, UserRoleEnum.fromString(role));
this.user = new JwtUser(rdsUserId, UserRoleEnum.fromString(role));
setAuthenticated(true);
}

Expand All @@ -24,7 +24,7 @@ public Object getCredentials() {
}

@Override
public JwtUserModel getPrincipal() {
public JwtUser getPrincipal() {
return user;
}

Expand Down
49 changes: 0 additions & 49 deletions skill-tree/src/main/java/com/RDS/skilltree/User/UserDRO.java

This file was deleted.

43 changes: 0 additions & 43 deletions skill-tree/src/main/java/com/RDS/skilltree/User/UserDTO.java

This file was deleted.

23 changes: 0 additions & 23 deletions skill-tree/src/main/java/com/RDS/skilltree/User/UserModel.java

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions skill-tree/src/main/java/com/RDS/skilltree/User/UserService.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.RDS.skilltree.annotations;

import com.RDS.skilltree.User.UserRoleEnum;
import com.RDS.skilltree.enums.UserRoleEnum;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
31 changes: 0 additions & 31 deletions skill-tree/src/main/java/com/RDS/skilltree/apis/AuthApi.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.RDS.skilltree.apis;

import com.RDS.skilltree.User.UserRoleEnum;
import com.RDS.skilltree.annotations.AuthorizedRoles;
import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.services.EndorsementService;
import com.RDS.skilltree.viewmodels.CreateEndorsementViewModel;
import com.RDS.skilltree.viewmodels.EndorsementViewModel;
import com.RDS.skilltree.viewmodels.UpdateEndorsementViewModel;
import jakarta.validation.Valid;
Expand All @@ -21,12 +20,6 @@
public class EndorsementsApi {
private final EndorsementService endorsementService;

@PostMapping
public ResponseEntity<EndorsementViewModel> create(
@Valid @RequestBody CreateEndorsementViewModel endorsement) {
return new ResponseEntity<>(endorsementService.create(endorsement), HttpStatus.CREATED);
}

@PatchMapping("/{id}")
public ResponseEntity<EndorsementViewModel> update(
@PathVariable Integer id, @Valid @RequestBody UpdateEndorsementViewModel body) {
Expand Down
28 changes: 27 additions & 1 deletion skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.RDS.skilltree.apis;

import com.RDS.skilltree.User.UserRoleEnum;
import com.RDS.skilltree.annotations.AuthorizedRoles;
import com.RDS.skilltree.dtos.CreateEndorsementRequestDto;
import com.RDS.skilltree.dtos.SkillRequestActionRequestDto;
import com.RDS.skilltree.dtos.SkillRequestsDto;
import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.services.EndorsementService;
import com.RDS.skilltree.services.SkillService;
import com.RDS.skilltree.utils.GenericResponse;
import com.RDS.skilltree.viewmodels.CreateEndorsementViewModel;
import com.RDS.skilltree.viewmodels.CreateSkillViewModel;
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.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -35,6 +40,16 @@ public ResponseEntity<SkillRequestsDto> getAllRequests() {
return ResponseEntity.ok(skillService.getAllRequests());
}

@PostMapping("/requests/{skillId}/action")
@AuthorizedRoles({UserRoleEnum.SUPERUSER})
public ResponseEntity<GenericResponse<String>> approveRejectSkillRequest(
@PathVariable(value = "skillId") Integer skillId,
@Valid @RequestBody SkillRequestActionRequestDto skillRequestAction) {
return ResponseEntity.ok(
skillService.approveRejectSkillRequest(
skillId, skillRequestAction.getEndorseId(), skillRequestAction.getAction()));
}

@PostMapping
@AuthorizedRoles({UserRoleEnum.SUPERUSER})
public ResponseEntity<SkillViewModel> create(@Valid @RequestBody CreateSkillViewModel skill) {
Expand All @@ -46,4 +61,15 @@ public ResponseEntity<List<EndorsementViewModel>> getEndorsementsBySkillId(
@PathVariable(value = "id") Integer skillID) {
return ResponseEntity.ok(endorsementService.getAllEndorsementsBySkillId(skillID));
}

@PostMapping("/{id}/endorsements")
public ResponseEntity<EndorsementViewModel> create(
@PathVariable(value = "id") Integer skillID,
@Valid @RequestBody CreateEndorsementRequestDto endorsementRequest) {
return new ResponseEntity<>(
endorsementService.create(
CreateEndorsementViewModel.toViewModel(
skillID, endorsementRequest.getEndorseId(), endorsementRequest.getMessage())),
HttpStatus.CREATED);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.RDS.skilltree.aspects;

import com.RDS.skilltree.User.JwtUserModel;
import com.RDS.skilltree.User.UserRoleEnum;
import com.RDS.skilltree.annotations.AuthorizedRoles;
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;
Expand All @@ -19,8 +19,8 @@ public class AuthorizedRolesAspect {
@Around("@within(authorizedRoles) || @annotation(authorizedRoles)")
public Object authorize(ProceedingJoinPoint joinPoint, AuthorizedRoles authorizedRoles)
throws Throwable {
JwtUserModel jwtDetails =
(JwtUserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
JwtUser jwtDetails =
(JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserRoleEnum role = jwtDetails.getRole();

MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.RDS.skilltree.Authentication.AuthEntryPoint;
import com.RDS.skilltree.Authentication.CustomAccessDeniedHandler;
import com.RDS.skilltree.User.UserRoleEnum;
import com.RDS.skilltree.enums.UserRoleEnum;
import com.RDS.skilltree.utils.JWTAuthenticationFilter;
import java.util.Arrays;
import java.util.List;
Expand Down
Loading

0 comments on commit 56e4ac3

Please sign in to comment.