From 4063ddc8e5f429ebcfeda62f288b1c455ad3a446 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 13:10:28 +0200 Subject: [PATCH 1/9] Project setup is ok --- task-1/.gitattributes | 2 + task-1/.gitignore | 33 ++ task-1/.gitkeep | 0 task-1/.mvn/wrapper/maven-wrapper.properties | 3 + task-1/mvnw | 306 ++++++++++++++++++ task-1/mvnw.cmd | 202 ++++++++++++ task-1/pom.xml | 117 +++++++ .../analyticsapi/week4/Week4Application.java | 13 + task-1/src/main/resources/application.yaml | 3 + .../week4/Week4ApplicationTests.java | 13 + 10 files changed, 692 insertions(+) create mode 100644 task-1/.gitattributes create mode 100644 task-1/.gitignore delete mode 100644 task-1/.gitkeep create mode 100644 task-1/.mvn/wrapper/maven-wrapper.properties create mode 100644 task-1/mvnw create mode 100644 task-1/mvnw.cmd create mode 100644 task-1/pom.xml create mode 100644 task-1/src/main/java/com/analyticsapi/week4/Week4Application.java create mode 100644 task-1/src/main/resources/application.yaml create mode 100644 task-1/src/test/java/com/analyticsapi/week4/Week4ApplicationTests.java diff --git a/task-1/.gitattributes b/task-1/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/task-1/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/task-1/.gitignore b/task-1/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/task-1/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/task-1/.gitkeep b/task-1/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/task-1/.mvn/wrapper/maven-wrapper.properties b/task-1/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..216df05 --- /dev/null +++ b/task-1/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip diff --git a/task-1/mvnw b/task-1/mvnw new file mode 100644 index 0000000..3443c40 --- /dev/null +++ b/task-1/mvnw @@ -0,0 +1,306 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# Prefer JDK 25 for this project when running on Windows shells. +case "$(uname)" in +CYGWIN* | MINGW*) + if [ -z "${JAVA_HOME-}" ] || ! printf %s "$JAVA_HOME" | tr '[:upper:]' '[:lower:]' | grep -q 'jdk-25'; then + if [ -d "/c/Program Files/Java/jdk-25.0.3" ]; then + JAVA_HOME="/c/Program Files/Java/jdk-25.0.3" + fi + fi + ;; +esac + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/task-1/mvnw.cmd b/task-1/mvnw.cmd new file mode 100644 index 0000000..f2d4f25 --- /dev/null +++ b/task-1/mvnw.cmd @@ -0,0 +1,202 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# Prefer JDK 25 for this project unless JAVA_HOME already points to JDK 25. +$preferredJavaHome = $env:MVNW_JAVA_HOME +if (-not $preferredJavaHome) { + $preferredJavaHome = "C:\Program Files\Java\jdk-25.0.3" +} + +if ((-not $env:JAVA_HOME) -or ($env:JAVA_HOME -notmatch '(?i)\\jdk-25')) { + if (Test-Path -Path $preferredJavaHome) { + $env:JAVA_HOME = $preferredJavaHome + $env:Path = "$env:JAVA_HOME\bin;$env:Path" + } +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/task-1/pom.xml b/task-1/pom.xml new file mode 100644 index 0000000..5928efe --- /dev/null +++ b/task-1/pom.xml @@ -0,0 +1,117 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 4.0.6 + + + com.analyticsapi + week4 + 0.0.1-SNAPSHOT + + + + + + + + + + + + + + + + + 25 + + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-webmvc + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 3.0.2 + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-validation-test + test + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + compile + + compile + + + + + org.projectlombok + lombok + + + + + + default-testCompile + test-compile + + testCompile + + + + + org.projectlombok + lombok + + + + + + + + + + diff --git a/task-1/src/main/java/com/analyticsapi/week4/Week4Application.java b/task-1/src/main/java/com/analyticsapi/week4/Week4Application.java new file mode 100644 index 0000000..57cb0c7 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/Week4Application.java @@ -0,0 +1,13 @@ +package com.analyticsapi.week4; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Week4Application { + + public static void main(String[] args) { + SpringApplication.run(Week4Application.class, args); + } + +} diff --git a/task-1/src/main/resources/application.yaml b/task-1/src/main/resources/application.yaml new file mode 100644 index 0000000..644e3fa --- /dev/null +++ b/task-1/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +spring: + application: + name: week4 diff --git a/task-1/src/test/java/com/analyticsapi/week4/Week4ApplicationTests.java b/task-1/src/test/java/com/analyticsapi/week4/Week4ApplicationTests.java new file mode 100644 index 0000000..2c4de13 --- /dev/null +++ b/task-1/src/test/java/com/analyticsapi/week4/Week4ApplicationTests.java @@ -0,0 +1,13 @@ +package com.analyticsapi.week4; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Week4ApplicationTests { + + @Test + void contextLoads() { + } + +} From 5267fb85d5edb3ca6d0302e77bcb1268c9f008ca Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 17:34:31 +0200 Subject: [PATCH 2/9] AnalyticsRecord model; add empty class stubs for remaining layers --- .../week4/controller/AnalyticsController.java | 4 ++++ .../controller/GlobalExceptionHandler.java | 4 ++++ .../dto/AnalyticsRecordCreateRequest.java | 4 ++++ .../dto/AnalyticsRecordReplaceRequest.java | 4 ++++ .../week4/dto/AnalyticsSummary.java | 4 ++++ .../analyticsapi/week4/dto/ErrorResponse.java | 4 ++++ .../exception/RecordNotFoundException.java | 4 ++++ .../week4/model/AnalyticsRecord.java | 20 +++++++++++++++++++ .../week4/repository/AnalyticsRepository.java | 4 ++++ .../week4/service/AnalyticsService.java | 4 ++++ 10 files changed, 56 insertions(+) create mode 100644 task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/model/AnalyticsRecord.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java create mode 100644 task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java new file mode 100644 index 0000000..a159364 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.controller; + +public class AnalyticsController { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java b/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java new file mode 100644 index 0000000..494621c --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.controller; + +public class GlobalExceptionHandler { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java new file mode 100644 index 0000000..4b261bb --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.dto; + +public class AnalyticsRecordCreateRequest { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java new file mode 100644 index 0000000..7b895fd --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.dto; + +public class AnalyticsRecordReplaceRequest { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java new file mode 100644 index 0000000..03b9993 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.dto; + +public class AnalyticsSummary { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java b/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java new file mode 100644 index 0000000..bef7133 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.dto; + +public class ErrorResponse { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java b/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java new file mode 100644 index 0000000..9f6c0a6 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.exception; + +public class RecordNotFoundException { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/model/AnalyticsRecord.java b/task-1/src/main/java/com/analyticsapi/week4/model/AnalyticsRecord.java new file mode 100644 index 0000000..36cffc3 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/model/AnalyticsRecord.java @@ -0,0 +1,20 @@ +package com.analyticsapi.week4.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.Instant; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AnalyticsRecord { + private String id; + private Instant timestamp; + private String eventType; + private String eventSource; + private String sessionId; +} diff --git a/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java b/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java new file mode 100644 index 0000000..ab01293 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.repository; + +public class AnalyticsRepository { +} \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java new file mode 100644 index 0000000..4adcf67 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -0,0 +1,4 @@ +package com.analyticsapi.week4.service; + +public class AnalyticsService { +} \ No newline at end of file From b9571f10b2b26652ca38af8e1c14d0fb1fe90eda Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 18:55:36 +0200 Subject: [PATCH 3/9] dto and exception are compiled well --- .../dto/AnalyticsRecordCreateRequest.java | 23 ++++++++++++++ .../dto/AnalyticsRecordReplaceRequest.java | 24 ++++++++++++++ .../week4/dto/AnalyticsSummary.java | 11 +++++++ .../analyticsapi/week4/dto/ErrorResponse.java | 23 +++++++++++++- .../exception/RecordNotFoundException.java | 6 +++- .../week4/repository/AnalyticsRepository.java | 31 +++++++++++++++++++ 6 files changed, 116 insertions(+), 2 deletions(-) diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java index 4b261bb..f402d25 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordCreateRequest.java @@ -1,4 +1,27 @@ package com.analyticsapi.week4.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.time.Instant; + +@Data public class AnalyticsRecordCreateRequest { + + @NotNull + private Instant timestamp; + + @NotBlank + @Size(min =1, max = 64) + private String eventType; + + @NotBlank + @Size(min =1, max = 64) + private String eventSource; + + @NotBlank + @Size(min =1, max = 64) + private String sessionId; } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java index 7b895fd..28926a9 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsRecordReplaceRequest.java @@ -1,4 +1,28 @@ package com.analyticsapi.week4.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.time.Instant; + +@Data public class AnalyticsRecordReplaceRequest { + + @NotNull + private Instant timestamp; + + @NotBlank + @Size(min =1, max = 64) + private String eventType; + + @NotBlank + @Size(min =1, max = 64) + private String eventSource; + + @NotBlank + @Size(min =1, max = 64) + private String sessionId; + } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java index 03b9993..5766444 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java @@ -1,4 +1,15 @@ package com.analyticsapi.week4.dto; +import lombok.Builder; +import lombok.Data; + +import java.util.Map; + +@Data +@Builder public class AnalyticsSummary { + + private long totalRecords; + private Map recordsByCategory; + private long uniqueSessions; } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java b/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java index bef7133..6e1191e 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/ErrorResponse.java @@ -1,4 +1,25 @@ package com.analyticsapi.week4.dto; +import lombok.Builder; +import lombok.Data; + +import java.time.Instant; +import java.util.List; + +@Data +@Builder public class ErrorResponse { -} \ No newline at end of file + private Instant timestamp; + private int status; + private String error; + private String message; + private String path; + private List details; + + @Data + @Builder + public static class FieldError { + private String field; + private String message; + } +} diff --git a/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java b/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java index 9f6c0a6..27e1db4 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java +++ b/task-1/src/main/java/com/analyticsapi/week4/exception/RecordNotFoundException.java @@ -1,4 +1,8 @@ package com.analyticsapi.week4.exception; -public class RecordNotFoundException { +public class RecordNotFoundException extends RuntimeException { + + public RecordNotFoundException(String id){ + super("Record not found: " + id); + } } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java b/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java index ab01293..2b21753 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java +++ b/task-1/src/main/java/com/analyticsapi/week4/repository/AnalyticsRepository.java @@ -1,4 +1,35 @@ package com.analyticsapi.week4.repository; +import com.analyticsapi.week4.model.AnalyticsRecord; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Repository public class AnalyticsRepository { + + private final List store = new ArrayList<>(); + + public AnalyticsRecord save(AnalyticsRecord record) { + store.removeIf(r -> r.getId().equals(record.getId())); + store.add(record); + return record; + } + + public List findAll(){ + return new ArrayList<>(store); + } + + public Optional findById(String id) { + return store.stream() + .filter(r -> r.getId().equals(id)) + .findFirst(); + } + + public boolean deleteById(String id){ + return store.removeIf(r -> r.getId().equals(id)); + } + } \ No newline at end of file From 5ddf923c7ac50b9bde741502b833d234e3c3b917 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 19:11:10 +0200 Subject: [PATCH 4/9] sercice is the business logic layer, it receives plain ava objects, applies the rules of the application. returns plain java objects --- .../week4/service/AnalyticsService.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java index 4adcf67..15fc244 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -1,4 +1,35 @@ package com.analyticsapi.week4.service; +import java.util.UUID; + +import com.analyticsapi.week4.dto.AnalyticsRecordCreateRequest; +import com.analyticsapi.week4.exception.RecordNotFoundException; +import com.analyticsapi.week4.model.AnalyticsRecord; +import com.analyticsapi.week4.repository.AnalyticsRepository; +import org.springframework.stereotype.Service; + +@Service public class AnalyticsService { + + private final AnalyticsRepository repository; + + public AnalyticsService(AnalyticsRepository repository){ + this.repository = repository; + } + + public AnalyticsRecord create (AnalyticsRecordCreateRequest request){ + AnalyticsRecord record = AnalyticsRecord.builder() + .id(UUID.randomUUID().toString()) + .timestamp(request.getTimestamp()) + .eventType(request.getEventType()) + .eventSource(request.getEventSource()) + .sessionId(request.getSessionId()) + .build(); + return repository.save(record); + } + + public AnalyticsRecord getById(String id){ + return repository.findById(id) + .orElseThrow(() -> new RecordNotFoundException(id)); + } } \ No newline at end of file From a807f2a796e94f7d90c555973b4e935e8cc5d349 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 19:37:00 +0200 Subject: [PATCH 5/9] api layer works well with create, retrieve records --- .../week4/controller/AnalyticsController.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java index a159364..b320d62 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -1,4 +1,37 @@ package com.analyticsapi.week4.controller; +import com.analyticsapi.week4.dto.AnalyticsRecordCreateRequest; +import com.analyticsapi.week4.model.AnalyticsRecord; +import com.analyticsapi.week4.service.AnalyticsService; +import jakarta.validation.Valid; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.net.URI; + + +@RestController +@RequestMapping("/api/analytics-records") public class AnalyticsController { + + private final AnalyticsService service; + + public AnalyticsController(AnalyticsService service) { + this.service = service; + } + + @PostMapping + public ResponseEntity create( + @RequestBody @Valid AnalyticsRecordCreateRequest record) { + AnalyticsRecord created = service.create(record); + URI location = URI.create("/api/analytics-records/" + created.getId()); + return ResponseEntity.created(location).body(created); + } + + @GetMapping("/{id}") + public ResponseEntity getById(@PathVariable String id) { + AnalyticsRecord record = service.getById(id); + return ResponseEntity.ok(record); + } } \ No newline at end of file From 1dd6de3847576158b749e03894f6f3ebbfeb0a76 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 20:23:56 +0200 Subject: [PATCH 6/9] filter, pagination limit, sorting by timestamp are added --- .../week4/controller/AnalyticsController.java | 16 +++++++++++ .../week4/service/AnalyticsService.java | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java index b320d62..2f9f3f0 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.*; import java.net.URI; +import java.time.Instant; +import java.util.List; @RestController @@ -34,4 +36,18 @@ public ResponseEntity getById(@PathVariable String id) { AnalyticsRecord record = service.getById(id); return ResponseEntity.ok(record); } + + @GetMapping + public ResponseEntity> list( + @RequestParam(required = false) Instant from, + @RequestParam(required = false) Instant to, + @RequestParam(required = false) String eventType, + @RequestParam(required = false) String eventSource, + @RequestParam(required = false) String sessionId, + @RequestParam(defaultValue = "100") int limit, + @RequestParam(defaultValue = "0") int offset + ){ + List records = service.list(from, to, eventType, eventSource, sessionId, limit, offset); + return ResponseEntity.ok(records); + } } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java index 15fc244..992184d 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -8,6 +8,12 @@ import com.analyticsapi.week4.repository.AnalyticsRepository; import org.springframework.stereotype.Service; +import java.time.Instant; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + + @Service public class AnalyticsService { @@ -32,4 +38,26 @@ public AnalyticsRecord getById(String id){ return repository.findById(id) .orElseThrow(() -> new RecordNotFoundException(id)); } + + public List list( + Instant from, + Instant to, + String eventType, + String eventSource, + String sessionId, + int limit, + int offset){ + + return repository.findAll().stream() + .filter(r -> from == null || !r.getTimestamp().isBefore(from)) + .filter(r -> to == null || !r.getTimestamp().isAfter(to)) + .filter(r -> eventType == null || r.getEventType().equals(eventType)) + .filter(r -> eventSource == null || r.getEventSource().equals(eventSource)) + .filter(r -> sessionId == null || r.getSessionId().equals(sessionId)) + .sorted(Comparator.comparing(AnalyticsRecord::getTimestamp).reversed()) + .skip(offset) + .limit(limit) + .collect(Collectors.toList()); + } + } \ No newline at end of file From 0cd6c867f6959da308c3505b49b28c1ffa0ae0f5 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 21:02:46 +0200 Subject: [PATCH 7/9] delete and replace are added --- .../week4/controller/AnalyticsController.java | 15 +++++++++ .../week4/service/AnalyticsService.java | 31 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java index 2f9f3f0..64b18a6 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -3,6 +3,7 @@ import com.analyticsapi.week4.dto.AnalyticsRecordCreateRequest; import com.analyticsapi.week4.model.AnalyticsRecord; import com.analyticsapi.week4.service.AnalyticsService; +import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -50,4 +51,18 @@ public ResponseEntity> list( List records = service.list(from, to, eventType, eventSource, sessionId, limit, offset); return ResponseEntity.ok(records); } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable String id){ + service.delete(id); + return ResponseEntity.noContent().build(); + } + + @PutMapping("/{id}") + public ResponseEntity replace ( + @PathVariable String id, + @Valid @RequestBody AnalyticsRecordReplaceRequest request){ + AnalyticsRecord record = service.replace(id, request); + return ResponseEntity.ok(record); + } } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java index 992184d..73343a6 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -3,9 +3,11 @@ import java.util.UUID; import com.analyticsapi.week4.dto.AnalyticsRecordCreateRequest; +import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; import com.analyticsapi.week4.exception.RecordNotFoundException; import com.analyticsapi.week4.model.AnalyticsRecord; import com.analyticsapi.week4.repository.AnalyticsRepository; +import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; import org.springframework.stereotype.Service; import java.time.Instant; @@ -14,6 +16,7 @@ import java.util.stream.Collectors; + @Service public class AnalyticsService { @@ -59,5 +62,29 @@ public List list( .limit(limit) .collect(Collectors.toList()); } - -} \ No newline at end of file + + public void delete(String id){ + boolean removed = repository.deleteById(id); + if(!removed){ + throw new RecordNotFoundException(id); + } + } + + public AnalyticsRecord replace(String id, AnalyticsRecordReplaceRequest request){ + repository.findById(id) + .orElseThrow(() -> new RecordNotFoundException(id)); + + AnalyticsRecord updated = AnalyticsRecord.builder() + .id(id) + .timestamp(request.getTimestamp()) + .eventType(request.getEventType()) + .eventSource(request.getEventSource()) + .sessionId(request.getSessionId()) + .build(); + + return repository.save(updated); + } + + +} + \ No newline at end of file From 9adb54147515244944e8cf5b0a45f15e94ca2a94 Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 22:02:39 +0200 Subject: [PATCH 8/9] added summary endpoint --- .../week4/controller/AnalyticsController.java | 14 +++++++++ .../week4/service/AnalyticsService.java | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java index 64b18a6..04142bf 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -4,6 +4,7 @@ import com.analyticsapi.week4.model.AnalyticsRecord; import com.analyticsapi.week4.service.AnalyticsService; import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; +import com.analyticsapi.week4.dto.AnalyticsSummary; import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -52,6 +53,19 @@ public ResponseEntity> list( return ResponseEntity.ok(records); } + @GetMapping("/api/analytics-summary") + public ResponseEntity getSummary( + @RequestParam(required = false) Instant from, + @RequestParam(required = false) Instant to, + @RequestParam(required = false) String eventType, + @RequestParam(required = false) String eventSource, + @RequestParam(required = false) String sessionId + ){ + AnalyticsSummary summary = service.getSummary(from, to, eventType, eventSource, sessionId); + return ResponseEntity.ok(summary); + } + + @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable String id){ service.delete(id); diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java index 73343a6..eeddc05 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -9,6 +9,8 @@ import com.analyticsapi.week4.repository.AnalyticsRepository; import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; import org.springframework.stereotype.Service; +import com.analyticsapi.week4.dto.AnalyticsSummary; +import java.util.Map; import java.time.Instant; import java.util.Comparator; @@ -85,6 +87,33 @@ public AnalyticsRecord replace(String id, AnalyticsRecordReplaceRequest request) return repository.save(updated); } + public AnalyticsSummary getSummary( + Instant from, + Instant to, + String eventType, + String eventSource, + String sessionId){ + + List filtered = list(from, to, eventType, eventSource, sessionId, Integer.MAX_VALUE, 0); + + Map totalsByEventType = filtered.stream() + .collect(Collectors.groupingBy( + AnalyticsRecord::getEventType, + Collectors.counting() + )); + + long uniqueSessions = filtered.stream() + .map(AnalyticsRecord::getSessionId) + .distinct() + .count(); + + return AnalyticsSummary.builder() + .totalRecords(filtered.size()) + .recordsByCategory(totalsByEventType) + .uniqueSessions(uniqueSessions) + .build(); + } + } \ No newline at end of file From d524bafb6aa61c088d745e2c79e99b5121210d6d Mon Sep 17 00:00:00 2001 From: Yusuprozimemet Date: Thu, 28 May 2026 23:02:59 +0200 Subject: [PATCH 9/9] add analytics summary endpoint and API design documentation --- task-1/API_DESIGN.md | 311 ++++++++++++++++++ .../week4/controller/AnalyticsController.java | 14 - .../AnalyticsSummaryController.java | 31 ++ .../controller/GlobalExceptionHandler.java | 65 ++++ .../week4/dto/AnalyticsSummary.java | 2 +- .../week4/service/AnalyticsService.java | 2 +- 6 files changed, 409 insertions(+), 16 deletions(-) create mode 100644 task-1/API_DESIGN.md create mode 100644 task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsSummaryController.java diff --git a/task-1/API_DESIGN.md b/task-1/API_DESIGN.md new file mode 100644 index 0000000..33d8791 --- /dev/null +++ b/task-1/API_DESIGN.md @@ -0,0 +1,311 @@ +# API Design - Analytics API + +## Base URL + +`/api` + +## Endpoint overview + +```mermaid +graph TD + Client([Client]) + + subgraph Records ["Resource: /api/analytics-records"] + POST["POST /api/analytics-records + Body: timestamp, eventType, eventSource, sessionId + 201 Created, 400 Bad Request"] + + GET_LIST["GET /api/analytics-records + Filters: from, to, eventType, eventSource, sessionId + Pagination: limit, offset + 200 OK"] + + subgraph ByID ["By ID: /api/analytics-records/{id}"] + GET_ONE["GET /{id} + 200 OK, 404 Not Found"] + + PUT["PUT /{id} + Body: timestamp, eventType, eventSource, sessionId + 200 OK, 404 Not Found, 400 Bad Request"] + + DEL["DELETE /{id} + 204 No Content, 404 Not Found"] + end + end + + subgraph Summary ["Resource: /api/analytics-summary"] + GET_SUM["GET /api/analytics-summary + Filters: from, to, eventType, eventSource, sessionId + 200 OK: totalRecords, totalsByEventType, uniqueSessions"] + end + + Client -->|create| POST + Client -->|list + filter| GET_LIST + Client -->|fetch one| GET_ONE + Client -->|replace one| PUT + Client -->|delete one| DEL + Client -->|get summary| GET_SUM +``` + +## Resource: analytics records + +### Data model + +AnalyticsRecord + +``` +{ + "id": "uuid", + "timestamp": "2026-05-28T12:34:56Z", + "eventType": "page_view", + "eventSource": "web", + "sessionId": "anon-123" +} +``` + +Notes: +- `id` is server-generated and acts as the trace ID. +- `timestamp` uses ISO-8601 in UTC (e.g., `2026-05-28T12:34:56Z`). +- `sessionId` must be anonymized. No personal data is allowed. + +```mermaid +classDiagram + class AnalyticsRecord { + +String id + +Instant timestamp + +String eventType + +String eventSource + +String sessionId + } + + class AnalyticsRecordCreateRequest { + +Instant timestamp + +String eventType + +String eventSource + +String sessionId + } + + class AnalyticsRecordReplaceRequest { + +Instant timestamp + +String eventType + +String eventSource + +String sessionId + } + + class AnalyticsSummary { + +long totalRecords + +Map~String, Long~ totalsByEventType + +long uniqueSessions + } + + class ErrorResponse { + +Instant timestamp + +int status + +String error + +String message + +String path + +List~FieldError~ details + } + + AnalyticsRecordCreateRequest ..> AnalyticsRecord : server adds id + AnalyticsRecordReplaceRequest ..> AnalyticsRecord : server keeps id +``` + +## Endpoints + +### Create record + +`POST /api/analytics-records` + +Request body (AnalyticsRecordCreateRequest) + +``` +{ + "timestamp": "2026-05-28T12:34:56Z", + "eventType": "page_view", + "eventSource": "web", + "sessionId": "anon-123" +} +``` + +Validation rules +- `timestamp`: required, valid ISO-8601. +- `eventType`: required, non-blank, length 1-64. +- `eventSource`: required, non-blank, length 1-64. +- `sessionId`: required, non-blank, length 1-64. + +Response +- `201 Created` with the created record. +- `Location` header points to `/api/analytics-records/{id}`. + +```mermaid +sequenceDiagram + participant Client + participant API as API Layer (Controller) + participant Service as Business Logic (Service) + participant DB as Database Layer (Repository) + + Client->>API: POST /api/analytics-records
{ timestamp, eventType, eventSource, sessionId } + API->>API: deserialize JSON into AnalyticsRecordCreateRequest DTO + API->>API: validate fields (not blank, length 1-64, ISO-8601) + API-->>Client: 400 Bad Request + error details (if validation fails) + API->>Service: create(request) + Service->>Service: generate UUID as trace ID + Service->>Service: build AnalyticsRecord model + Service->>DB: save(record) + DB-->>Service: saved AnalyticsRecord + Service-->>API: AnalyticsRecord + API->>API: set Location header to /api/analytics-records/{id} + API-->>Client: 201 Created + { id, timestamp, eventType, eventSource, sessionId } +``` + +### List records (with filters) + +`GET /api/analytics-records` + +Query parameters (all optional) +- `from`: ISO-8601 start time, inclusive. +- `to`: ISO-8601 end time, inclusive. +- `eventType`: filter by event type. +- `eventSource`: filter by event source. +- `sessionId`: filter by anonymized session ID. +- `limit`: default 100. +- `offset`: default 0. + +Behavior +- Filters are combined with AND. +- If only `from` is provided, return records on or after `from`. +- If only `to` is provided, return records on or before `to`. +- If both are provided and `from` is after `to`, an empty list is returned. +- Results are sorted by `timestamp` descending. + +Response +- `200 OK` with a JSON array of records. + +### Get record by ID + +`GET /api/analytics-records/{id}` + +Response +- `200 OK` with the record. +- `404 Not Found` if the ID does not exist. + +### Replace record by ID + +`PUT /api/analytics-records/{id}` + +Request body (AnalyticsRecordReplaceRequest) + +``` +{ + "timestamp": "2026-05-28T12:34:56Z", + "eventType": "page_view", + "eventSource": "web", + "sessionId": "anon-123" +} +``` + +Validation rules +- Same as create. +- Full replace: all fields are required. + +Response +- `200 OK` with the updated record. +- `404 Not Found` if the ID does not exist. + +### Delete record by ID + +`DELETE /api/analytics-records/{id}` + +Response +- `204 No Content` if deleted. +- `404 Not Found` if the ID does not exist. + +### Summary + +`GET /api/analytics-summary` + +Query parameters (optional, same as list) +- `from`, `to`, `eventType`, `eventSource`, `sessionId` + +Response body + +``` +{ + "totalRecords": 123, + "totalsByEventType": { + "page_view": 100, + "signup": 23 + }, + "uniqueSessions": 17 +} +``` + +Response +- `200 OK` with the summary of records that match the filters. + +## Error responses + +All error responses use the following shape: + +``` +{ + "timestamp": "2026-05-28T12:34:56Z", + "status": 400, + "error": "Bad Request", + "message": "Validation failed", + "path": "/api/analytics-records", + "details": [ + { "field": "eventType", "message": "must not be blank" } + ] +} +``` + +Common errors +- `400 Bad Request` for validation failures (missing or blank required fields, invalid JSON). +- `404 Not Found` when a record ID does not exist. + +## Architecture + +```mermaid +graph LR + Client([Client]) + + subgraph "API Layer" + C1["AnalyticsController"] + C2["AnalyticsSummaryController"] + C3["GlobalExceptionHandler"] + end + + subgraph "Business Logic Layer" + S1["AnalyticsService"] + end + + subgraph "DTOs" + D1["AnalyticsRecordCreateRequest"] + D2["AnalyticsRecordReplaceRequest"] + D3["AnalyticsSummary"] + D4["ErrorResponse"] + end + + subgraph "Model" + M1["AnalyticsRecord"] + end + + subgraph "Database Layer" + R1["AnalyticsRepository
(in-memory List)"] + end + + Client -->|HTTP| C1 + Client -->|HTTP| C2 + C1 --> S1 + C2 --> S1 + S1 --> R1 + C1 -.->|uses| D1 + C1 -.->|uses| D2 + C1 -.->|uses| D4 + C2 -.->|uses| D3 + C3 -.->|produces| D4 + S1 -.->|uses| M1 + R1 -.->|stores| M1 +``` diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java index 04142bf..64b18a6 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsController.java @@ -4,7 +4,6 @@ import com.analyticsapi.week4.model.AnalyticsRecord; import com.analyticsapi.week4.service.AnalyticsService; import com.analyticsapi.week4.dto.AnalyticsRecordReplaceRequest; -import com.analyticsapi.week4.dto.AnalyticsSummary; import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -53,19 +52,6 @@ public ResponseEntity> list( return ResponseEntity.ok(records); } - @GetMapping("/api/analytics-summary") - public ResponseEntity getSummary( - @RequestParam(required = false) Instant from, - @RequestParam(required = false) Instant to, - @RequestParam(required = false) String eventType, - @RequestParam(required = false) String eventSource, - @RequestParam(required = false) String sessionId - ){ - AnalyticsSummary summary = service.getSummary(from, to, eventType, eventSource, sessionId); - return ResponseEntity.ok(summary); - } - - @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable String id){ service.delete(id); diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsSummaryController.java b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsSummaryController.java new file mode 100644 index 0000000..3e180d6 --- /dev/null +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/AnalyticsSummaryController.java @@ -0,0 +1,31 @@ +package com.analyticsapi.week4.controller; + +import com.analyticsapi.week4.dto.AnalyticsSummary; +import com.analyticsapi.week4.service.AnalyticsService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.time.Instant; + +@RestController +@RequestMapping("/api/analytics-summary") +public class AnalyticsSummaryController { + + private final AnalyticsService service; + + public AnalyticsSummaryController(AnalyticsService service) { + this.service = service; + } + + @GetMapping + public ResponseEntity getSummary( + @RequestParam(required = false) Instant from, + @RequestParam(required = false) Instant to, + @RequestParam(required = false) String eventType, + @RequestParam(required = false) String eventSource, + @RequestParam(required = false) String sessionId + ) { + AnalyticsSummary summary = service.getSummary(from, to, eventType, eventSource, sessionId); + return ResponseEntity.ok(summary); + } +} diff --git a/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java b/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java index 494621c..54ae696 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java +++ b/task-1/src/main/java/com/analyticsapi/week4/controller/GlobalExceptionHandler.java @@ -1,4 +1,69 @@ package com.analyticsapi.week4.controller; +import com.analyticsapi.week4.exception.RecordNotFoundException; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import com.analyticsapi.week4.dto.ErrorResponse; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.time.Instant; +import java.util.List; +import java.util.stream.Collectors; + +@RestControllerAdvice public class GlobalExceptionHandler { + @ExceptionHandler(RecordNotFoundException.class) + public ResponseEntity handleNotFount( + RecordNotFoundException ex, + HttpServletRequest request){ + ErrorResponse body = ErrorResponse.builder() + .timestamp(Instant.now()) + .status(404) + .error("Not Found") + .message(ex.getMessage()) + .path(request.getRequestURI()) + .details(List.of()) + .build(); + return ResponseEntity.status(404).body(body); + } + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleValidation( + MethodArgumentNotValidException ex, + HttpServletRequest request){ + List details = ex.getBindingResult() + .getFieldErrors() + .stream() + .map(fe -> ErrorResponse.FieldError.builder() + .field(fe.getField()) + .message(fe.getDefaultMessage()) + .build()) + .collect(Collectors.toList()); + ErrorResponse body = ErrorResponse.builder() + .timestamp(Instant.now()) + .status(400) + .error("Bad request") + .message("Validation failed") + .path(request.getRequestURI()) + .details(details) + .build(); + return ResponseEntity.badRequest().body(body); + } + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity handleBadRequest( + HttpMessageNotReadableException ex, + HttpServletRequest request){ + ErrorResponse body = ErrorResponse.builder() + .timestamp(Instant.now()) + .status(400) + .error("Bad request") + .message("Request body is missing or contains invalid JSON") + .path(request.getRequestURI()) + .details(List.of()) + .build(); + return ResponseEntity.badRequest().body(body); + } + } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java index 5766444..6389909 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java +++ b/task-1/src/main/java/com/analyticsapi/week4/dto/AnalyticsSummary.java @@ -10,6 +10,6 @@ public class AnalyticsSummary { private long totalRecords; - private Map recordsByCategory; + private Map totalsByEventType; private long uniqueSessions; } \ No newline at end of file diff --git a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java index eeddc05..30d496d 100644 --- a/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java +++ b/task-1/src/main/java/com/analyticsapi/week4/service/AnalyticsService.java @@ -109,7 +109,7 @@ public AnalyticsSummary getSummary( return AnalyticsSummary.builder() .totalRecords(filtered.size()) - .recordsByCategory(totalsByEventType) + .totalsByEventType(totalsByEventType) .uniqueSessions(uniqueSessions) .build(); }