-
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 pull request #133 from gelecekbilimde/roleChange
#121 | Role Application Flows Have Been Created and Role/Permissions Have Been Refactored
- Loading branch information
Showing
46 changed files
with
1,222 additions
and
200 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
...in/java/org/gelecekbilimde/scienceplatform/auth/controller/RoleApplicationController.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,69 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.gelecekbilimde.scienceplatform.auth.model.RoleApplication; | ||
import org.gelecekbilimde.scienceplatform.auth.model.mapper.RoleApplicationToRoleApplicationResponseMapper; | ||
import org.gelecekbilimde.scienceplatform.auth.model.request.RoleApplicationListRequest; | ||
import org.gelecekbilimde.scienceplatform.auth.model.response.RoleApplicationsResponse; | ||
import org.gelecekbilimde.scienceplatform.auth.service.RoleApplicationService; | ||
import org.gelecekbilimde.scienceplatform.common.model.BasePage; | ||
import org.gelecekbilimde.scienceplatform.common.model.response.PagingResponse; | ||
import org.gelecekbilimde.scienceplatform.common.model.response.SuccessResponse; | ||
import org.hibernate.validator.constraints.UUID; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
class RoleApplicationController { | ||
|
||
private final RoleApplicationService roleApplicationService; | ||
|
||
|
||
private final RoleApplicationToRoleApplicationResponseMapper roleApplicationToRoleApplicationResponseMapper = RoleApplicationToRoleApplicationResponseMapper.initialize(); | ||
|
||
|
||
@PostMapping("/role-applications") | ||
@PreAuthorize("hasAnyAuthority('role:application:list')") | ||
SuccessResponse<PagingResponse<RoleApplicationsResponse>> findAll(@RequestBody @Valid RoleApplicationListRequest listRequest) { | ||
|
||
final BasePage<RoleApplication> pageOfRoleApplications = roleApplicationService.findAll(listRequest); | ||
|
||
final PagingResponse<RoleApplicationsResponse> pageResponseOfRoleApplication = PagingResponse | ||
.<RoleApplicationsResponse>builder() | ||
.of(pageOfRoleApplications) | ||
.content( | ||
roleApplicationToRoleApplicationResponseMapper.map(pageOfRoleApplications.getContent()) | ||
) | ||
.filteredBy(listRequest.getFilter()) | ||
.build(); | ||
|
||
return SuccessResponse.success(pageResponseOfRoleApplication); | ||
} | ||
|
||
@PatchMapping("/role-application/{id}/approve") | ||
@PreAuthorize("hasAnyAuthority('role:application:conclude')") | ||
SuccessResponse<Void> approve(@PathVariable @UUID String id) { | ||
|
||
roleApplicationService.approve(id); | ||
return SuccessResponse.success(); | ||
} | ||
|
||
@PatchMapping("/role-application/{id}/reject") | ||
@PreAuthorize("hasAnyAuthority('role:application:conclude')") | ||
SuccessResponse<Void> reject(@PathVariable @UUID String id) { | ||
|
||
roleApplicationService.reject(id); | ||
return SuccessResponse.success(); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...ava/org/gelecekbilimde/scienceplatform/auth/controller/RoleSelfApplicationController.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,77 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.gelecekbilimde.scienceplatform.auth.model.RoleApplication; | ||
import org.gelecekbilimde.scienceplatform.auth.model.mapper.RoleApplicationToRoleSelfApplicationsResponseMapper; | ||
import org.gelecekbilimde.scienceplatform.auth.model.request.RoleSelfApplicationListRequest; | ||
import org.gelecekbilimde.scienceplatform.auth.model.response.RoleSelfApplicationsResponse; | ||
import org.gelecekbilimde.scienceplatform.auth.service.RoleSelfApplicationService; | ||
import org.gelecekbilimde.scienceplatform.common.model.BasePage; | ||
import org.gelecekbilimde.scienceplatform.common.model.response.PagingResponse; | ||
import org.gelecekbilimde.scienceplatform.common.model.response.SuccessResponse; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
class RoleSelfApplicationController { | ||
|
||
private final RoleSelfApplicationService roleSelfApplicationService; | ||
|
||
|
||
private final RoleApplicationToRoleSelfApplicationsResponseMapper roleApplicationToRoleSelfApplicationsResponseMapper = RoleApplicationToRoleSelfApplicationsResponseMapper.initialize(); | ||
|
||
|
||
@PostMapping("/role-applications/self") | ||
@PreAuthorize("hasAnyAuthority('role:application:list:self')") | ||
SuccessResponse<PagingResponse<RoleSelfApplicationsResponse>> findAll(@RequestBody @Valid RoleSelfApplicationListRequest listRequest) { | ||
|
||
final BasePage<RoleApplication> pageOfRoleApplications = roleSelfApplicationService.findAll(listRequest); | ||
|
||
final PagingResponse<RoleSelfApplicationsResponse> pageResponseOfRoleApplication = PagingResponse | ||
.<RoleSelfApplicationsResponse>builder() | ||
.of(pageOfRoleApplications) | ||
.content( | ||
roleApplicationToRoleSelfApplicationsResponseMapper.map(pageOfRoleApplications.getContent()) | ||
) | ||
.filteredBy(listRequest.getFilter()) | ||
.build(); | ||
|
||
return SuccessResponse.success(pageResponseOfRoleApplication); | ||
} | ||
|
||
|
||
@PostMapping("/role-application/self/author") | ||
@PreAuthorize("hasAnyAuthority('role:application:create:self:author')") | ||
SuccessResponse<Void> createAuthorApplication() { | ||
|
||
roleSelfApplicationService.createAuthorApplication(); | ||
return SuccessResponse.success(); | ||
} | ||
|
||
|
||
@PostMapping("/role-application/self/moderator") | ||
@PreAuthorize("hasAnyAuthority('role:application:create:self:moderator')") | ||
SuccessResponse<Void> createModeratorApplication() { | ||
|
||
roleSelfApplicationService.createModeratorApplication(); | ||
return SuccessResponse.success(); | ||
} | ||
|
||
|
||
@PatchMapping("/role-application/self/cancel") | ||
@PreAuthorize("hasAnyAuthority('role:application:cancel:self')") | ||
SuccessResponse<Void> cancel() { | ||
roleSelfApplicationService.cancel(); | ||
return SuccessResponse.success(); | ||
} | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
...ava/org/gelecekbilimde/scienceplatform/auth/exception/DefaultRoleNotDefinedException.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...lecekbilimde/scienceplatform/auth/exception/RoleApplicationAlreadyConcludedException.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,16 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractConflictException; | ||
|
||
import java.io.Serial; | ||
|
||
public class RoleApplicationAlreadyConcludedException extends AbstractConflictException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = -7807528937254572325L; | ||
|
||
public RoleApplicationAlreadyConcludedException(String id) { | ||
super("role application already concluded id: " + id); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...g/gelecekbilimde/scienceplatform/auth/exception/RoleApplicationAlreadyExistException.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,16 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractConflictException; | ||
|
||
import java.io.Serial; | ||
|
||
public class RoleApplicationAlreadyExistException extends AbstractConflictException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 3834570698226426742L; | ||
|
||
public RoleApplicationAlreadyExistException() { | ||
super("user already has a role application in review"); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...g/gelecekbilimde/scienceplatform/auth/exception/RoleApplicationNotFoundByIdException.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,16 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractNotFoundException; | ||
|
||
import java.io.Serial; | ||
|
||
public class RoleApplicationNotFoundByIdException extends AbstractNotFoundException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = -7420720906649254998L; | ||
|
||
public RoleApplicationNotFoundByIdException(String id) { | ||
super("role application does not found! id: " + id); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...mde/scienceplatform/auth/exception/RoleApplicationNotFoundByUserIdAndStatusException.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,17 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.auth.model.enums.RoleApplicationStatus; | ||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractNotFoundException; | ||
|
||
import java.io.Serial; | ||
|
||
public class RoleApplicationNotFoundByUserIdAndStatusException extends AbstractNotFoundException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 4738260982768669235L; | ||
|
||
public RoleApplicationNotFoundByUserIdAndStatusException(String userId, RoleApplicationStatus status) { | ||
super("role application not found! userId: " + userId + ", status: " + status); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...n/java/org/gelecekbilimde/scienceplatform/auth/exception/RoleNotFoundByNameException.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,14 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import java.io.Serial; | ||
|
||
public class RoleNotFoundByNameException extends RuntimeException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = -927147689852209182L; | ||
|
||
public RoleNotFoundByNameException(String name) { | ||
super("role not found with name: " + name); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...main/java/org/gelecekbilimde/scienceplatform/auth/exception/UserNotVerifiedException.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,16 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractAuthException; | ||
|
||
import java.io.Serial; | ||
|
||
public class UserNotVerifiedException extends AbstractAuthException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 263502105581485335L; | ||
|
||
public UserNotVerifiedException(String email) { | ||
super("user not verified yet! email: " + email); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...java/org/gelecekbilimde/scienceplatform/auth/exception/UserPasswordNotValidException.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,16 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.exception; | ||
|
||
import org.gelecekbilimde.scienceplatform.common.exception.AbstractAuthException; | ||
|
||
import java.io.Serial; | ||
|
||
public class UserPasswordNotValidException extends AbstractAuthException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 359664997679732461L; | ||
|
||
public UserPasswordNotValidException() { | ||
super("user password is not valid"); | ||
} | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/org/gelecekbilimde/scienceplatform/auth/exception/VerifyException.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...java/org/gelecekbilimde/scienceplatform/auth/exception/WrongEmailOrPasswordException.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/java/org/gelecekbilimde/scienceplatform/auth/model/Role.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,20 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.gelecekbilimde.scienceplatform.auth.model.entity.PermissionEntity; | ||
import org.gelecekbilimde.scienceplatform.auth.model.enums.RoleStatus; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class Role { | ||
|
||
private String id; | ||
private String name; | ||
private String description; | ||
private RoleStatus status; | ||
private List<PermissionEntity> permissions; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/gelecekbilimde/scienceplatform/auth/model/RoleApplication.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,17 @@ | ||
package org.gelecekbilimde.scienceplatform.auth.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.gelecekbilimde.scienceplatform.auth.model.enums.RoleApplicationStatus; | ||
import org.gelecekbilimde.scienceplatform.user.model.User; | ||
|
||
@Getter | ||
@Setter | ||
public class RoleApplication { | ||
|
||
private String id; | ||
private User user; | ||
private Role role; | ||
private RoleApplicationStatus status; | ||
|
||
} |
Oops, something went wrong.