This commit is contained in:
2025-10-26 09:58:08 +07:00
parent 35e88de99a
commit 44d4b94aef
8 changed files with 119 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
lombok.addLombokGeneratedAnnotation = true
lombok.experimental.flagUsage = error
lombok.log.apacheCommons.flagUsage = error
lombok.log.flogger.flagUsage = error
lombok.log.javaUtilLogging.flagUsage = error
lombok.log.jbosslog.flagUsage = error
lombok.log.log4j.flagUsage = error
lombok.log.slf4j.flagUsage = error
lombok.log.xslf4j.flagUsage = error
lombok.synchronized.flagUsage = error
lombok.val.flagUsage = error
lombok.var.flagUsage = error
@@ -1,5 +1,9 @@
package com.miti99.storescraperbot.config;
public class Config {
public static final String COUCHBASE_CONNECTION_STRING =
System.getenv("COUCHBASE_CONNECTION_STRING");
public static final String COUCHBASE_USERNAME = System.getenv("COUCHBASE_USERNAME");
public static final String COUCHBASE_PASSWORD = System.getenv("COUCHBASE_PASSWORD");
public static final String COUCHBASE_BUCKET_NAME = System.getenv("COUCHBASE_BUCKET_NAME");
}
@@ -0,0 +1,9 @@
package com.miti99.storescraperbot.model;
import java.util.List;
import lombok.Data;
@Data
public class Admin {
List<Long> groups;
}
@@ -0,0 +1,8 @@
package com.miti99.storescraperbot.model;
import com.miti99.storescraperbot.api.apple.response.AppleAppResponse;
public class AppleApp {
long cacheTime;
AppleAppResponse rawResponse;
}
@@ -0,0 +1,8 @@
package com.miti99.storescraperbot.model;
import com.miti99.storescraperbot.api.google.response.GoogleAppResponse;
public class GoogleApp {
long cacheTime;
GoogleAppResponse rawResponse;
}
@@ -0,0 +1,15 @@
package com.miti99.storescraperbot.model;
import com.miti99.storescraperbot.type.AppType;
import java.util.List;
import lombok.Data;
@Data
public class Group {
List<App> apps;
public static class App {
String appId;
AppType type;
}
}
@@ -0,0 +1,6 @@
package com.miti99.storescraperbot.type;
public enum AppType {
GOOGLE,
APPLE
}
@@ -0,0 +1,56 @@
package com.miti99.storescraperbot.util;
import static com.miti99.storescraperbot.config.Config.COUCHBASE_BUCKET_NAME;
import static com.miti99.storescraperbot.config.Config.COUCHBASE_CONNECTION_STRING;
import static com.miti99.storescraperbot.config.Config.COUCHBASE_PASSWORD;
import static com.miti99.storescraperbot.config.Config.COUCHBASE_USERNAME;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.ClusterOptions;
import com.couchbase.client.java.Collection;
import com.couchbase.client.java.Scope;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.GetResult;
import com.couchbase.client.java.kv.MutationResult;
import com.couchbase.client.java.query.QueryResult;
import java.time.Duration;
public class CouchbaseUtil {
public static final Cluster CLUSTER;
public static final Bucket BUCKET;
static {
CLUSTER =
Cluster.connect(
COUCHBASE_CONNECTION_STRING,
ClusterOptions.clusterOptions(COUCHBASE_USERNAME, COUCHBASE_PASSWORD)
.environment(
env -> {
// Customize client settings by calling methods on the "env" variable.
}));
// get a bucket reference
BUCKET = CLUSTER.bucket(COUCHBASE_BUCKET_NAME);
BUCKET.waitUntilReady(Duration.ofSeconds(10));
// get a user-defined collection reference
Scope scope = BUCKET.scope("tenant_agent_00");
Collection collection = scope.collection("users");
// Upsert Document
MutationResult upsertResult =
collection.upsert("my-document", JsonObject.create().put("name", "mike"));
// Get Document
GetResult getResult = collection.get("my-document");
String name = getResult.contentAsObject().getString("name");
System.out.println(name); // name == "mike"
// Call the query() method on the scope object and store the result.
Scope inventoryScope = BUCKET.scope("inventory");
QueryResult result = inventoryScope.query("SELECT * FROM airline WHERE id = 10;");
// Return the result rows with the rowsAsObject() method and print to the terminal.
System.out.println(result.rowsAsObject());
}
}