Skip to content

Commit 102a9c9

Browse files
committed
Add support for the timestamp_range property after spec change
Signed-off-by: sdimitrov9 <stoyan.dimitrov@limechain.tech>
1 parent bdbfbd9 commit 102a9c9

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

rest-java/src/main/java/org/hiero/mirror/restjava/mapper/CommonMapper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hiero.mirror.rest.model.Key;
2121
import org.hiero.mirror.rest.model.Key.TypeEnum;
2222
import org.hiero.mirror.rest.model.TimestampRange;
23+
import org.hiero.mirror.rest.model.TimestampRangeNullable;
2324
import org.hiero.mirror.restjava.exception.InvalidMappingException;
2425
import org.mapstruct.Mapper;
2526
import org.mapstruct.MappingInheritanceStrategy;
@@ -115,6 +116,18 @@ default TimestampRange mapRange(Range<Long> source) {
115116
return target;
116117
}
117118

119+
default TimestampRangeNullable mapTimestampRangeNullable(Range<Long> source) {
120+
final var timestampRange = mapRange(source);
121+
if (timestampRange == null) {
122+
return null;
123+
}
124+
125+
final var target = new TimestampRangeNullable();
126+
target.setFrom(timestampRange.getFrom());
127+
target.setTo(timestampRange.getTo());
128+
return target;
129+
}
130+
118131
@Named(QUALIFIER_TIMESTAMP)
119132
default String mapTimestamp(Long timestamp) {
120133
if (timestamp == null) {

rest-java/src/main/java/org/hiero/mirror/restjava/repository/HookRepositoryCustomImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Collection<Hook> findAll(HooksRequest request, EntityId accountId) {
3232
final var orderBy = hookTable.HOOK_ID.sort(request.getOrder().isAscending() ? SortOrder.ASC : SortOrder.DESC);
3333

3434
return dsl.selectFrom(hookTable)
35-
.where(ownerIdCondition.and(hookIdCondition)) // Combine conditions
35+
.where(ownerIdCondition.and(hookIdCondition))
3636
.orderBy(orderBy)
3737
.limit(request.getLimit())
3838
.fetchInto(Hook.class);

rest-java/src/test/java/org/hiero/mirror/restjava/mapper/HookMapperTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
import static org.assertj.core.api.Assertions.assertThat;
66

7+
import com.google.common.collect.Range;
78
import org.apache.commons.codec.DecoderException;
89
import org.hiero.mirror.common.domain.entity.EntityId;
910
import org.hiero.mirror.common.domain.hook.HookExtensionPoint;
1011
import org.hiero.mirror.common.domain.hook.HookType;
1112
import org.hiero.mirror.rest.model.Hook;
1213
import org.hiero.mirror.rest.model.Key;
14+
import org.hiero.mirror.rest.model.TimestampRangeNullable;
1315
import org.junit.jupiter.api.BeforeEach;
1416
import org.junit.jupiter.api.Test;
1517

@@ -33,6 +35,7 @@ void map() throws DecoderException {
3335
source.setHookId(10L);
3436
source.setOwnerId(200L);
3537
source.setExtensionPoint(HookExtensionPoint.ACCOUNT_ALLOWANCE_HOOK);
38+
source.setTimestampRange(Range.closed(1L, 100000L));
3639
source.setType(HookType.LAMBDA);
3740
source.setDeleted(false);
3841

@@ -50,6 +53,8 @@ void map() throws DecoderException {
5053
assertThat(result.getHookId()).isEqualTo(10L);
5154
assertThat(result.getDeleted()).isFalse();
5255
assertThat(result.getExtensionPoint()).isEqualTo(Hook.ExtensionPointEnum.ACCOUNT_ALLOWANCE_HOOK);
56+
assertThat(result.getTimestampRange())
57+
.isEqualTo(new TimestampRangeNullable().from("0.000000001").to("0.000100000"));
5358
assertThat(result.getType()).isEqualTo(Hook.TypeEnum.LAMBDA);
5459
assertThat(result.getAdminKey().getType()).isEqualTo(Key.TypeEnum.ED25519);
5560
assertThat(result.getAdminKey().getKey()).hasSize(64);
@@ -77,6 +82,9 @@ void mapNulls() {
7782
.isNull();
7883
assertThat(result.getHookId()).as("hookId default for primitive long").isEqualTo(0L);
7984
assertThat(result.getOwnerId()).as("ownerId should be null").isNull();
85+
assertThat(result.getTimestampRange())
86+
.as("timestampRange should be null")
87+
.isNull();
8088
assertThat(result.getType()).as("type should be null").isNull();
8189
}
8290
}

rest/api/v1/openapi.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ components:
15951595
- extension_point
15961596
- hook_id
15971597
- owner_id
1598+
- timestamp_range
15981599
- type
15991600
properties:
16001601
admin_key:
@@ -1625,6 +1626,8 @@ components:
16251626
allOf:
16261627
- $ref: "#/components/schemas/EntityId"
16271628
description: The entity that owns the hook
1629+
timestamp_range:
1630+
$ref: "#/components/schemas/TimestampRangeNullable"
16281631
type:
16291632
description: The type of the hook implementation
16301633
enum: [LAMBDA]

0 commit comments

Comments
 (0)