diff --git a/.github/workflows/prod-build.yaml b/.github/workflows/prod-build.yaml new file mode 100644 index 0000000..3224459 --- /dev/null +++ b/.github/workflows/prod-build.yaml @@ -0,0 +1,78 @@ +name: Build for Prod +on: + push: + tags: + - v*.*.* + +env: + SERVICE_NAME: user + SERVICE_TYPE: be + +jobs: + build: + environment: prod + runs-on: ubuntu-latest + strategy: + matrix: + java-version: [ 17 ] + outputs: + version: ${{ steps.get_version.outputs.BRANCH_NAME }} + + steps: + - name: Check Out The Repository + uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java-version }} + distribution: 'zulu' + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3) + + - name: Gradle Build + uses: gradle/gradle-build-action@v2 + with: + arguments: | + build + --no-daemon + + - name: Log in to Docker Hub + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{secrets.DOCKER_USER}} + password: ${{secrets.DOCKER_HUB_TOKEN}} + + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + file: ./Dockerfile + push: true + tags: ${{secrets.DOCKER_USER}}/${{env.SERVICE_NAME}}-${{env.SERVICE_TYPE}}:${{ steps.get_version.outputs.VERSION }} + build-args: | + DBMS=${{secrets.DBMS_PROD}} + DB_HOST=${{secrets.DB_HOST_PROD}} + DB_PORT=${{secrets.DB_PORT_PROD}} + DB_NAME=${{secrets.DB_NAME_PROD}} + DB_PASSWORD=${{secrets.DB_PASSWORD_PROD}} + DB_USERNAME=${{secrets.DB_USERNAME_PROD}} + SHOW_SQL=${{secrets.SHOW_SQL_PROD}} + DDL_AUTO_MODE=${{secrets.DDL_AUTO_MODE_PROD}} + DB_POOL=${{secrets.DB_POOL_PROD}} + AUTHORITY_SERVICE_HOST=${{secrets.AUTHORITY_SERVICE_HOST}} + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.GITOPS_DEPLOY_PRODUCTION_TOKEN }} + repository: team-xquare/xquare-gitops-repo-production + event-type: update_image + client-payload: '{ + "ref": "${{ github.ref }}", + "version": "${{ steps.get_version.outputs.VERSION }}", + "service_name": "${{env.SERVICE_NAME}}", + "service_type": "${{env.SERVICE_TYPE}}" + }' diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/User.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/User.kt index b479fa0..5e12661 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/User.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/User.kt @@ -35,4 +35,8 @@ data class User( fun setUserStateToCreated(): User { return copy(state = UserState.CREATED) } + + fun setDeviceToken(deviceToken: String): User { + return copy(deviceToken = deviceToken) + } } diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/dtos/SignInDomainRequest.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/dtos/SignInDomainRequest.kt index ece0a79..3994fcc 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/dtos/SignInDomainRequest.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/dtos/SignInDomainRequest.kt @@ -2,5 +2,6 @@ package com.xquare.v1userservice.user.api.dtos data class SignInDomainRequest( val accountId: String, - val password: String + val password: String, + val deviceToken: String ) diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserSignInApiImpl.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserSignInApiImpl.kt index b680e2e..1777ac4 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserSignInApiImpl.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserSignInApiImpl.kt @@ -25,13 +25,15 @@ class UserSignInApiImpl( val user = userRepositorySpi.findByAccountIdAndStateWithCreated(signInDomainRequest.accountId) ?: throw UserNotFoundException(UserNotFoundException.USER_ID_NOT_FOUND) - checkPasswordMatches(user, signInDomainRequest.password) - val authorities = authorityListSpi.getAuthorities(user.id) + val deviceTokenModifiedUser = userRepositorySpi.applyChanges(user.setDeviceToken(signInDomainRequest.deviceToken)) + + checkPasswordMatches(deviceTokenModifiedUser, signInDomainRequest.password) + val authorities = authorityListSpi.getAuthorities(deviceTokenModifiedUser.id) val params = HashMap() .apply { put("authorities", authorities) - put("role", user.role) + put("role", deviceTokenModifiedUser.role) } val accessToken = jwtTokenGeneratorSpi.generateJwtToken(signInDomainRequest.accountId, TokenType.ACCESS_TOKEN, params) diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt index 9d2b61f..4d00efa 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt @@ -60,7 +60,8 @@ class UserHandler( private fun SignInRequest.toDomainRequest() = SignInDomainRequest( accountId = this.accountId, - password = this.password + password = this.password, + deviceToken = this.deviceToken ) suspend fun getUserByIdHandler(serverRequest: ServerRequest): ServerResponse { diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/dto/SignInRequest.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/dto/SignInRequest.kt index 16f433e..8f8d763 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/dto/SignInRequest.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/dto/SignInRequest.kt @@ -6,5 +6,7 @@ data class SignInRequest( @field:NotNull val accountId: String, @field:NotNull - val password: String + val password: String, + @field:NotNull + val deviceToken: String ) diff --git a/user-infrastructure/src/test/kotlin/com/xquare/v1userservice/user/router/UserRouterTest.kt b/user-infrastructure/src/test/kotlin/com/xquare/v1userservice/user/router/UserRouterTest.kt index e9edf97..ec3176f 100644 --- a/user-infrastructure/src/test/kotlin/com/xquare/v1userservice/user/router/UserRouterTest.kt +++ b/user-infrastructure/src/test/kotlin/com/xquare/v1userservice/user/router/UserRouterTest.kt @@ -98,7 +98,8 @@ internal class UserRouterTest( private fun buildUserSignInRequest() = SignInRequest( accountId = "test", - password = "test" + password = "test", + deviceToken = "test" ) private fun sendSignInRequestWithBody(signInRequest: SignInRequest) =