-
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 #79 from neumanf/feature/click-stats
feat: click stats
- Loading branch information
Showing
84 changed files
with
1,675 additions
and
326 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
2 changes: 1 addition & 1 deletion
2
.../api/configuration/WebSecurityConfig.java → ...auth/configuration/WebSecurityConfig.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
3 changes: 3 additions & 0 deletions
3
apps/api/src/main/java/com/mally/api/auth/domain/valueobjects/UserId.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,3 @@ | ||
package com.mally.api.auth.domain.valueobjects; | ||
|
||
public record UserId(String value) {} |
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
5 changes: 5 additions & 0 deletions
5
apps/api/src/main/java/com/mally/api/shared/abstractions/UseCase.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,5 @@ | ||
package com.mally.api.shared.abstractions; | ||
|
||
public interface UseCase<TRequest, TResponse> { | ||
TResponse execute(TRequest request); | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/api/src/main/java/com/mally/api/shared/commands/FindAllCommand.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 com.mally.api.shared.commands; | ||
|
||
import com.mally.api.auth.domain.valueobjects.UserId; | ||
import com.mally.api.shared.utils.PaginationUtils; | ||
import jakarta.annotation.Nullable; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public record FindAllCommand( | ||
UserId userId, | ||
@Nullable String search, | ||
Pageable pageable | ||
) { | ||
public FindAllCommand(UserId userId, String search, int pageNumber, int pageSize, String orderBy, String sortBy) { | ||
this(userId, search, PaginationUtils.buildPageable(pageNumber, pageSize, orderBy, sortBy)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/api/src/main/java/com/mally/api/shared/configuration/InfluxConfiguration.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 com.mally.api.shared.configuration; | ||
|
||
import com.influxdb.client.InfluxDBClient; | ||
import com.influxdb.client.InfluxDBClientFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class InfluxConfiguration { | ||
|
||
@Value("${influx.url}") | ||
private String connectionUrl; | ||
|
||
@Value("${influx.token}") | ||
private String token; | ||
|
||
@Value("${influx.org}") | ||
private String org; | ||
|
||
@Bean | ||
public InfluxDBClient influxDBClient() { | ||
return InfluxDBClientFactory.create(connectionUrl, token.toCharArray(), org); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
apps/api/src/main/java/com/mally/api/shared/configuration/InfluxInitializer.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,59 @@ | ||
package com.mally.api.shared.configuration; | ||
|
||
import com.influxdb.client.BucketsApi; | ||
import com.influxdb.client.InfluxDBClient; | ||
import com.influxdb.client.domain.Bucket; | ||
import com.influxdb.client.domain.Organization; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class InfluxInitializer { | ||
private final InfluxDBClient influxDBClient; | ||
|
||
private final String bucketNames; | ||
|
||
private final String orgName; | ||
|
||
public InfluxInitializer(InfluxDBClient influxDBClient, | ||
@Value("${influx.buckets}") String buckets, | ||
@Value("${influx.org}") String org) { | ||
this.influxDBClient = influxDBClient; | ||
this.bucketNames = buckets; | ||
this.orgName = org; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
createBucketsIfNotExists(); | ||
} | ||
|
||
private void createBucketsIfNotExists() { | ||
BucketsApi bucketsApi = influxDBClient.getBucketsApi(); | ||
|
||
Organization organization = influxDBClient.getOrganizationsApi() | ||
.findOrganizations().stream() | ||
.filter(org -> org.getName().equals(orgName)) | ||
.findFirst() | ||
.orElseThrow(); | ||
|
||
for (String bucketName : bucketNames.split(",")) { | ||
boolean bucketAlreadyCreated = bucketsApi.findBucketByName(bucketName) != null; | ||
|
||
if (bucketAlreadyCreated) { | ||
log.info("Bucket with name {} already created, skipping...", bucketName); | ||
continue; | ||
} | ||
|
||
Bucket bucket = new Bucket(); | ||
bucket.setName(bucketName); | ||
bucket.setOrgID(organization.getId()); | ||
|
||
bucketsApi.createBucket(bucket); | ||
log.info("Created bucket {}", bucketName); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/api/src/main/java/com/mally/api/shared/configuration/RabbitMQConfiguration.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,22 @@ | ||
package com.mally.api.shared.configuration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.amqp.support.converter.MessageConverter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class RabbitMQConfiguration { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public RabbitMQConfiguration(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Bean | ||
MessageConverter messageConverter() { | ||
return new Jackson2JsonMessageConverter(objectMapper); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
apps/api/src/main/java/com/mally/api/shared/repositories/InfluxRepository.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,52 @@ | ||
package com.mally.api.shared.repositories; | ||
|
||
import com.influxdb.client.InfluxDBClient; | ||
import com.influxdb.client.domain.WritePrecision; | ||
import com.influxdb.query.FluxRecord; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Repository | ||
public class InfluxRepository { | ||
|
||
private final String org; | ||
|
||
private final InfluxDBClient influxDBClient; | ||
|
||
InfluxRepository(InfluxDBClient influxDBClient, @Value("${influx.org}") String org) { | ||
this.influxDBClient = influxDBClient; | ||
this.org = org; | ||
} | ||
|
||
public List<FluxRecord> query(String query) { | ||
var queryApi = influxDBClient.getQueryApi(); | ||
|
||
var tables = queryApi.query(query); | ||
|
||
var results = new ArrayList<FluxRecord>(); | ||
|
||
for (var table : tables) { | ||
var records = table.getRecords(); | ||
|
||
results.addAll(records); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public void writeMeasurement(Object measurement, String bucket) { | ||
influxDBClient.getWriteApiBlocking().writeMeasurement(bucket, org, WritePrecision.MS, measurement); | ||
} | ||
|
||
public void deleteMeasurement(Long measurementId, String bucket) { | ||
var start = OffsetDateTime.now().minusYears(100); | ||
var stop = OffsetDateTime.now(); | ||
var predicate = String.format("id=\"%s\"", measurementId); | ||
|
||
influxDBClient.getDeleteApi().delete(start, stop, predicate, bucket, org); | ||
} | ||
} |
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
Oops, something went wrong.