Skip to content

Commit

Permalink
refs #8 マジックカラムを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
averak committed Jan 8, 2024
1 parent 799e22d commit 07bc7fc
Show file tree
Hide file tree
Showing 27 changed files with 517 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.averak.gsync.adapter.dao.entity.base;

import java.util.Date;
import java.time.LocalDateTime;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -30,18 +30,39 @@ public class EchoEntity {
*
* @mbg.generated
*/
private Date timestamp;
private LocalDateTime timestamp;

/**
*
* This field was generated by MyBatis Generator. This field corresponds to the
* database column gsync_echo.created_at
*
* @mbg.generated
*/
private LocalDateTime createdAt;

/**
*
* This field was generated by MyBatis Generator. This field corresponds to the
* database column gsync_echo.updated_at
*
* @mbg.generated
*/
private LocalDateTime updatedAt;

/**
* This method was generated by MyBatis Generator. This method corresponds to
* the database table gsync_echo
*
* @mbg.generated
*/
public EchoEntity(@Nonnull String echoId, @Nonnull String message, @Nonnull Date timestamp) {
public EchoEntity(@Nonnull String echoId, @Nonnull String message, @Nonnull LocalDateTime timestamp,
@Nonnull LocalDateTime createdAt, @Nonnull LocalDateTime updatedAt) {
this.echoId = echoId;
this.message = message;
this.timestamp = timestamp;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

/**
Expand Down Expand Up @@ -115,7 +136,7 @@ public void setMessage(@Nonnull String message) {
* @mbg.generated
*/
@Nonnull
public Date getTimestamp() {
public LocalDateTime getTimestamp() {
return timestamp;
}

Expand All @@ -128,7 +149,59 @@ public Date getTimestamp() {
*
* @mbg.generated
*/
public void setTimestamp(@Nonnull Date timestamp) {
public void setTimestamp(@Nonnull LocalDateTime timestamp) {
this.timestamp = timestamp;
}

/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column gsync_echo.created_at
*
* @return the value of gsync_echo.created_at
*
* @mbg.generated
*/
@Nonnull
public LocalDateTime getCreatedAt() {
return createdAt;
}

/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column gsync_echo.created_at
*
* @param createdAt
* the value for gsync_echo.created_at
*
* @mbg.generated
*/
public void setCreatedAt(@Nonnull LocalDateTime createdAt) {
this.createdAt = createdAt;
}

/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column gsync_echo.updated_at
*
* @return the value of gsync_echo.updated_at
*
* @mbg.generated
*/
@Nonnull
public LocalDateTime getUpdatedAt() {
return updatedAt;
}

/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column gsync_echo.updated_at
*
* @param updatedAt
* the value for gsync_echo.updated_at
*
* @mbg.generated
*/
public void setUpdatedAt(@Nonnull LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.averak.gsync.adapter.dao.entity.base;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class EchoExample {
Expand Down Expand Up @@ -345,55 +345,175 @@ public Criteria andTimestampIsNotNull() {
return (Criteria) this;
}

public Criteria andTimestampEqualTo(Date value) {
public Criteria andTimestampEqualTo(LocalDateTime value) {
addCriterion("`timestamp` =", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampNotEqualTo(Date value) {
public Criteria andTimestampNotEqualTo(LocalDateTime value) {
addCriterion("`timestamp` <>", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampGreaterThan(Date value) {
public Criteria andTimestampGreaterThan(LocalDateTime value) {
addCriterion("`timestamp` >", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampGreaterThanOrEqualTo(Date value) {
public Criteria andTimestampGreaterThanOrEqualTo(LocalDateTime value) {
addCriterion("`timestamp` >=", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampLessThan(Date value) {
public Criteria andTimestampLessThan(LocalDateTime value) {
addCriterion("`timestamp` <", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampLessThanOrEqualTo(Date value) {
public Criteria andTimestampLessThanOrEqualTo(LocalDateTime value) {
addCriterion("`timestamp` <=", value, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampIn(List<Date> values) {
public Criteria andTimestampIn(List<LocalDateTime> values) {
addCriterion("`timestamp` in", values, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampNotIn(List<Date> values) {
public Criteria andTimestampNotIn(List<LocalDateTime> values) {
addCriterion("`timestamp` not in", values, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampBetween(Date value1, Date value2) {
public Criteria andTimestampBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`timestamp` between", value1, value2, "timestamp");
return (Criteria) this;
}

public Criteria andTimestampNotBetween(Date value1, Date value2) {
public Criteria andTimestampNotBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`timestamp` not between", value1, value2, "timestamp");
return (Criteria) this;
}

public Criteria andCreatedAtIsNull() {
addCriterion("`created_at` is null");
return (Criteria) this;
}

public Criteria andCreatedAtIsNotNull() {
addCriterion("`created_at` is not null");
return (Criteria) this;
}

public Criteria andCreatedAtEqualTo(LocalDateTime value) {
addCriterion("`created_at` =", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtNotEqualTo(LocalDateTime value) {
addCriterion("`created_at` <>", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtGreaterThan(LocalDateTime value) {
addCriterion("`created_at` >", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtGreaterThanOrEqualTo(LocalDateTime value) {
addCriterion("`created_at` >=", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtLessThan(LocalDateTime value) {
addCriterion("`created_at` <", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtLessThanOrEqualTo(LocalDateTime value) {
addCriterion("`created_at` <=", value, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtIn(List<LocalDateTime> values) {
addCriterion("`created_at` in", values, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtNotIn(List<LocalDateTime> values) {
addCriterion("`created_at` not in", values, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`created_at` between", value1, value2, "createdAt");
return (Criteria) this;
}

public Criteria andCreatedAtNotBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`created_at` not between", value1, value2, "createdAt");
return (Criteria) this;
}

public Criteria andUpdatedAtIsNull() {
addCriterion("`updated_at` is null");
return (Criteria) this;
}

public Criteria andUpdatedAtIsNotNull() {
addCriterion("`updated_at` is not null");
return (Criteria) this;
}

public Criteria andUpdatedAtEqualTo(LocalDateTime value) {
addCriterion("`updated_at` =", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtNotEqualTo(LocalDateTime value) {
addCriterion("`updated_at` <>", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtGreaterThan(LocalDateTime value) {
addCriterion("`updated_at` >", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtGreaterThanOrEqualTo(LocalDateTime value) {
addCriterion("`updated_at` >=", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtLessThan(LocalDateTime value) {
addCriterion("`updated_at` <", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtLessThanOrEqualTo(LocalDateTime value) {
addCriterion("`updated_at` <=", value, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtIn(List<LocalDateTime> values) {
addCriterion("`updated_at` in", values, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtNotIn(List<LocalDateTime> values) {
addCriterion("`updated_at` not in", values, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`updated_at` between", value1, value2, "updatedAt");
return (Criteria) this;
}

public Criteria andUpdatedAtNotBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("`updated_at` not between", value1, value2, "updatedAt");
return (Criteria) this;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.averak.gsync.core.game_context.GameContext
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*

@Component
class HttpRequestScope(
Expand Down Expand Up @@ -50,8 +51,10 @@ class HttpRequestScope(
return httpServletRequest.getHeader(HeaderName.CLIENT_VERSION.key)
}

fun getIdempotencyKey(): String? {
return httpServletRequest.getHeader(HeaderName.IDEMPOTENCY_KEY.key)
fun getIdempotencyKey(): UUID? {
return httpServletRequest.getHeader(HeaderName.IDEMPOTENCY_KEY.key)?.let {
UUID.fromString(it)
}
}

fun getSpoofingCurrentTime(): LocalDateTime? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AccessLogInterceptor(
mapOf(
"http_request" to mapOf(
"client_version" to requestScope.getClientVersion(),
"idempotency_key" to gctx.idempotencyKey,
"idempotency_key" to gctx.idempotencyKey.toString(),
"requested_at" to gctx.currentTime.toString(),
"elapsed_ms" to Duration.between(gctx.currentTime, LocalDateTime.now()).toMillis(),
"status_code" to HttpStatusCode.valueOf(response.status),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class GameContextInterceptor(
val gctx = GameContext(
config.version,
// クライアントが Idempotency-Key を必ず設定してくるとは限らないので、未設定の場合はサーバ側でユニークキーを発行し、毎回異なるリクエストとして扱う
requestScope.getIdempotencyKey() ?: UUID.randomUUID().toString(),
requestScope.getIdempotencyKey() ?: UUID.randomUUID(),
Dateline.DEFAULT,
spoofingCurrentTime ?: LocalDateTime.now(),
)
Expand Down
Loading

0 comments on commit 07bc7fc

Please sign in to comment.