-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#39 - expanding model, adding entity mappers
- Loading branch information
1 parent
7e97e55
commit 822b4a7
Showing
16 changed files
with
338 additions
and
19 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
16 changes: 16 additions & 0 deletions
16
user-module/src/main/java/io/edpn/backend/user/domain/model/ApiRole.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 io.edpn.backend.user.domain.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Value | ||
@Builder | ||
public class ApiRole { | ||
|
||
UUID id; | ||
String name; | ||
Set<String> grants; | ||
} |
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
3 changes: 3 additions & 0 deletions
3
user-module/src/main/java/io/edpn/backend/user/domain/model/UserRole.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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package io.edpn.backend.user.domain.model; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
@Value | ||
@Builder | ||
public class UserRole { | ||
|
||
UUID id; | ||
String name; | ||
Set<String> grants; | ||
} |
32 changes: 32 additions & 0 deletions
32
user-module/src/main/java/io/edpn/backend/user/infrastructure/entity/ApiKeyEntity.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,32 @@ | ||
package io.edpn.backend.user.infrastructure.entity; | ||
|
||
import io.edpn.backend.user.domain.model.ApiRole; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ApiKeyEntity { | ||
|
||
private UUID id; | ||
private String prefix; | ||
private String keyHash; | ||
private String name; | ||
private Set<ApiRoleEntity> roles; | ||
private Set<String> grants; | ||
private LocalDateTime expiryTimestamp; | ||
private boolean enabled; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
user-module/src/main/java/io/edpn/backend/user/infrastructure/entity/ApiRoleEntity.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,24 @@ | ||
package io.edpn.backend.user.infrastructure.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ApiRoleEntity { | ||
|
||
private UUID id; | ||
private String name; | ||
private Set<String> grants; | ||
} |
34 changes: 34 additions & 0 deletions
34
user-module/src/main/java/io/edpn/backend/user/infrastructure/entity/EdpnUserEntity.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,34 @@ | ||
package io.edpn.backend.user.infrastructure.entity; | ||
|
||
import io.edpn.backend.user.domain.model.ApiKey; | ||
import io.edpn.backend.user.domain.model.UserRole; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class EdpnUserEntity { | ||
|
||
private UUID id; | ||
private String email; | ||
private String password; | ||
private LocalDateTime accountExpiryTimestamp; | ||
private LocalDateTime passwordExpiryTimestamp; | ||
private boolean enabled; | ||
private boolean locked; | ||
private Set<UserRoleEntity> roles; | ||
private Set<String> grants; | ||
private Set<ApiKeyEntity> apiKeys; | ||
} |
23 changes: 23 additions & 0 deletions
23
user-module/src/main/java/io/edpn/backend/user/infrastructure/entity/PricingPlanEntity.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,23 @@ | ||
package io.edpn.backend.user.infrastructure.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class PricingPlanEntity { | ||
|
||
private UUID id; | ||
private String name; | ||
private long capacityPerMinute; | ||
} |
24 changes: 24 additions & 0 deletions
24
user-module/src/main/java/io/edpn/backend/user/infrastructure/entity/UserRoleEntity.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,24 @@ | ||
package io.edpn.backend.user.infrastructure.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class UserRoleEntity { | ||
|
||
private UUID id; | ||
private String name; | ||
private Set<String> grants; | ||
} |
37 changes: 37 additions & 0 deletions
37
user-module/src/main/java/io/edpn/backend/user/infrastructure/mapper/ApiKeyMapper.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,37 @@ | ||
package io.edpn.backend.user.infrastructure.mapper; | ||
|
||
import io.edpn.backend.user.domain.model.ApiKey; | ||
import io.edpn.backend.user.infrastructure.entity.ApiKeyEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
public class ApiKeyMapper { | ||
|
||
private final ApiRoleMapper apiRoleMapper; | ||
|
||
public ApiKey map(ApiKeyEntity entity) { | ||
return ApiKey.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.prefix(entity.getPrefix()) | ||
.keyHash(entity.getKeyHash()) | ||
.roles(entity.getRoles().stream().map(apiRoleMapper::map).collect(Collectors.toSet())) | ||
.grants(entity.getGrants()) | ||
.expiryTimestamp(entity.getExpiryTimestamp()) | ||
.build(); | ||
} | ||
|
||
public ApiKeyEntity map(ApiKey key) { | ||
return ApiKeyEntity.builder() | ||
.id(key.getId()) | ||
.name(key.getName()) | ||
.prefix(key.getPrefix()) | ||
.keyHash(key.getKeyHash()) | ||
.roles(key.getRoles().stream().map(apiRoleMapper::map).collect(Collectors.toSet())) | ||
.grants(key.getGrants()) | ||
.expiryTimestamp(key.getExpiryTimestamp()) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
user-module/src/main/java/io/edpn/backend/user/infrastructure/mapper/ApiRoleMapper.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,24 @@ | ||
package io.edpn.backend.user.infrastructure.mapper; | ||
|
||
import io.edpn.backend.user.domain.model.ApiRole; | ||
import io.edpn.backend.user.infrastructure.entity.ApiRoleEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ApiRoleMapper { | ||
|
||
public ApiRole map(ApiRoleEntity entity) { | ||
return ApiRole.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.grants(entity.getGrants()) | ||
.build(); | ||
} | ||
public ApiRoleEntity map(ApiRole role) { | ||
return ApiRoleEntity.builder() | ||
.id(role.getId()) | ||
.name(role.getName()) | ||
.grants(role.getGrants()) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
user-module/src/main/java/io/edpn/backend/user/infrastructure/mapper/EdpnMapper.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,44 @@ | ||
package io.edpn.backend.user.infrastructure.mapper; | ||
|
||
import io.edpn.backend.user.domain.model.EdpnUser; | ||
import io.edpn.backend.user.infrastructure.entity.EdpnUserEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
public class EdpnMapper { | ||
|
||
private final UserRoleMapper userRoleMapper; | ||
private final ApiKeyMapper apiKeyMapper; | ||
|
||
public EdpnUser map(EdpnUserEntity entity) { | ||
return EdpnUser.builder() | ||
.id(entity.getId()) | ||
.email(entity.getEmail()) | ||
.password(null) // DO NOT RETURN EMAIL | ||
.accountExpiryTimestamp(entity.getAccountExpiryTimestamp()) | ||
.passwordExpiryTimestamp(entity.getPasswordExpiryTimestamp()) | ||
.enabled(entity.isEnabled()) | ||
.locked(entity.isLocked()) | ||
.roles(entity.getRoles().stream().map(userRoleMapper::map).collect(Collectors.toSet())) | ||
.grants(entity.getGrants()) | ||
.apiKeys(entity.getApiKeys().stream().map(apiKeyMapper::map).collect(Collectors.toSet())) | ||
.build(); | ||
} | ||
|
||
public EdpnUserEntity map(EdpnUser user) { | ||
return EdpnUserEntity.builder() | ||
.id(user.getId()) | ||
.email(user.getEmail()) | ||
.password(user.getPassword()) | ||
.accountExpiryTimestamp(user.getAccountExpiryTimestamp()) | ||
.passwordExpiryTimestamp(user.getPasswordExpiryTimestamp()) | ||
.enabled(user.isEnabled()) | ||
.locked(user.isLocked()) | ||
.roles(user.getRoles().stream().map(userRoleMapper::map).collect(Collectors.toSet())) | ||
.grants(user.getGrants()) | ||
.apiKeys(user.getApiKeys().stream().map(apiKeyMapper::map).collect(Collectors.toSet())) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
user-module/src/main/java/io/edpn/backend/user/infrastructure/mapper/PricingPlanMapper.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,25 @@ | ||
package io.edpn.backend.user.infrastructure.mapper; | ||
|
||
import io.edpn.backend.user.domain.model.PricingPlan; | ||
import io.edpn.backend.user.infrastructure.entity.PricingPlanEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class PricingPlanMapper { | ||
|
||
public PricingPlan map(PricingPlanEntity entity) { | ||
return PricingPlan.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.capacityPerMinute(entity.getCapacityPerMinute()) | ||
.build(); | ||
} | ||
|
||
public PricingPlanEntity map(PricingPlan entity) { | ||
return PricingPlanEntity.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.capacityPerMinute(entity.getCapacityPerMinute()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.