diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 843b526f9..d04c32ab2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,7 +34,7 @@ jobs: - name: Run test run: go test ./src/... -v -coverprofile=/tmp/coverage/coverage.txt -race -vet=off - name: Upload coverage data - uses: codecov/codecov-action@v4.5.0 + uses: codecov/codecov-action@v4.6.0 with: file: /tmp/coverage/coverage.txt token: ${{ secrets.CODECOV_TOKEN }} diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 40ea1ca6e..99c3dc1ee 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,6 +1,6 @@ # syntax = docker/dockerfile:1 -FROM golang:1.23.1-alpine AS build +FROM golang:1.23.2-alpine AS build RUN --mount=type=cache,target=/var/cache/apk \ apk --update add tzdata git && \ diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index f61812746..62f148879 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -1,6 +1,6 @@ # syntax = docker/dockerfile:1 -FROM golang:1.23.1-alpine AS build +FROM golang:1.23.2-alpine AS build RUN apk add --update --no-cache git diff --git a/go.mod b/go.mod index 89c8abfff..14fe0342e 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,12 @@ go 1.23 toolchain go1.23.0 require ( - github.com/aws/aws-sdk-go-v2 v1.31.0 - github.com/aws/aws-sdk-go-v2/credentials v1.17.37 + github.com/aws/aws-sdk-go-v2 v1.32.2 + github.com/aws/aws-sdk-go-v2/credentials v1.17.41 github.com/cosmtrek/air v1.52.1 github.com/deepmap/oapi-codegen v1.16.3 github.com/dgraph-io/ristretto v0.1.1 - github.com/getkin/kin-openapi v0.127.0 + github.com/getkin/kin-openapi v0.128.0 github.com/go-task/task/v3 v3.39.2 github.com/golang/mock v1.6.0 github.com/google/uuid v1.6.0 @@ -20,13 +20,13 @@ require ( github.com/labstack/echo-contrib v0.17.1 github.com/labstack/echo/v4 v4.12.0 github.com/mazrean/formstream v1.1.1 - github.com/ncw/swift/v2 v2.0.2 + github.com/ncw/swift/v2 v2.0.3 github.com/oapi-codegen/echo-middleware v1.0.2 - github.com/oapi-codegen/oapi-codegen/v2 v2.4.0 + github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 github.com/oapi-codegen/runtime v1.1.1 github.com/ory/dockertest/v3 v3.11.0 github.com/stretchr/testify v1.9.0 - golang.org/x/mod v0.19.0 + golang.org/x/mod v0.21.0 golang.org/x/sync v0.8.0 gorm.io/driver/mysql v1.5.7 gorm.io/gorm v1.25.12 @@ -42,20 +42,20 @@ require ( github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect github.com/alecthomas/chroma/v2 v2.14.0 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect - github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.5 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect - github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.18 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.20 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.18 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.31.3 // indirect - github.com/aws/smithy-go v1.21.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 // indirect + github.com/aws/smithy-go v1.22.0 // indirect github.com/bep/godartsass v1.2.0 // indirect github.com/bep/godartsass/v2 v2.0.0 // indirect github.com/bep/golibsass v1.1.1 // indirect @@ -122,9 +122,9 @@ require ( ) require ( - github.com/aws/aws-sdk-go-v2/config v1.27.39 - github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.10 - github.com/aws/aws-sdk-go-v2/service/s3 v1.63.3 + github.com/aws/aws-sdk-go-v2/config v1.28.0 + github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.33 + github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -143,7 +143,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.20.3 + github.com/prometheus/client_golang v1.20.5 github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect diff --git a/go.sum b/go.sum index a4a5fa84c..07f1dbb0e 100644 --- a/go.sum +++ b/go.sum @@ -69,44 +69,44 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c h1:651/eoCRnQ7YtSjAnSzRucrJz+3iGEFt+ysraELS81M= github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U= -github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.5 h1:xDAuZTn4IMm8o1LnBZvmrL8JA1io4o3YWNXgohbf20g= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.5/go.mod h1:wYSv6iDS621sEFLfKvpPE2ugjTuGlAG7iROg0hLOkfc= -github.com/aws/aws-sdk-go-v2/config v1.27.39 h1:FCylu78eTGzW1ynHcongXK9YHtoXD5AiiUqq3YfJYjU= -github.com/aws/aws-sdk-go-v2/config v1.27.39/go.mod h1:wczj2hbyskP4LjMKBEZwPRO1shXY+GsQleab+ZXT2ik= -github.com/aws/aws-sdk-go-v2/credentials v1.17.37 h1:G2aOH01yW8X373JK419THj5QVqu9vKEwxSEsGxihoW0= -github.com/aws/aws-sdk-go-v2/credentials v1.17.37/go.mod h1:0ecCjlb7htYCptRD45lXJ6aJDQac6D2NlKGpZqyTG6A= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 h1:C/d03NAmh8C4BZXhuRNboF/DqhBkBCeDiJDcaqIT5pA= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14/go.mod h1:7I0Ju7p9mCIdlrfS+JCgqcYD0VXz/N4yozsox+0o078= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.10 h1:zeN9UtUlA6FTx0vFSayxSX32HDw73Yb6Hh2izDSFxXY= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.10/go.mod h1:3HKuexPDcwLWPaqpW2UR/9n8N/u/3CKcGAzSs8p8u8g= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18/go.mod h1:r506HmK5JDUh9+Mw4CfGJGSSoqIiLCndAuqXuhbv67Y= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7YuhtVxN99v2cCoHRXOS4mTr0B/pUc= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc= +github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= +github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= +github.com/aws/aws-sdk-go-v2/config v1.28.0 h1:FosVYWcqEtWNxHn8gB/Vs6jOlNwSoyOCA/g/sxyySOQ= +github.com/aws/aws-sdk-go-v2/config v1.28.0/go.mod h1:pYhbtvg1siOOg8h5an77rXle9tVG8T+BWLWAo7cOukc= +github.com/aws/aws-sdk-go-v2/credentials v1.17.41 h1:7gXo+Axmp+R4Z+AK8YFQO0ZV3L0gizGINCOWxSLY9W8= +github.com/aws/aws-sdk-go-v2/credentials v1.17.41/go.mod h1:u4Eb8d3394YLubphT4jLEwN1rLNq2wFOlT6OuxFwPzU= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 h1:TMH3f/SCAWdNtXXVPPu5D6wrr4G5hI1rAxbcocKfC7Q= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17/go.mod h1:1ZRXLdTpzdJb9fwTMXiLipENRxkGMTn1sfKexGllQCw= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.33 h1:X+4YY5kZRI/cOoSMVMGTqFXHAMg1bvvay7IBcqHpybQ= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.33/go.mod h1:DPynzu+cn92k5UQ6tZhX+wfTB4ah6QDU/NgdHqatmvk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.18 h1:OWYvKL53l1rbsUmW7bQyJVsYU/Ii3bbAAQIIFNbM0Tk= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.18/go.mod h1:CUx0G1v3wG6l01tUB+j7Y8kclA8NSqK4ef0YG79a4cg= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 h1:QFASJGfT8wMXtuP3D5CRmMjARHv9ZmzFUMJznHDOY3w= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5/go.mod h1:QdZ3OmoIjSX+8D1OPAzPxDfjXASbBMDsz9qvtyIhtik= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.20 h1:rTWjG6AvWekO2B1LHeM3ktU7MqyX9rzWQ7hgzneZW7E= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.20/go.mod h1:RGW2DDpVc8hu6Y6yG8G5CHVmVOAn1oV8rNKOHRJyswg= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 h1:Xbwbmk44URTiHNx6PNo0ujDE6ERlsCKJD3u1zfnzAPg= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20/go.mod h1:oAfOFzUB14ltPZj1rWwRc3d/6OgD76R8KlvU3EqM9Fg= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.18 h1:eb+tFOIl9ZsUe2259/BKPeniKuz4/02zZFH/i4Nf8Rg= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.18/go.mod h1:GVCC2IJNJTmdlyEsSmofEy7EfJncP7DNnXDzRjJ5Keg= -github.com/aws/aws-sdk-go-v2/service/s3 v1.63.3 h1:3zt8qqznMuAZWDTDpcwv9Xr11M/lVj2FsRR7oYBt0OA= -github.com/aws/aws-sdk-go-v2/service/s3 v1.63.3/go.mod h1:NLTqRLe3pUNu3nTEHI6XlHLKYmc8fbHUdMxAB6+s41Q= -github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 h1:rs4JCczF805+FDv2tRhZ1NU0RB2H6ryAvsWPanAr72Y= -github.com/aws/aws-sdk-go-v2/service/sso v1.23.3/go.mod h1:XRlMvmad0ZNL+75C5FYdMvbbLkd6qiqz6foR1nA1PXY= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 h1:S7EPdMVZod8BGKQQPTBK+FcX9g7bKR7c4+HxWqHP7Vg= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3/go.mod h1:FnvDM4sfa+isJ3kDXIzAB9GAwVSzFzSy97uZ3IsHo4E= -github.com/aws/aws-sdk-go-v2/service/sts v1.31.3 h1:VzudTFrDCIDakXtemR7l6Qzt2+JYsVqo2MxBPt5k8T8= -github.com/aws/aws-sdk-go-v2/service/sts v1.31.3/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI= -github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA= -github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 h1:7edmS3VOBDhK00b/MwGtGglCm7hhwNYnjJs/PgFdMQE= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21/go.mod h1:Q9o5h4HoIWG8XfzxqiuK/CGUbepCJ8uTlaE3bAbxytQ= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 h1:4FMHqLfk0efmTqhXVRL5xYRqlEBNBiRI7N6w4jsEdd4= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2/go.mod h1:LWoqeWlK9OZeJxsROW2RqrSPvQHKTpp69r/iDjwsSaw= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 h1:s7NA1SOw8q/5c0wr8477yOPp0z+uBaXBnLE0XYb0POA= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2/go.mod h1:fnjjWyAW/Pj5HYOxl9LJqWtEwS7W2qgcRLWP+uWbss0= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 h1:t7iUP9+4wdc5lt3E41huP+GvQZJD38WLsgVp4iOtAjg= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2/go.mod h1:/niFCtmuQNxqx9v8WAPq5qh7EH25U4BF6tjoyq9bObM= +github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 h1:xA6XhTF7PE89BCNHJbQi8VvPzcgMtmGC5dr8S8N7lHk= +github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0/go.mod h1:cB6oAuus7YXRZhWCc1wIwPywwZ1XwweNp2TVAEGYeB8= +github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 h1:bSYXVyUzoTHoKalBmwaZxs97HU9DWWI3ehHSAMa7xOk= +github.com/aws/aws-sdk-go-v2/service/sso v1.24.2/go.mod h1:skMqY7JElusiOUjMJMOv1jJsP7YUg7DrhgqZZWuzu1U= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 h1:AhmO1fHINP9vFYUE0LHzCWg/LfUWUF+zFPEcY9QXb7o= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2/go.mod h1:o8aQygT2+MVP0NaV6kbdE1YnnIM8RRVQzoeUH45GOdI= +github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 h1:CiS7i0+FUe+/YY1GvIBLLrR/XNGZ4CtM1Ll0XavNuVo= +github.com/aws/aws-sdk-go-v2/service/sts v1.32.2/go.mod h1:HtaiBI8CjYoNVde8arShXb94UbQQi9L4EMr6D+xGBwo= +github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= +github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -206,8 +206,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY= -github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM= +github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4= +github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -452,8 +452,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/ncw/swift/v2 v2.0.2 h1:jx282pcAKFhmoZBSdMcCRFn9VWkoBIRsCpe+yZq7vEk= -github.com/ncw/swift/v2 v2.0.2/go.mod h1:z0A9RVdYPjNjXVo2pDOPxZ4eu3oarO1P91fTItcb+Kg= +github.com/ncw/swift/v2 v2.0.3 h1:8R9dmgFIWs+RiVlisCEfiQiik1hjuR0JnOkLxaP9ihg= +github.com/ncw/swift/v2 v2.0.3/go.mod h1:cbAO76/ZwcFrFlHdXPjaqWZ9R7Hdar7HpjRXBfbjigk= github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek= github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -461,8 +461,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oapi-codegen/echo-middleware v1.0.2 h1:oNBqiE7jd/9bfGNk/bpbX2nqWrtPc+LL4Boya8Wl81U= github.com/oapi-codegen/echo-middleware v1.0.2/go.mod h1:5J6MFcGqrpWLXpbKGZtRPZViLIHyyyUHlkqg6dT2R4E= -github.com/oapi-codegen/oapi-codegen/v2 v2.4.0 h1:ewncaynfMEu6CgvhxUFsMx7y/9aXFtGVXC3eJx/lwxY= -github.com/oapi-codegen/oapi-codegen/v2 v2.4.0/go.mod h1:zerrXS/bF5RsHAGFUjfEtq5OyMjuLAeMZCb84orpd7g= +github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 h1:ykgG34472DWey7TSjd8vIfNykXgjOgYJZoQbKfEeY/Q= +github.com/oapi-codegen/oapi-codegen/v2 v2.4.1/go.mod h1:N5+lY1tiTDV3V1BeHtOxeWXHoPVeApvsvjJqegfoaz8= github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro= github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg= github.com/oapi-codegen/testutil v1.0.0 h1:1GI2IiMMLh2vDHr1OkNacaYU/VaApKdcmfgl4aeXAa8= @@ -513,8 +513,8 @@ github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrb github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= -github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= -github.com/prometheus/client_golang v1.20.3/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -685,8 +685,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/src/handler/v2/game.go b/src/handler/v2/game.go index 19e3d3545..76f34fc53 100644 --- a/src/handler/v2/game.go +++ b/src/handler/v2/game.go @@ -396,11 +396,29 @@ func (g *Game) PatchGame(ctx echo.Context, gameID openapi.GameIDInPath) error { return echo.NewHTTPError(http.StatusInternalServerError, "failed to validate game name") } + // visibilityが変更されない場合はnilを指定する + var visibility *values.GameVisibility + if req.Visibility != nil { + var vis values.GameVisibility + switch { + case *req.Visibility == openapi.Public: + vis = values.GameVisibilityTypePublic + case *req.Visibility == openapi.Limited: + vis = values.GameVisibilityTypeLimited + case *req.Visibility == openapi.Private: + vis = values.GameVisibilityTypePrivate + default: + return echo.NewHTTPError(http.StatusBadRequest, "invalid visibility") + } + visibility = &vis + } + game, err := g.gameService.UpdateGame( ctx.Request().Context(), values.GameID(gameID), gameName, values.GameDescription(req.Description), + visibility, ) if errors.Is(err, service.ErrNoGame) { return echo.NewHTTPError(http.StatusNotFound, "game not found") @@ -409,10 +427,25 @@ func (g *Game) PatchGame(ctx echo.Context, gameID openapi.GameIDInPath) error { return echo.NewHTTPError(http.StatusInternalServerError, "failed to update game") } + gameVisibility := game.GetVisibility() + var apiVisibility openapi.GameVisibility + switch gameVisibility { + case values.GameVisibilityTypePublic: + apiVisibility = openapi.Public + case values.GameVisibilityTypeLimited: + apiVisibility = openapi.Limited + case values.GameVisibilityTypePrivate: + apiVisibility = openapi.Private + default: + log.Printf("error: invalid visibility: %v\n", gameVisibility) + return echo.NewHTTPError(http.StatusInternalServerError, "failed to get game visibility") + } + res := openapi.GameInfo{ Name: string(game.GetName()), Id: uuid.UUID(game.GetID()), Description: string(game.GetDescription()), + Visibility: apiVisibility, CreatedAt: game.GetCreatedAt(), } diff --git a/src/handler/v2/game_test.go b/src/handler/v2/game_test.go index 5cfee843e..d3c52a3e5 100644 --- a/src/handler/v2/game_test.go +++ b/src/handler/v2/game_test.go @@ -1966,6 +1966,8 @@ func TestPatchGame(t *testing.T) { now := time.Now() + openapiLimited := openapi.Limited + testCases := []test{ { description: "特に問題ないのでエラーなし", @@ -1973,6 +1975,7 @@ func TestPatchGame(t *testing.T) { newGame: &openapi.PatchGameJSONRequestBody{ Name: "test", Description: "test", + Visibility: &openapiLimited, }, executeUpdateGame: true, game: domain.NewGame( @@ -1986,6 +1989,30 @@ func TestPatchGame(t *testing.T) { Id: uuid.UUID(gameID), Name: "test", Description: "test", + Visibility: openapi.Limited, + CreatedAt: now, + }, + }, + { + description: "visibilityがnilでもエラーなし", + gameID: gameID, + newGame: &openapi.PatchGameJSONRequestBody{ + Name: "test", + Description: "test", + }, + executeUpdateGame: true, + game: domain.NewGame( + gameID, + values.NewGameName("test"), + values.NewGameDescription("test"), + values.GameVisibilityTypePublic, + now, + ), + apiGame: openapi.GameInfo{ + Id: uuid.UUID(gameID), + Name: "test", + Description: "test", + Visibility: openapi.Public, CreatedAt: now, }, }, @@ -2034,6 +2061,7 @@ func TestPatchGame(t *testing.T) { Id: uuid.UUID(gameID), Name: "test", Description: "", + Visibility: openapi.Limited, CreatedAt: now, }, }, @@ -2090,9 +2118,25 @@ func TestPatchGame(t *testing.T) { c := e.NewContext(req, rec) if testCase.executeUpdateGame { + var visibility *values.GameVisibility + if testCase.newGame.Visibility != nil { + var vis values.GameVisibility + switch *testCase.newGame.Visibility { + case openapi.Limited: + vis = values.GameVisibilityTypeLimited + case openapi.Private: + vis = values.GameVisibilityTypePrivate + case openapi.Public: + vis = values.GameVisibilityTypePublic + default: + t.Fatalf("invalid visibility: %v", *testCase.newGame.Visibility) + } + visibility = &vis + } + mockGameService. EXPECT(). - UpdateGame(gomock.Any(), gomock.Any(), values.NewGameName(testCase.newGame.Name), values.NewGameDescription(testCase.newGame.Description)). + UpdateGame(gomock.Any(), gomock.Any(), values.NewGameName(testCase.newGame.Name), values.NewGameDescription(testCase.newGame.Description), visibility). Return(testCase.game, testCase.UpdateGameErr) } @@ -2127,6 +2171,7 @@ func TestPatchGame(t *testing.T) { assert.Equal(t, testCase.apiGame.Name, responseGame.Name) assert.Equal(t, testCase.apiGame.Id, responseGame.Id) assert.Equal(t, testCase.apiGame.Description, responseGame.Description) + assert.Equal(t, testCase.apiGame.Visibility, responseGame.Visibility) assert.WithinDuration(t, testCase.apiGame.CreatedAt, responseGame.CreatedAt, time.Second) }) } diff --git a/src/repository/gorm2/v2_game.go b/src/repository/gorm2/v2_game.go index 4395a99e0..21e981853 100644 --- a/src/repository/gorm2/v2_game.go +++ b/src/repository/gorm2/v2_game.go @@ -72,9 +72,15 @@ func (g *GameV2) UpdateGame(ctx context.Context, game *domain.Game) error { return fmt.Errorf("failed to get db: %w", err) } + visibility, err := g.getVisibility(ctx, game.GetVisibility()) + if err != nil { + return fmt.Errorf("failed to get visibility: %w", err) + } + gameTable := migrate.GameTable2{ - Name: string(game.GetName()), - Description: string(game.GetDescription()), + Name: string(game.GetName()), + Description: string(game.GetDescription()), + VisibilityTypeID: visibility.ID, } result := db. @@ -346,3 +352,25 @@ func (g *GameV2) GetGamesByIDs(ctx context.Context, gameIDs []values.GameID, loc return gamesDomains, nil } + +func (g *GameV2) getVisibility(ctx context.Context, visibility values.GameVisibility) (*migrate.GameVisibilityTypeTable, error) { + db, err := g.db.getDB(ctx) + if err != nil { + return nil, fmt.Errorf("failed to get db: %w", err) + } + + visibilityTypeName, err := convertVisibilityType(visibility) + if err != nil { + return nil, fmt.Errorf("failed to convert visibility type: %w", err) + } + + var visibilityType migrate.GameVisibilityTypeTable + err = db. + Where("name = ?", visibilityTypeName). + Take(&visibilityType).Error + if err != nil { + return nil, fmt.Errorf("failed to get visibility type: %w", err) + } + + return &visibilityType, nil +} diff --git a/src/repository/gorm2/v2_game_test.go b/src/repository/gorm2/v2_game_test.go index af5e3c7dc..3decd0189 100644 --- a/src/repository/gorm2/v2_game_test.go +++ b/src/repository/gorm2/v2_game_test.go @@ -172,15 +172,29 @@ func TestUpdateGameV2(t *testing.T) { now := time.Now() - var gameVisibilityPublic migrate.GameVisibilityTypeTable + var gameVisibilityTypes []migrate.GameVisibilityTypeTable err = db. - Session(&gorm.Session{}). - Where(&migrate.GameVisibilityTypeTable{Name: migrate.GameVisibilityTypePublic}). - Find(&gameVisibilityPublic).Error + Find(&gameVisibilityTypes).Error if err != nil { t.Fatalf("failed to get game visibility: %v\n", err) } - gameVisibilityTypeIDPublic := gameVisibilityPublic.ID + var ( + gameVisibilityTypeIDPublic int + gameVisibilityTypeIDLimited int + // gameVisibilityTypeIDPrivate int + ) + for i := range gameVisibilityTypes { + switch gameVisibilityTypes[i].Name { + case migrate.GameVisibilityTypePublic: + gameVisibilityTypeIDPublic = gameVisibilityTypes[i].ID + case migrate.GameVisibilityTypeLimited: + gameVisibilityTypeIDLimited = gameVisibilityTypes[i].ID + case migrate.GameVisibilityTypePrivate: + _ = gameVisibilityTypes[i].ID + default: + t.Fatalf("unknown game visibility type: %s", gameVisibilityTypes[i].Name) + } + } testCases := []test{ { @@ -207,7 +221,7 @@ func TestUpdateGameV2(t *testing.T) { Name: "test2", Description: "test2", CreatedAt: now, - VisibilityTypeID: gameVisibilityTypeIDPublic, + VisibilityTypeID: gameVisibilityTypeIDLimited, }, }, }, @@ -242,7 +256,7 @@ func TestUpdateGameV2(t *testing.T) { Name: "test3", Description: "test3", CreatedAt: now, - VisibilityTypeID: gameVisibilityTypeIDPublic, + VisibilityTypeID: gameVisibilityTypeIDLimited, }, { ID: uuid.UUID(gameID2), @@ -324,6 +338,7 @@ func TestUpdateGameV2(t *testing.T) { assert.Equal(t, game.ID, games[i].ID) assert.Equal(t, game.Name, games[i].Name) assert.Equal(t, game.Description, games[i].Description) + assert.Equal(t, game.VisibilityTypeID, games[i].VisibilityTypeID) assert.WithinDuration(t, game.CreatedAt, games[i].CreatedAt, time.Second) } }) @@ -1545,3 +1560,54 @@ func TestGetGamesByIDsV2(t *testing.T) { }) } } + +func Test_getVisibility(t *testing.T) { + ctx := context.Background() + + gameRepository := NewGameV2(testDB) + + type test struct { + visibility values.GameVisibility + want migrate.GameVisibilityTypeTable + isErr bool + } + + testCases := map[string]test{ + "public": { + visibility: values.GameVisibilityTypePublic, + want: migrate.GameVisibilityTypeTable{ + Name: migrate.GameVisibilityTypePublic, + }, + }, + "limited": { + visibility: values.GameVisibilityTypeLimited, + want: migrate.GameVisibilityTypeTable{ + Name: migrate.GameVisibilityTypeLimited, + }, + }, + "private": { + visibility: values.GameVisibilityTypePrivate, + want: migrate.GameVisibilityTypeTable{ + Name: migrate.GameVisibilityTypePrivate, + }, + }, + "invalid": { + visibility: values.GameVisibility(-1), + want: migrate.GameVisibilityTypeTable{}, + isErr: true, + }, + } + + for name, testCase := range testCases { + t.Run(name, func(t *testing.T) { + got, err := gameRepository.getVisibility(ctx, testCase.visibility) + + if testCase.isErr { + assert.Error(t, err) + } else { + assert.Equal(t, testCase.want.Name, got.Name) + assert.NoError(t, err) + } + }) + } +} diff --git a/src/repository/gorm2/visibility.go b/src/repository/gorm2/visibility.go new file mode 100644 index 000000000..7734b5062 --- /dev/null +++ b/src/repository/gorm2/visibility.go @@ -0,0 +1,21 @@ +package gorm2 + +import ( + "fmt" + + "github.com/traPtitech/trap-collection-server/src/domain/values" + "github.com/traPtitech/trap-collection-server/src/repository/gorm2/migrate" +) + +func convertVisibilityType(visibility values.GameVisibility) (string, error) { + switch visibility { + case values.GameVisibilityTypePublic: + return migrate.GameVisibilityTypePublic, nil + case values.GameVisibilityTypeLimited: + return migrate.GameVisibilityTypeLimited, nil + case values.GameVisibilityTypePrivate: + return migrate.GameVisibilityTypePrivate, nil + default: + return "", fmt.Errorf("invalid visibility type: %d", visibility) + } +} diff --git a/src/service/v2/game.go b/src/service/v2/game.go index 3796d4ef2..b31d43e8c 100644 --- a/src/service/v2/game.go +++ b/src/service/v2/game.go @@ -351,8 +351,8 @@ func (g *Game) GetMyGames( return gameNumber, myGamesWithGenres, nil } -func (g *Game) UpdateGame(ctx context.Context, gameID values.GameID, name values.GameName, description values.GameDescription) (*domain.Game, error) { //V1と変わらず - var game *domain.Game +func (g *Game) UpdateGame(ctx context.Context, gameID values.GameID, name values.GameName, description values.GameDescription, visibility *values.GameVisibility) (*domain.Game, error) { + var game, newGame *domain.Game err := g.db.Transaction(ctx, nil, func(ctx context.Context) error { var err error game, err = g.gameRepository.GetGame(ctx, gameID, repository.LockTypeRecord) @@ -364,14 +364,21 @@ func (g *Game) UpdateGame(ctx context.Context, gameID values.GameID, name values } // 変更がなければ何もしない - if game.GetName() == name && game.GetDescription() == description { + if game.GetName() == name && + game.GetDescription() == description && + (visibility == nil || game.GetVisibility() == *visibility) { //visibilityがnilの場合はvisibilityの変更がないとみなす + newGame = game return nil } - game.SetName(name) - game.SetDescription(description) + newVisibility := game.GetVisibility() + if visibility != nil { + newVisibility = *visibility + } + + newGame = domain.NewGame(game.GetID(), name, description, newVisibility, game.GetCreatedAt()) - err = g.gameRepository.UpdateGame(ctx, game) + err = g.gameRepository.UpdateGame(ctx, newGame) if err != nil { return fmt.Errorf("failed to save game: %w", err) } @@ -382,7 +389,7 @@ func (g *Game) UpdateGame(ctx context.Context, gameID values.GameID, name values return nil, fmt.Errorf("failed in transaction: %w", err) } - return game, nil + return newGame, nil } func (g *Game) DeleteGame(ctx context.Context, gameID values.GameID) error { //V1と変わらない diff --git a/src/service/v2/game_test.go b/src/service/v2/game_test.go index 68be980b2..250cf90b0 100644 --- a/src/service/v2/game_test.go +++ b/src/service/v2/game_test.go @@ -1758,8 +1758,10 @@ func TestUpdateGame(t *testing.T) { gameID values.GameID name values.GameName gameDescription values.GameDescription - game *domain.Game + visibility *values.GameVisibility + currentGame *domain.Game GetGameErr error + newGame *domain.Game executeUpdateGame bool UpdateGameErr error isErr bool @@ -1767,6 +1769,13 @@ func TestUpdateGame(t *testing.T) { } gameID := values.NewGameID() + var ( + visibilityPublic = values.GameVisibilityTypePublic + visibilityLimited = values.GameVisibilityTypeLimited + // visibilityPrivate = values.GameVisibilityTypePrivate + ) + + now := time.Now() testCases := []test{ { @@ -1774,12 +1783,20 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("after"), gameDescription: values.GameDescription("after"), - game: domain.NewGame( + visibility: &visibilityPublic, + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("after"), + values.GameVisibilityTypePublic, + now, ), executeUpdateGame: true, }, @@ -1788,12 +1805,20 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("before"), gameDescription: values.GameDescription("after"), - game: domain.NewGame( + visibility: &visibilityPublic, + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("before"), + values.GameDescription("after"), + values.GameVisibilityTypePublic, + now, ), executeUpdateGame: true, }, @@ -1802,12 +1827,64 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("after"), gameDescription: values.GameDescription("before"), - game: domain.NewGame( + visibility: &visibilityPublic, + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("before"), + values.GameVisibilityTypePublic, + now, + ), + executeUpdateGame: true, + }, + { + description: "visibilityの変更なしでもエラーなし", + gameID: gameID, + name: values.GameName("after"), + gameDescription: values.GameDescription("before"), + visibility: &visibilityLimited, + currentGame: domain.NewGame( + gameID, + values.GameName("before"), + values.GameDescription("before"), + values.GameVisibilityTypeLimited, + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("before"), + values.GameVisibilityTypeLimited, + now, + ), + executeUpdateGame: true, + }, + { + description: "visibilityの変更なし(nil)でもエラーなし", + gameID: gameID, + name: values.GameName("after"), + gameDescription: values.GameDescription("before"), + visibility: nil, + currentGame: domain.NewGame( + gameID, + values.GameName("before"), + values.GameDescription("before"), + values.GameVisibilityTypeLimited, + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("before"), + values.GameVisibilityTypeLimited, + now, ), executeUpdateGame: true, }, @@ -1816,12 +1893,19 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("before"), gameDescription: values.GameDescription("before"), - game: domain.NewGame( + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("before"), + values.GameDescription("before"), + values.GameVisibilityTypeLimited, + now, ), }, { @@ -1846,12 +1930,19 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("after"), gameDescription: values.GameDescription("after"), - game: domain.NewGame( + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("after"), + values.GameVisibilityTypeLimited, + now, ), executeUpdateGame: true, UpdateGameErr: repository.ErrNoRecordUpdated, @@ -1862,12 +1953,19 @@ func TestUpdateGame(t *testing.T) { gameID: gameID, name: values.GameName("after"), gameDescription: values.GameDescription("after"), - game: domain.NewGame( + currentGame: domain.NewGame( gameID, values.GameName("before"), values.GameDescription("before"), values.GameVisibilityTypeLimited, - time.Now(), + now, + ), + newGame: domain.NewGame( + gameID, + values.GameName("after"), + values.GameDescription("after"), + values.GameVisibilityTypeLimited, + now, ), executeUpdateGame: true, UpdateGameErr: errors.New("error"), @@ -1880,16 +1978,16 @@ func TestUpdateGame(t *testing.T) { mockGameRepository. EXPECT(). GetGame(gomock.Any(), testCase.gameID, repository.LockTypeRecord). - Return(testCase.game, testCase.GetGameErr) + Return(testCase.currentGame, testCase.GetGameErr) if testCase.executeUpdateGame { mockGameRepository. EXPECT(). - UpdateGame(gomock.Any(), testCase.game). + UpdateGame(gomock.Any(), testCase.newGame). Return(testCase.UpdateGameErr) } - game, err := gameVersionService.UpdateGame(ctx, testCase.gameID, testCase.name, testCase.gameDescription) + game, err := gameVersionService.UpdateGame(ctx, testCase.gameID, testCase.name, testCase.gameDescription, testCase.visibility) if testCase.isErr { if testCase.err == nil { @@ -1904,12 +2002,11 @@ func TestUpdateGame(t *testing.T) { return } - assert.Equal(t, testCase.game, game) - - assert.Equal(t, testCase.game.GetID(), game.GetID()) - assert.Equal(t, testCase.name, game.GetName()) - assert.Equal(t, testCase.gameDescription, game.GetDescription()) - assert.Equal(t, testCase.game.GetCreatedAt(), game.GetCreatedAt()) + assert.Equal(t, testCase.newGame.GetID(), game.GetID()) + assert.Equal(t, testCase.newGame.GetName(), game.GetName()) + assert.Equal(t, testCase.newGame.GetDescription(), game.GetDescription()) + assert.Equal(t, testCase.newGame.GetVisibility(), game.GetVisibility()) + assert.WithinDuration(t, testCase.newGame.GetCreatedAt(), game.GetCreatedAt(), time.Second) }) } } diff --git a/src/service/v2_game.go b/src/service/v2_game.go index 26a7de97a..c013e6178 100644 --- a/src/service/v2_game.go +++ b/src/service/v2_game.go @@ -50,7 +50,8 @@ type GameV2 interface { // UpdateGame // ゲームのidを指定して情報(名前、説明)を修正する。 // idが一致するゲームが存在しなかった場合、ErrNoGameを返す。 - UpdateGame(ctx context.Context, gameID values.GameID, name values.GameName, description values.GameDescription) (*domain.Game, error) + // visibilityが変わらないときはnilを指定する。 + UpdateGame(ctx context.Context, gameID values.GameID, name values.GameName, description values.GameDescription, visibility *values.GameVisibility) (*domain.Game, error) // DeleteGame // ゲームのidを指定してゲームを削除する。