-
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.
- Loading branch information
1 parent
b9da13d
commit 3c399f6
Showing
24 changed files
with
403 additions
and
24 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
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
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/harmlessprince/ecommerceApi/permission/Permission.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,33 @@ | ||
package com.harmlessprince.ecommerceApi.permission; | ||
|
||
import com.harmlessprince.ecommerceApi.bases.BaseEntity; | ||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.index.Indexed; | ||
import org.springframework.data.mongodb.core.mapping.DBRef; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.Set; | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Document(collection = "permissions") | ||
public class Permission extends BaseEntity { | ||
@Id | ||
private String id; | ||
|
||
@Indexed(unique = true) | ||
private String name; | ||
|
||
private Boolean status = true; | ||
|
||
@Indexed(unique = true) | ||
private String slug; | ||
|
||
public void setSlug(String slug) { | ||
this.slug = slug.replace(" ", "_").toLowerCase(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/harmlessprince/ecommerceApi/permission/PermissionController.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,4 @@ | ||
package com.harmlessprince.ecommerceApi.permission; | ||
|
||
public class PermissionController { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/harmlessprince/ecommerceApi/permission/PermissionRepository.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,6 @@ | ||
package com.harmlessprince.ecommerceApi.permission; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface PermissionRepository extends MongoRepository<Permission, String> { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/harmlessprince/ecommerceApi/permission/PermissionService.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,4 @@ | ||
package com.harmlessprince.ecommerceApi.permission; | ||
|
||
public class PermissionService { | ||
} |
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
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/harmlessprince/ecommerceApi/role/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,39 @@ | ||
package com.harmlessprince.ecommerceApi.role; | ||
|
||
import com.harmlessprince.ecommerceApi.bases.BaseEntity; | ||
import com.harmlessprince.ecommerceApi.permission.Permission; | ||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.index.Indexed; | ||
import org.springframework.data.mongodb.core.mapping.DBRef; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.Set; | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Document(collection = "roles") | ||
public class Role extends BaseEntity { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Indexed(unique = true) | ||
private String name; | ||
|
||
private Boolean status = true; | ||
|
||
@Indexed(unique = true) | ||
private String slug; | ||
|
||
@DBRef | ||
private Set<Permission> permissions; | ||
|
||
public void setSlug() { | ||
this.slug = this.name.replace(" ", "_").toLowerCase(); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/harmlessprince/ecommerceApi/role/RoleController.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,35 @@ | ||
package com.harmlessprince.ecommerceApi.role; | ||
|
||
import com.harmlessprince.ecommerceApi.handler.CustomSuccessResponse; | ||
import com.harmlessprince.ecommerceApi.paymentMethod.PaymentMethod; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/v1/roles") | ||
@AllArgsConstructor | ||
public class RoleController { | ||
private final RoleService roleService; | ||
|
||
@GetMapping | ||
@PreAuthorize("hasAnyAuthority('admin', 'superadmin')") | ||
public ResponseEntity<CustomSuccessResponse<List<Role>>> findAll() { | ||
List<Role> roles = roleService.getAllRoles(); | ||
return ResponseEntity.ok(new CustomSuccessResponse<>(roles)); | ||
} | ||
|
||
// @GetMapping("/{userId}") | ||
// @PreAuthorize("hasAuthority('admin')") | ||
// public ResponseEntity<CustomSuccessResponse<?>> assignRoleToUser() { | ||
// List<Role> roles = roleService.getAllRoles(); | ||
// return ResponseEntity.ok(new CustomSuccessResponse<>(roles)); | ||
// } | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/harmlessprince/ecommerceApi/role/RoleRepository.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,9 @@ | ||
package com.harmlessprince.ecommerceApi.role; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface RoleRepository extends MongoRepository<Role, String> { | ||
Optional<Role> findFirstBySlug(String slug); | ||
} |
Oops, something went wrong.