├── README.md ├── backend └── chat-service │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codreal │ │ │ └── chatservice │ │ │ ├── ChatServiceApplication.java │ │ │ ├── controller │ │ │ ├── ChatController.java │ │ │ └── UserController.java │ │ │ ├── exceptions │ │ │ ├── ChatAlreadyExistException.java │ │ │ ├── ChatNotFoundException.java │ │ │ ├── NoChatExistsInTheRepository.java │ │ │ ├── UserAlreadyExistException.java │ │ │ └── UserNotFoundException.java │ │ │ ├── model │ │ │ ├── Chat.java │ │ │ ├── DatabaseSequence.java │ │ │ ├── Message.java │ │ │ └── User.java │ │ │ ├── repository │ │ │ ├── ChatRepository.java │ │ │ └── UserRepository.java │ │ │ └── services │ │ │ ├── ChatService.java │ │ │ ├── ChatServiceImpl.java │ │ │ ├── SequenceGeneratorService.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── codreal │ └── chatservice │ └── ChatServiceApplicationTests.java └── frontend └── app ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── README.md ├── angular.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── chat │ │ ├── chat.component.css │ │ ├── chat.component.html │ │ ├── chat.component.spec.ts │ │ └── chat.component.ts │ ├── main │ │ ├── main.component.css │ │ ├── main.component.html │ │ ├── main.component.spec.ts │ │ └── main.component.ts │ ├── models │ │ ├── chat.spec.ts │ │ ├── chat.ts │ │ ├── message.spec.ts │ │ ├── message.ts │ │ ├── user.spec.ts │ │ └── user.ts │ ├── services │ │ ├── chat.service.spec.ts │ │ ├── chat.service.ts │ │ ├── user.service.spec.ts │ │ └── user.service.ts │ └── user │ │ ├── user.component.css │ │ ├── user.component.html │ │ ├── user.component.spec.ts │ │ └── user.component.ts ├── assets │ ├── .gitkeep │ └── bootstrap.min.css ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css └── test.ts ├── tsconfig.app.json ├── tsconfig.json └── tsconfig.spec.json /README.md: -------------------------------------------------------------------------------- 1 | # chat-application 2 | Full frontend and backend ( Angular , Spring Boot and mongoDb ) 3 | 4 | Steps to run the application 5 | ============================= 6 | In backend 7 | Step1: Add the chat-service to the worspace using intellij , sts , etc(depends on your choice). 8 | Step2: Change the configuation in application.properties according to your system. 9 | Step3: Run the backend. 10 | 11 | In frontend 12 | Step4: Open the app in vs code. 13 | Step5: Install npm using command : npm install 14 | Step6: Run the application using command : ng serve 15 | Step7: Open any web browser 16 | type : localhost:4200 17 | 18 | =============IMPORTANT================ 19 | Full frontend and backend ( Angular , Spring Boot and MYSQL ) added in another branch 20 | (change mysql username and password in configuration file) 21 | 22 | To pull from that branch use the command :- 23 | git clone --branch chat_using_mysql https://github.com/codreal-yt/chat-application.git 24 | 25 | (If getting any error, Ping me in Youtube channel comment box) 26 | 27 | ====================================== 28 | 29 | Like, share and subscribe to my channel for more updates. 30 | https://www.youtube.com/@codreal 31 | 32 | Thank You 33 | -------------------------------------------------------------------------------- /backend/chat-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /backend/chat-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codreal-yt/chat-application/d6900163fadffc1667f51e6fce09d45bf8f45e3d/backend/chat-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /backend/chat-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /backend/chat-service/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /backend/chat-service/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /backend/chat-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.1 9 | 10 | 11 | com.codreal 12 | chat-service 13 | 0.0.1-SNAPSHOT 14 | chat-service 15 | Demo project for Spring Boot 16 | 17 | 11 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-mongodb 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-devtools 32 | runtime 33 | true 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/ChatServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ChatServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ChatServiceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/controller/ChatController.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.controller; 2 | 3 | import com.codreal.chatservice.exceptions.ChatAlreadyExistException; 4 | import com.codreal.chatservice.exceptions.ChatNotFoundException; 5 | import com.codreal.chatservice.exceptions.NoChatExistsInTheRepository; 6 | import com.codreal.chatservice.model.Chat; 7 | import com.codreal.chatservice.model.Message; 8 | import com.codreal.chatservice.services.ChatService; 9 | import com.codreal.chatservice.services.SequenceGeneratorService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.io.IOException; 16 | import java.util.HashSet; 17 | import java.util.List; 18 | 19 | @RestController 20 | @CrossOrigin(origins = "*") 21 | @RequestMapping("/chats") 22 | public class ChatController { 23 | 24 | @Autowired 25 | private ChatService chatService; 26 | @Autowired 27 | private SequenceGeneratorService sequenceGeneratorService; 28 | 29 | @PostMapping("/add") 30 | public ResponseEntity createChat(@RequestBody Chat chat) throws IOException { 31 | 32 | try { 33 | return new ResponseEntity(chatService.addChat(chat), HttpStatus.CREATED); 34 | } catch (ChatAlreadyExistException e) { 35 | return new ResponseEntity("Chat Already Exist", HttpStatus.CONFLICT); 36 | } 37 | } 38 | 39 | @GetMapping("/all") 40 | public ResponseEntity> getAllChats() { 41 | try { 42 | return new ResponseEntity>(chatService.findallchats(), HttpStatus.OK); 43 | } catch (NoChatExistsInTheRepository e) { 44 | return new ResponseEntity("List not found", HttpStatus.CONFLICT); 45 | } 46 | } 47 | 48 | @GetMapping("/{id}") 49 | public ResponseEntity getChatById(@PathVariable int id) { 50 | try { 51 | return new ResponseEntity(chatService.getById(id), HttpStatus.OK); 52 | } catch (ChatNotFoundException e) { 53 | return new ResponseEntity("Chat Not Found", HttpStatus.NOT_FOUND); 54 | } 55 | } 56 | 57 | @GetMapping("/firstUserName/{username}") 58 | public ResponseEntity getChatByFirstUserName(@PathVariable String username) { 59 | try { 60 | HashSet byChat = this.chatService.getChatByFirstUserName(username); 61 | return new ResponseEntity<>(byChat, HttpStatus.OK); 62 | } catch (ChatNotFoundException e) { 63 | return new ResponseEntity("Chat Not Exits", HttpStatus.CONFLICT); 64 | } 65 | } 66 | 67 | 68 | 69 | @GetMapping("/secondUserName/{username}") 70 | public ResponseEntity getChatBySecondUserName(@PathVariable String username) { 71 | 72 | try { 73 | HashSet byChat = this.chatService.getChatBySecondUserName(username); 74 | return new ResponseEntity<>(byChat, HttpStatus.OK); 75 | } catch (ChatNotFoundException e) { 76 | return new ResponseEntity("Chat Not Exits", HttpStatus.CONFLICT); 77 | } 78 | } 79 | 80 | @GetMapping("/getChatByFirstUserNameOrSecondUserName/{username}") 81 | public ResponseEntity getChatByFirstUserNameOrSecondUserName(@PathVariable String username) { 82 | 83 | try { 84 | HashSet byChat = this.chatService.getChatByFirstUserNameOrSecondUserName(username); 85 | return new ResponseEntity<>(byChat, HttpStatus.OK); 86 | } catch (ChatNotFoundException e) { 87 | return new ResponseEntity("Chat Not Exits", HttpStatus.CONFLICT); 88 | } 89 | } 90 | 91 | 92 | @GetMapping("/getChatByFirstUserNameAndSecondUserName") 93 | public ResponseEntity getChatByFirstUserNameAndSecondUserName(@RequestParam("firstUserName") String firstUserName, @RequestParam("secondUserName") String secondUserName){ 94 | 95 | try { 96 | HashSet chatByBothEmail = this.chatService.getChatByFirstUserNameAndSecondUserName(firstUserName, secondUserName); 97 | return new ResponseEntity<>(chatByBothEmail, HttpStatus.OK); 98 | } catch (ChatNotFoundException e) { 99 | return new ResponseEntity("Chat Not Exits", HttpStatus.NOT_FOUND); 100 | } 101 | } 102 | 103 | 104 | @PutMapping("/message/{chatId}") 105 | public ResponseEntity addMessage(@RequestBody Message add , @PathVariable int chatId) throws ChatNotFoundException { 106 | return new ResponseEntity(chatService.addMessage(add,chatId), org.springframework.http.HttpStatus.OK); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.controller; 2 | 3 | import com.codreal.chatservice.exceptions.UserAlreadyExistException; 4 | import com.codreal.chatservice.exceptions.UserNotFoundException; 5 | import com.codreal.chatservice.model.User; 6 | import com.codreal.chatservice.services.UserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | 15 | @RestController 16 | @CrossOrigin(origins = "*") 17 | @RequestMapping("/user") 18 | public class UserController { 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @GetMapping("/getall") 24 | public ResponseEntity> getall() throws IOException { 25 | try{ 26 | return new ResponseEntity>(userService.getall(), HttpStatus.OK); 27 | }catch (UserNotFoundException e){ 28 | return new ResponseEntity("User not Found", HttpStatus.NOT_FOUND); 29 | } 30 | } 31 | 32 | @PostMapping("/add") 33 | public ResponseEntity addUser(@RequestBody User user) throws IOException { 34 | try{ 35 | return new ResponseEntity(userService.addUser(user), HttpStatus.OK); 36 | }catch (UserAlreadyExistException e){ 37 | return new ResponseEntity("User already exists", HttpStatus.CONFLICT); 38 | } 39 | } 40 | 41 | @GetMapping("/getbyusername/{username}") 42 | public ResponseEntity getUserByUserName(@PathVariable String username) throws IOException { 43 | try{ 44 | return new ResponseEntity(userService.getUserByUserName(username), HttpStatus.OK); 45 | }catch (UserNotFoundException e){ 46 | return new ResponseEntity("User not Found", HttpStatus.NOT_FOUND); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/exceptions/ChatAlreadyExistException.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.exceptions; 2 | 3 | public class ChatAlreadyExistException extends Throwable { 4 | } 5 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/exceptions/ChatNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.exceptions; 2 | 3 | public class ChatNotFoundException extends Throwable { 4 | } 5 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/exceptions/NoChatExistsInTheRepository.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.exceptions; 2 | 3 | public class NoChatExistsInTheRepository extends Throwable { 4 | } 5 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/exceptions/UserAlreadyExistException.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.exceptions; 2 | 3 | public class UserAlreadyExistException extends Throwable { 4 | } 5 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/exceptions/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.exceptions; 2 | 3 | public class UserNotFoundException extends Throwable { 4 | } 5 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/model/Chat.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.annotation.Transient; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | 7 | import java.util.List; 8 | 9 | @Document(collection = "chats") 10 | public class Chat { 11 | 12 | @Transient 13 | public static final String SEQUENCE_NAME = "chat_sequence"; 14 | 15 | @Id 16 | private int chatId; 17 | private String firstUserName; 18 | private String secondUserName; 19 | private List messageList; 20 | 21 | public Chat() { 22 | } 23 | 24 | public Chat(int chatId, String firstUserName, String secondUserName, List messageList) { 25 | this.chatId = chatId; 26 | this.firstUserName = firstUserName; 27 | this.secondUserName = secondUserName; 28 | this.messageList = messageList; 29 | } 30 | 31 | public int getChatId() { 32 | return chatId; 33 | } 34 | 35 | public void setChatId(int chatId) { 36 | this.chatId = chatId; 37 | } 38 | 39 | public String getFirstUserName() { 40 | return firstUserName; 41 | } 42 | 43 | public void setFirstUserName(String firstUserName) { 44 | this.firstUserName = firstUserName; 45 | } 46 | 47 | public String getSecondUserName() { 48 | return secondUserName; 49 | } 50 | 51 | public void setSecondUserName(String secondUserName) { 52 | this.secondUserName = secondUserName; 53 | } 54 | 55 | public List getMessageList() { 56 | return messageList; 57 | } 58 | 59 | public void setMessageList(List messageList) { 60 | this.messageList = messageList; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/model/DatabaseSequence.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection = "chats_database_sequences") 7 | public class DatabaseSequence { 8 | 9 | @Id 10 | private String id; 11 | private int seq; 12 | 13 | public DatabaseSequence() { 14 | } 15 | 16 | public DatabaseSequence(String id, int seq) { 17 | this.id = id; 18 | this.seq = seq; 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public int getSeq() { 30 | return seq; 31 | } 32 | 33 | public void setSeq(int seq) { 34 | this.seq = seq; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/model/Message.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.model; 2 | 3 | import java.util.Date; 4 | 5 | public class Message { 6 | 7 | private String senderEmail; 8 | private Date time = new Date(System.currentTimeMillis()); 9 | private String replymessage; 10 | 11 | public Message() { 12 | } 13 | 14 | public Message(String senderEmail, Date time, String replymessage) { 15 | this.senderEmail = senderEmail; 16 | this.time = time; 17 | this.replymessage = replymessage; 18 | } 19 | 20 | public String getSenderEmail() { 21 | return senderEmail; 22 | } 23 | 24 | public void setSenderEmail(String senderEmail) { 25 | this.senderEmail = senderEmail; 26 | } 27 | 28 | public Date getTime() { 29 | return time; 30 | } 31 | 32 | public void setTime(Date time) { 33 | this.time = time; 34 | } 35 | 36 | public String getReplymessage() { 37 | return replymessage; 38 | } 39 | 40 | public void setReplymessage(String replymessage) { 41 | this.replymessage = replymessage; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/model/User.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection = "users") 7 | public class User { 8 | 9 | @Id 10 | private String userName; 11 | 12 | public User() { 13 | } 14 | 15 | public User(String userName) { 16 | this.userName = userName; 17 | } 18 | 19 | public String getUserName() { 20 | return userName; 21 | } 22 | 23 | public void setUserName(String userName) { 24 | this.userName = userName; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/repository/ChatRepository.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.repository; 2 | 3 | import com.codreal.chatservice.model.Chat; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.HashSet; 8 | 9 | @Repository 10 | public interface ChatRepository extends MongoRepository { 11 | 12 | HashSet getChatByFirstUserName(String username); 13 | 14 | HashSet getChatBySecondUserName(String username); 15 | 16 | HashSet getChatByFirstUserNameAndSecondUserName(String firstUserName, String secondUserName); 17 | 18 | HashSet getChatBySecondUserNameAndFirstUserName(String firstUserName, String secondUserName); 19 | } 20 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.repository; 2 | 3 | import com.codreal.chatservice.model.User; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface UserRepository extends MongoRepository { 9 | } 10 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/services/ChatService.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.services; 2 | 3 | import com.codreal.chatservice.exceptions.ChatAlreadyExistException; 4 | import com.codreal.chatservice.exceptions.ChatNotFoundException; 5 | import com.codreal.chatservice.exceptions.NoChatExistsInTheRepository; 6 | import com.codreal.chatservice.model.Chat; 7 | import com.codreal.chatservice.model.Message; 8 | 9 | import java.util.HashSet; 10 | import java.util.List; 11 | 12 | public interface ChatService { 13 | 14 | public Chat addChat(Chat chat) throws ChatAlreadyExistException; 15 | 16 | List findallchats() throws NoChatExistsInTheRepository; 17 | 18 | Chat getById(int id) throws ChatNotFoundException; 19 | 20 | HashSet getChatByFirstUserName(String username) throws ChatNotFoundException; 21 | 22 | HashSet getChatBySecondUserName(String username) throws ChatNotFoundException; 23 | 24 | HashSet getChatByFirstUserNameOrSecondUserName(String username) throws ChatNotFoundException; 25 | 26 | HashSet getChatByFirstUserNameAndSecondUserName(String firstUserName, String secondUserName) throws ChatNotFoundException; 27 | 28 | Chat addMessage(Message add, int chatId) throws ChatNotFoundException; 29 | } 30 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/services/ChatServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.services; 2 | 3 | import com.codreal.chatservice.exceptions.ChatNotFoundException; 4 | import com.codreal.chatservice.exceptions.NoChatExistsInTheRepository; 5 | import com.codreal.chatservice.model.Chat; 6 | import com.codreal.chatservice.model.Message; 7 | import com.codreal.chatservice.repository.ChatRepository; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashSet; 13 | import java.util.List; 14 | import java.util.Optional; 15 | 16 | @Service 17 | public class ChatServiceImpl implements ChatService { 18 | 19 | @Autowired 20 | private ChatRepository chatRepository; 21 | @Autowired 22 | private SequenceGeneratorService sequenceGeneratorService; 23 | 24 | public Chat addChat(Chat chat) { 25 | chat.setChatId(sequenceGeneratorService.generateSequence(Chat.SEQUENCE_NAME)); 26 | return chatRepository.save(chat); 27 | } 28 | 29 | @Override 30 | public List findallchats() throws NoChatExistsInTheRepository { 31 | if (chatRepository.findAll().isEmpty()) { 32 | throw new NoChatExistsInTheRepository(); 33 | } else { 34 | return chatRepository.findAll(); 35 | } 36 | 37 | } 38 | 39 | @Override 40 | public Chat getById(int id) throws ChatNotFoundException { 41 | Optional chatid = chatRepository.findById(id); 42 | if (chatid.isPresent()) { 43 | return chatid.get(); 44 | } else { 45 | throw new ChatNotFoundException(); 46 | } 47 | } 48 | 49 | @Override 50 | public HashSet getChatByFirstUserName(String username) throws ChatNotFoundException { 51 | HashSet chat = chatRepository.getChatByFirstUserName(username); 52 | 53 | if (chat.isEmpty()) { 54 | throw new ChatNotFoundException(); 55 | } else { 56 | return chat; 57 | } 58 | } 59 | 60 | @Override 61 | public HashSet getChatBySecondUserName(String username) throws ChatNotFoundException { 62 | HashSet chat = chatRepository.getChatBySecondUserName(username); 63 | if (chat.isEmpty()) { 64 | throw new ChatNotFoundException(); 65 | } else { 66 | return chat; 67 | } 68 | } 69 | 70 | @Override 71 | public HashSet getChatByFirstUserNameOrSecondUserName(String username) throws ChatNotFoundException { 72 | HashSet chat = chatRepository.getChatByFirstUserName(username); 73 | HashSet chat1 = chatRepository.getChatBySecondUserName(username); 74 | 75 | chat1.addAll(chat); 76 | 77 | if (chat.isEmpty() && chat1.isEmpty()) { 78 | throw new ChatNotFoundException(); 79 | } else if (chat1.isEmpty()) { 80 | return chat; 81 | } else { 82 | return chat1; 83 | } 84 | } 85 | 86 | @Override 87 | public HashSet getChatByFirstUserNameAndSecondUserName(String firstUserName, String secondUserName) throws ChatNotFoundException { 88 | HashSet chat = chatRepository.getChatByFirstUserNameAndSecondUserName(firstUserName, secondUserName); 89 | HashSet chat1 = chatRepository.getChatBySecondUserNameAndFirstUserName(firstUserName, secondUserName); 90 | if (chat.isEmpty() && chat1.isEmpty()) { 91 | throw new ChatNotFoundException(); 92 | } else if (chat.isEmpty()) { 93 | return chat1; 94 | } else { 95 | return chat; 96 | } 97 | } 98 | 99 | @Override 100 | public Chat addMessage(Message add, int chatId) throws ChatNotFoundException { 101 | Optional chat=chatRepository.findById(chatId); 102 | Chat abc=chat.get(); 103 | 104 | if(abc.getMessageList()==null){ 105 | List msg=new ArrayList<>(); 106 | msg.add(add); 107 | abc.setMessageList(msg); 108 | return chatRepository.save(abc); 109 | }else{ 110 | List rates=abc.getMessageList(); 111 | rates.add(add); 112 | abc.setMessageList(rates); 113 | return chatRepository.save(abc); 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/services/SequenceGeneratorService.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.services; 2 | 3 | import com.codreal.chatservice.model.DatabaseSequence; 4 | 5 | import org.springframework.data.mongodb.core.MongoOperations; 6 | import org.springframework.data.mongodb.core.query.Update; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.Objects; 10 | 11 | import static org.springframework.data.mongodb.core.FindAndModifyOptions.options; 12 | import static org.springframework.data.mongodb.core.query.Criteria.where; 13 | import static org.springframework.data.mongodb.core.query.Query.query; 14 | 15 | @Service 16 | public class SequenceGeneratorService { 17 | 18 | private MongoOperations mongoOperations; 19 | 20 | public SequenceGeneratorService(MongoOperations mongoOperations) { 21 | this.mongoOperations = mongoOperations; 22 | } 23 | 24 | public int generateSequence(String seqName) { 25 | 26 | DatabaseSequence counter = mongoOperations.findAndModify(query(where("_id").is(seqName)), 27 | new Update().inc("seq",1), options().returnNew(true).upsert(true), 28 | DatabaseSequence.class); 29 | return !Objects.isNull(counter) ? counter.getSeq():1; 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/services/UserService.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.services; 2 | 3 | import com.codreal.chatservice.exceptions.UserAlreadyExistException; 4 | import com.codreal.chatservice.exceptions.UserNotFoundException; 5 | import com.codreal.chatservice.model.User; 6 | 7 | import java.util.List; 8 | 9 | public interface UserService { 10 | List getall() throws UserNotFoundException; 11 | 12 | User addUser(User user) throws UserAlreadyExistException; 13 | 14 | User getUserByUserName(String username) throws UserNotFoundException; 15 | } 16 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/java/com/codreal/chatservice/services/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice.services; 2 | 3 | import com.codreal.chatservice.exceptions.UserAlreadyExistException; 4 | import com.codreal.chatservice.exceptions.UserNotFoundException; 5 | import com.codreal.chatservice.model.User; 6 | import com.codreal.chatservice.repository.UserRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | import java.util.Optional; 12 | 13 | @Service 14 | public class UserServiceImpl implements UserService{ 15 | 16 | @Autowired 17 | private UserRepository userRepository; 18 | 19 | 20 | @Override 21 | public List getall() throws UserNotFoundException { 22 | List users=userRepository.findAll(); 23 | if (users.isEmpty()){ 24 | throw new UserNotFoundException(); 25 | }else { 26 | return users; 27 | } 28 | } 29 | 30 | @Override 31 | public User addUser(User user) throws UserAlreadyExistException { 32 | Optional user1=userRepository.findById(user.getUserName()); 33 | 34 | if (user1.isPresent()){ 35 | throw new UserAlreadyExistException(); 36 | }else { 37 | return userRepository.save(user); 38 | } 39 | } 40 | 41 | @Override 42 | public User getUserByUserName(String username) throws UserNotFoundException { 43 | Optional user1=userRepository.findById(username); 44 | 45 | if (user1.isPresent()){ 46 | return user1.get(); 47 | }else { 48 | throw new UserNotFoundException(); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /backend/chat-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Change the port number according to your need 2 | server.port=8080 3 | 4 | spring.data.mongodb.host=localhost 5 | spring.data.mongodb.port=27017 6 | spring.data.mongodb.database=codreal 7 | spring.application.name=chatservice -------------------------------------------------------------------------------- /backend/chat-service/src/test/java/com/codreal/chatservice/ChatServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codreal.chatservice; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ChatServiceApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /frontend/app/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /frontend/app/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /frontend/app/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /frontend/app/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /frontend/app/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "ng serve", 7 | "type": "pwa-chrome", 8 | "request": "launch", 9 | "preLaunchTask": "npm: start", 10 | "url": "http://localhost:4200/" 11 | }, 12 | { 13 | "name": "ng test", 14 | "type": "chrome", 15 | "request": "launch", 16 | "preLaunchTask": "npm: test", 17 | "url": "http://localhost:9876/debug.html" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /frontend/app/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "type": "npm", 7 | "script": "start", 8 | "isBackground": true, 9 | "problemMatcher": { 10 | "owner": "typescript", 11 | "pattern": "$tsc", 12 | "background": { 13 | "activeOnStart": true, 14 | "beginsPattern": { 15 | "regexp": "(.*?)" 16 | }, 17 | "endsPattern": { 18 | "regexp": "bundle generation complete" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "test", 26 | "isBackground": true, 27 | "problemMatcher": { 28 | "owner": "typescript", 29 | "pattern": "$tsc", 30 | "background": { 31 | "activeOnStart": true, 32 | "beginsPattern": { 33 | "regexp": "(.*?)" 34 | }, 35 | "endsPattern": { 36 | "regexp": "bundle generation complete" 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /frontend/app/README.md: -------------------------------------------------------------------------------- 1 | # App 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.1.2. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /frontend/app/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "app": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/app", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "budgets": [ 33 | { 34 | "type": "initial", 35 | "maximumWarning": "500kb", 36 | "maximumError": "1mb" 37 | }, 38 | { 39 | "type": "anyComponentStyle", 40 | "maximumWarning": "2kb", 41 | "maximumError": "4kb" 42 | } 43 | ], 44 | "fileReplacements": [ 45 | { 46 | "replace": "src/environments/environment.ts", 47 | "with": "src/environments/environment.prod.ts" 48 | } 49 | ], 50 | "outputHashing": "all" 51 | }, 52 | "development": { 53 | "buildOptimizer": false, 54 | "optimization": false, 55 | "vendorChunk": true, 56 | "extractLicenses": false, 57 | "sourceMap": true, 58 | "namedChunks": true 59 | } 60 | }, 61 | "defaultConfiguration": "production" 62 | }, 63 | "serve": { 64 | "builder": "@angular-devkit/build-angular:dev-server", 65 | "configurations": { 66 | "production": { 67 | "browserTarget": "app:build:production" 68 | }, 69 | "development": { 70 | "browserTarget": "app:build:development" 71 | } 72 | }, 73 | "defaultConfiguration": "development" 74 | }, 75 | "extract-i18n": { 76 | "builder": "@angular-devkit/build-angular:extract-i18n", 77 | "options": { 78 | "browserTarget": "app:build" 79 | } 80 | }, 81 | "test": { 82 | "builder": "@angular-devkit/build-angular:karma", 83 | "options": { 84 | "main": "src/test.ts", 85 | "polyfills": "src/polyfills.ts", 86 | "tsConfig": "tsconfig.spec.json", 87 | "karmaConfig": "karma.conf.js", 88 | "assets": [ 89 | "src/favicon.ico", 90 | "src/assets" 91 | ], 92 | "styles": [ 93 | "src/styles.css" 94 | ], 95 | "scripts": [] 96 | } 97 | } 98 | } 99 | } 100 | }, 101 | "cli": { 102 | "analytics": "c45f72f6-1d6e-47c4-a09b-1ca24c9e6d70" 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /frontend/app/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/app'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /frontend/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "^14.1.0", 14 | "@angular/common": "^14.1.0", 15 | "@angular/compiler": "^14.1.0", 16 | "@angular/core": "^14.1.0", 17 | "@angular/forms": "^14.1.0", 18 | "@angular/platform-browser": "^14.1.0", 19 | "@angular/platform-browser-dynamic": "^14.1.0", 20 | "@angular/router": "^14.1.0", 21 | "rxjs": "~7.5.0", 22 | "tslib": "^2.3.0", 23 | "zone.js": "~0.11.4" 24 | }, 25 | "devDependencies": { 26 | "@angular-devkit/build-angular": "^14.1.2", 27 | "@angular/cli": "~14.1.2", 28 | "@angular/compiler-cli": "^14.1.0", 29 | "@types/jasmine": "~4.0.0", 30 | "jasmine-core": "~4.2.0", 31 | "karma": "~6.4.0", 32 | "karma-chrome-launcher": "~3.1.0", 33 | "karma-coverage": "~2.2.0", 34 | "karma-jasmine": "~5.1.0", 35 | "karma-jasmine-html-reporter": "~2.0.0", 36 | "typescript": "~4.7.2" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /frontend/app/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { ChatComponent } from './chat/chat.component'; 4 | import { MainComponent } from './main/main.component'; 5 | import { UserComponent } from './user/user.component'; 6 | 7 | const routes: Routes = [ 8 | { path: 'chat', component: ChatComponent }, 9 | { path: 'user', component: UserComponent }, 10 | { path: '', component: MainComponent } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forRoot(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class AppRoutingModule { } 18 | -------------------------------------------------------------------------------- /frontend/app/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codreal-yt/chat-application/d6900163fadffc1667f51e6fce09d45bf8f45e3d/frontend/app/src/app/app.component.css -------------------------------------------------------------------------------- /frontend/app/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /frontend/app/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'app'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('app'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement as HTMLElement; 33 | expect(compiled.querySelector('.content span')?.textContent).toContain('app app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /frontend/app/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'app'; 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /frontend/app/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 3 | import { BrowserModule } from '@angular/platform-browser'; 4 | 5 | import { AppRoutingModule } from './app-routing.module'; 6 | import { AppComponent } from './app.component'; 7 | import { ChatComponent } from './chat/chat.component'; 8 | import { HttpClientModule, HttpClient } from '@angular/common/http'; 9 | import { UserComponent } from './user/user.component'; 10 | import { MainComponent } from './main/main.component'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent, 15 | ChatComponent, 16 | UserComponent, 17 | MainComponent 18 | ], 19 | imports: [ 20 | BrowserModule, 21 | AppRoutingModule, 22 | FormsModule, 23 | ReactiveFormsModule, 24 | HttpClientModule 25 | ], 26 | providers: [], 27 | bootstrap: [AppComponent] 28 | }) 29 | export class AppModule { } 30 | -------------------------------------------------------------------------------- /frontend/app/src/app/chat/chat.component.css: -------------------------------------------------------------------------------- 1 | body, 2 | html { 3 | height: 100%; 4 | margin: 0; 5 | /* background: radial-gradient(circle, hsla(196, 63%, 61%, 1) 0%, hsla(240, 40%, 57%, 1) 100%); */ 6 | 7 | } 8 | 9 | .chat { 10 | margin-top: 1rem; 11 | margin-bottom: auto; 12 | 13 | } 14 | 15 | .card { 16 | height: 550px; 17 | border-radius: 15px !important; 18 | /* background: linear-gradient(90deg, rgb(140, 200, 253) 0%, rgb(93, 226, 241) 100%); */ 19 | border: 1px solid rgb(140, 200, 253); 20 | } 21 | 22 | .contacts_body { 23 | padding: 0.75rem 0 !important; 24 | overflow-y: auto; 25 | white-space: nowrap; 26 | } 27 | 28 | .card ::-webkit-scrollbar { 29 | width: 5px; 30 | } 31 | 32 | .msg_card_body { 33 | overflow-y: auto; 34 | } 35 | 36 | .msg_card_body::-webkit-scrollbar { 37 | width: 5px; 38 | } 39 | 40 | .chat-list-title { 41 | display: flex; 42 | justify-content: center; 43 | text-align: center; 44 | font-size: 1.5rem; 45 | font-weight: 500; 46 | } 47 | 48 | .card-header { 49 | border-radius: 15px 15px 0 0 !important; 50 | border-bottom: 0 !important; 51 | background: linear-gradient(90deg, rgb(140, 200, 253) 0%, rgb(93, 226, 241) 100%); 52 | } 53 | 54 | .card-footer { 55 | border-radius: 0 0 15px 15px !important; 56 | border-top: 0 !important; 57 | } 58 | 59 | .container { 60 | align-content: center; 61 | } 62 | 63 | .search { 64 | border-radius: 15px 0 0 15px !important; 65 | background: linear-gradient(90deg, rgb(97, 151, 198) 0%, rgb(77, 190, 203) 100%) !important; 66 | border: 0 !important; 67 | color: white !important; 68 | } 69 | 70 | .search:focus { 71 | box-shadow: none !important; 72 | outline: 0px !important; 73 | } 74 | 75 | .type_msg { 76 | background: linear-gradient(90deg, rgb(97, 151, 198) 0%, rgb(77, 190, 203) 100%) !important; 77 | border: 0 !important; 78 | color: white !important; 79 | height: 60px !important; 80 | overflow-y: auto; 81 | } 82 | 83 | .type_msg:focus { 84 | box-shadow: none !important; 85 | outline: 0px !important; 86 | } 87 | 88 | .attach_btn { 89 | border-radius: 15px 0 0 15px !important; 90 | background: rgb(97, 151, 198) !important; 91 | border: 0 !important; 92 | color: white !important; 93 | cursor: pointer; 94 | } 95 | 96 | .send_btn { 97 | border-radius: 0 15px 15px 0 !important; 98 | background-color: rgb(66, 170, 182) !important; 99 | border: 0 !important; 100 | color: white !important; 101 | cursor: pointer; 102 | } 103 | 104 | .search_btn { 105 | border-radius: 0 15px 15px 0 !important; 106 | background-color: rgba(0, 0, 0, 0.3) !important; 107 | border: 0 !important; 108 | color: white !important; 109 | cursor: pointer; 110 | } 111 | 112 | .contacts { 113 | list-style: none; 114 | padding: 0; 115 | } 116 | 117 | .contacts li { 118 | width: 100% !important; 119 | padding: 5px 10px; 120 | margin-bottom: 15px !important; 121 | } 122 | 123 | .active { 124 | background-color: rgba(0, 0, 0, 0.3); 125 | } 126 | 127 | .text_inside_circle { 128 | background: rgb(140, 200, 253); 129 | display: flex; 130 | justify-content: center; 131 | align-items: center; 132 | text-transform: capitalize; 133 | font-size: 1.5rem 134 | } 135 | 136 | .text_inside_circle1 { 137 | background: rgb(167, 165, 165); 138 | display: flex; 139 | justify-content: center; 140 | align-items: center; 141 | text-transform: capitalize; 142 | font-weight: bold; 143 | font-size: 1.5rem 144 | } 145 | 146 | .text_inside_circle2 { 147 | background: rgb(77, 190, 203); 148 | display: flex; 149 | justify-content: center; 150 | align-items: center; 151 | text-transform: capitalize; 152 | } 153 | 154 | .text_inside_circle3 { 155 | background: rgb(140, 200, 253); 156 | display: flex; 157 | justify-content: center; 158 | align-items: center; 159 | text-transform: capitalize; 160 | } 161 | 162 | 163 | .user_img { 164 | height: 70px; 165 | width: 70px; 166 | border: 1.5px solid #f5f6fa; 167 | 168 | } 169 | 170 | .user_img_msg { 171 | height: 40px; 172 | width: 40px; 173 | border: 1.5px solid #f5f6fa; 174 | 175 | } 176 | 177 | .img_cont { 178 | position: relative; 179 | height: 70px; 180 | width: 70px; 181 | } 182 | 183 | .img_cont_msg { 184 | height: 40px; 185 | width: 40px; 186 | } 187 | 188 | .chatList:hover { 189 | background-color: #91fea9; 190 | cursor: pointer; 191 | } 192 | 193 | .online_icon { 194 | position: absolute; 195 | height: 15px; 196 | width: 15px; 197 | background-color: #4cd137; 198 | border-radius: 50%; 199 | bottom: 0.2em; 200 | right: 0.4em; 201 | border: 1.5px solid white; 202 | } 203 | 204 | .offline { 205 | background-color: #c23616 !important; 206 | } 207 | 208 | .user_info { 209 | margin-top: auto; 210 | margin-bottom: auto; 211 | margin-left: 15px; 212 | } 213 | 214 | .user_info span { 215 | font-size: 20px; 216 | color: white; 217 | } 218 | 219 | .user_info p { 220 | font-size: 10px; 221 | color: rgba(255, 255, 255, 0.6); 222 | } 223 | 224 | .video_cam { 225 | margin-left: 50px; 226 | margin-top: 5px; 227 | } 228 | 229 | .video_cam span { 230 | color: white; 231 | font-size: 20px; 232 | cursor: pointer; 233 | margin-right: 20px; 234 | } 235 | 236 | .msg_cotainer { 237 | margin-top: auto; 238 | margin-bottom: auto; 239 | margin-left: 10px; 240 | border-radius: 25px; 241 | background-color: #a9ece6; 242 | padding: 10px; 243 | position: relative; 244 | } 245 | 246 | .msg_cotainer_send { 247 | margin-top: auto; 248 | margin-bottom: auto; 249 | margin-right: 10px; 250 | border-radius: 25px; 251 | background-color: #91fea9; 252 | padding: 10px; 253 | position: relative; 254 | } 255 | 256 | .msg_time { 257 | position: absolute; 258 | left: 0; 259 | bottom: -15px; 260 | color: rgba(23, 18, 35, 0.5); 261 | font-size: 10px; 262 | } 263 | 264 | .msg_time_send { 265 | position: absolute; 266 | right: 0; 267 | bottom: -15px; 268 | color: rgba(23, 18, 35, 0.5); 269 | font-size: 10px; 270 | } 271 | 272 | .msg_head { 273 | position: relative; 274 | } 275 | 276 | #action_menu_btn { 277 | position: absolute; 278 | right: 10px; 279 | top: 18px; 280 | color: white; 281 | cursor: pointer; 282 | font-size: 20px; 283 | } 284 | 285 | .action_menu { 286 | z-index: 1; 287 | position: absolute; 288 | padding: 15px 0; 289 | background-color: rgba(0, 0, 0, 0.5); 290 | color: white; 291 | border-radius: 15px; 292 | top: 30px; 293 | right: 15px; 294 | display: none; 295 | } 296 | 297 | .action_menu ul { 298 | list-style: none; 299 | padding: 0; 300 | margin: 0; 301 | } 302 | 303 | .action_menu ul li { 304 | width: 100%; 305 | padding: 10px 15px; 306 | margin-bottom: 5px; 307 | } 308 | 309 | .action_menu ul li i { 310 | padding-right: 10px; 311 | 312 | } 313 | 314 | .action_menu ul li:hover { 315 | cursor: pointer; 316 | background-color: rgba(0, 0, 0, 0.2); 317 | } 318 | 319 | @media(max-width: 576px) { 320 | .contacts_card { 321 | margin-bottom: 15px !important; 322 | } 323 | } -------------------------------------------------------------------------------- /frontend/app/src/app/chat/chat.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 5 |
6 | 7 |
8 |
9 |
10 |

All User

11 |
12 |
13 |
    14 |
  • 15 |
    16 |
    17 |
    18 | {{presentation.userName.substring(0,1)}} 19 |
    20 | 21 |
    22 | 28 |
    29 |
  • 30 |
31 |
32 | 33 |
34 |
35 | 36 |
37 | 38 | 39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 |
47 | {{secondUserName.substring(0,1)}}
48 |
49 | {{firstUserName.substring(0,1)}}
50 |
51 | 56 |
57 |
58 |
59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 67 |
68 | 69 |
70 |
71 | 72 | {{msg.replymessage}} 73 | 74 | 75 | {{msg.time.substring(11,16)}} 76 |
77 |
78 | {{msg.senderEmail.substring(0,1)}} 80 |
81 |
82 | 83 | 84 |
85 |
86 | {{msg.senderEmail.substring(0,1)}} 88 |
89 |
90 | {{msg.replymessage}} 91 | {{msg.time.substring(11,16)}} 92 |
93 |
94 | 95 | 96 |
97 |
98 | 113 |
114 |
115 | 116 | 117 | 118 |
119 |
120 |
121 |

Chat List

122 |
123 |
124 |
    125 |
  • 126 |
    127 |
    128 |
    129 | {{chats.secondUserName.substring(0,1)}} 130 |
    131 |
    132 | {{chats.firstUserName.substring(0,1)}} 133 |
    134 | 135 |
    136 | 143 |
    144 |
  • 145 |
146 |
147 | 148 |
149 |
150 | 151 |
152 |
153 |
154 | 155 | -------------------------------------------------------------------------------- /frontend/app/src/app/chat/chat.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ChatComponent } from './chat.component'; 4 | 5 | describe('ChatComponent', () => { 6 | let component: ChatComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ ChatComponent ] 12 | }) 13 | .compileComponents(); 14 | 15 | fixture = TestBed.createComponent(ChatComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /frontend/app/src/app/chat/chat.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormControl, FormGroup } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { Chat } from '../models/chat'; 5 | import { Message } from '../models/message'; 6 | import { ChatService } from '../services/chat.service'; 7 | import { UserService } from '../services/user.service'; 8 | 9 | @Component({ 10 | selector: 'app-chat', 11 | templateUrl: './chat.component.html', 12 | styleUrls: ['./chat.component.css'] 13 | }) 14 | export class ChatComponent implements OnInit { 15 | 16 | chatForm: FormGroup; 17 | chatObj: Chat = new Chat(); 18 | messageObj: Message = new Message(); 19 | // chatId: number = 22; 20 | public messageList: any = []; 21 | public chatList: any = []; 22 | replymessage: String = "checking"; 23 | public chatData: any; 24 | msg = "Good work"; 25 | chatId: any = sessionStorage.getItem('chatId'); 26 | color = ""; 27 | secondUserName = ""; 28 | public alluser: any = []; 29 | check = sessionStorage.getItem('username'); 30 | timesRun = 0; 31 | timesRun2 = 0; 32 | 33 | 34 | firstUserName = sessionStorage.getItem('username'); 35 | senderEmail = sessionStorage.getItem('username'); 36 | senderCheck = sessionStorage.getItem('username'); 37 | 38 | constructor(private chatService: ChatService, private router: Router, private userService: UserService) { 39 | this.chatForm = new FormGroup({ 40 | replymessage: new FormControl() 41 | }); 42 | 43 | } 44 | 45 | ngOnInit(): void { 46 | setInterval(() => { 47 | this.chatService.getChatById(sessionStorage.getItem('chatId')).subscribe(data => { 48 | this.chatData = data; 49 | this.messageList = this.chatData.messageList; 50 | this.secondUserName = this.chatData.secondUserName; 51 | this.firstUserName = this.chatData.firstUserName; 52 | }); 53 | }, 1000); 54 | 55 | 56 | let getByname = setInterval(() => { 57 | // For getting all the chat list whose ever is logged in. 58 | this.chatService.getChatByFirstUserNameOrSecondUserName(sessionStorage.getItem('username')).subscribe(data => { 59 | // console.log(data); 60 | this.chatData = data; 61 | this.chatList = this.chatData; 62 | }); 63 | 64 | this.timesRun2 += 1; 65 | if (this.timesRun2 === 2) { 66 | clearInterval(getByname); 67 | } 68 | }, 1000); 69 | 70 | let all = setInterval(() => { 71 | 72 | this.userService.getAll().subscribe((data) => { 73 | // console.log(data); 74 | 75 | this.alluser = data; 76 | }) 77 | 78 | this.timesRun += 1; 79 | if (this.timesRun === 2) { 80 | clearInterval(all); 81 | } 82 | }, 1000); 83 | 84 | 85 | } 86 | 87 | loadChatByEmail(event: string, event1: string) { 88 | console.log(event, event1); 89 | // For removing the previous chatId 90 | sessionStorage.removeItem("chatId"); 91 | 92 | // For checking the chat room by both the emails , if there is present then it will give the chat Id in sessionStorage 93 | this.chatService.getChatByFirstUserNameAndSecondUserName(event, event1).subscribe(data => { 94 | // console.log(data); 95 | this.chatData = data; 96 | this.chatId = this.chatData[0].chatId; 97 | console.log(this.chatId); 98 | sessionStorage.setItem('chatId', this.chatId) 99 | 100 | 101 | setInterval(() => { 102 | this.chatService.getChatById(this.chatId).subscribe(data => { 103 | this.chatData = data; 104 | this.messageList = this.chatData.messageList; 105 | this.secondUserName = this.chatData.secondUserName; 106 | this.firstUserName = this.chatData.firstUserName; 107 | }); 108 | }, 1000) 109 | 110 | }); 111 | 112 | } 113 | 114 | sendMessage() { 115 | console.log(this.chatForm.value); 116 | 117 | // This will call the update chat method when ever user send the message 118 | this.messageObj.replymessage = this.chatForm.value.replymessage; 119 | this.messageObj.senderEmail = this.senderEmail; 120 | this.chatService.updateChat(this.messageObj, this.chatId).subscribe(data => { 121 | console.log(data); 122 | this.chatForm.reset(); 123 | 124 | // for displaying the messageList by the chatId 125 | this.chatService.getChatById(this.chatId).subscribe(data => { 126 | console.log(data); 127 | this.chatData = data; 128 | // console.log(this.chatData.messageList);console.log(JSON.stringify(this.chatData.messageList)); 129 | this.messageList = this.chatData.messageList; 130 | this.secondUserName = this.chatData.secondUserName; 131 | this.firstUserName = this.chatData.firstUserName; 132 | 133 | }) 134 | }) 135 | } 136 | 137 | routeX() { 138 | // this.router.navigateByUrl('/navbar/recommendation-service'); 139 | sessionStorage.clear(); 140 | // window.location.reload(); 141 | this.router.navigateByUrl(''); 142 | } 143 | 144 | routeHome() { 145 | this.router.navigateByUrl(''); 146 | } 147 | 148 | 149 | goToChat(username: any) { 150 | this.chatService.getChatByFirstUserNameAndSecondUserName(username, sessionStorage.getItem("username")).subscribe( 151 | (data) => { 152 | this.chatId = data.chatId; 153 | sessionStorage.setItem("chatId", this.chatId); 154 | }, 155 | (error) => { 156 | if (error.status == 404) { 157 | this.chatObj.firstUserName = sessionStorage.getItem("username"); 158 | this.chatObj.secondUserName = username; 159 | this.chatService.createChatRoom(this.chatObj).subscribe( 160 | (data) => { 161 | this.chatData = data; 162 | this.chatId = this.chatData.chatId; 163 | sessionStorage.setItem("chatId", this.chatData.chatId); 164 | }) 165 | } else { 166 | 167 | } 168 | }); 169 | 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /frontend/app/src/app/main/main.component.css: -------------------------------------------------------------------------------- 1 | .user { 2 | border: 1px solid blueviolet; 3 | border-radius: 6px; 4 | margin: 4px 4px 4px 4px; 5 | background: cornsilk; 6 | display: flex; 7 | justify-content: center; 8 | text-align: center; 9 | } 10 | 11 | .user:hover { 12 | border: 1px solid red; 13 | background: gainsboro; 14 | /* box-shadow: 0 2px 1px 0 (0.5); */ 15 | } -------------------------------------------------------------------------------- /frontend/app/src/app/main/main.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

All Registered Users

4 |
5 |
6 |
7 |
8 | {{presentation.userName}} 9 |
10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /frontend/app/src/app/main/main.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { MainComponent } from './main.component'; 4 | 5 | describe('MainComponent', () => { 6 | let component: MainComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ MainComponent ] 12 | }) 13 | .compileComponents(); 14 | 15 | fixture = TestBed.createComponent(MainComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /frontend/app/src/app/main/main.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { Chat } from '../models/chat'; 4 | import { ChatService } from '../services/chat.service'; 5 | import { UserService } from '../services/user.service'; 6 | 7 | @Component({ 8 | selector: 'app-main', 9 | templateUrl: './main.component.html', 10 | styleUrls: ['./main.component.css'] 11 | }) 12 | export class MainComponent implements OnInit { 13 | public alluser: any = []; 14 | check = sessionStorage.getItem('username'); 15 | chatId: any = 0; 16 | chatObj: Chat = new Chat(); 17 | public chatData: any = []; 18 | 19 | constructor(private router: Router, private userService: UserService, private chatService: ChatService) { } 20 | 21 | ngOnInit(): void { 22 | let all = setInterval(() => { 23 | 24 | this.userService.getAll().subscribe((data) => { 25 | // console.log(data); 26 | this.alluser = data; 27 | }) 28 | }, 1000); 29 | } 30 | 31 | 32 | goToChat(username: any) { 33 | this.chatService.getChatByFirstUserNameAndSecondUserName(username, sessionStorage.getItem("username")).subscribe( 34 | (data) => { 35 | this.chatId = data.chatId; 36 | sessionStorage.setItem("chatId", this.chatId); 37 | 38 | sessionStorage.setItem("gotochat", "false"); 39 | this.router.navigateByUrl('/chat'); 40 | }, 41 | (error) => { 42 | if (error.status == 404) { 43 | this.chatObj.firstUserName = sessionStorage.getItem("username"); 44 | this.chatObj.secondUserName = username; 45 | this.chatService.createChatRoom(this.chatObj).subscribe( 46 | (data) => { 47 | this.chatData = data; 48 | this.chatId = this.chatData.chatId; 49 | sessionStorage.setItem("chatId", this.chatData.chatId); 50 | 51 | sessionStorage.setItem("gotochat", "false"); 52 | this.router.navigateByUrl('/chat'); 53 | }) 54 | } else { 55 | 56 | } 57 | }); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/chat.spec.ts: -------------------------------------------------------------------------------- 1 | import { Chat } from './chat'; 2 | 3 | describe('Chat', () => { 4 | it('should create an instance', () => { 5 | expect(new Chat()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/chat.ts: -------------------------------------------------------------------------------- 1 | import { Message } from "./message"; 2 | 3 | export class Chat { 4 | 5 | chatId: Number; 6 | firstUserName: string; 7 | secondUserName: string; 8 | messageList: Message[]; 9 | 10 | constructor() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/message.spec.ts: -------------------------------------------------------------------------------- 1 | import { Message } from './message'; 2 | 3 | describe('Message', () => { 4 | it('should create an instance', () => { 5 | expect(new Message()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/message.ts: -------------------------------------------------------------------------------- 1 | export class Message { 2 | senderEmail: string; 3 | time: string; 4 | replymessage: string; 5 | 6 | constructor() { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/user.spec.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user'; 2 | 3 | describe('User', () => { 4 | it('should create an instance', () => { 5 | expect(new User()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /frontend/app/src/app/models/user.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | userName:string; 3 | 4 | constructor(){} 5 | } 6 | -------------------------------------------------------------------------------- /frontend/app/src/app/services/chat.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { ChatService } from './chat.service'; 4 | 5 | describe('ChatService', () => { 6 | let service: ChatService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(ChatService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /frontend/app/src/app/services/chat.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { Chat } from '../models/chat'; 4 | import { Message } from '../models/message'; 5 | import { HttpClient } from '@angular/common/http'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class ChatService { 11 | 12 | baseUrl = "http://localhost:8080"; 13 | 14 | constructor(private httpClient: HttpClient) { } 15 | 16 | 17 | updateChat(message: Message, chatId: any): Observable { 18 | return this.httpClient.put(this.baseUrl + "/chats/message/" + `${chatId}`, message); 19 | } 20 | 21 | getChatById(chatId: any) { 22 | return this.httpClient.get(this.baseUrl + "/chats/" + chatId) 23 | } 24 | 25 | createChatRoom(chat: Chat): Observable { 26 | return this.httpClient.post(this.baseUrl + "/chats/add", chat); 27 | } 28 | 29 | getChatByFirstUserNameAndSecondUserName(firstUserName: String, secondUserName: String) { 30 | return this.httpClient.get(this.baseUrl + "/chats/getChatByFirstUserNameAndSecondUserName" + '?firstUserName=' + firstUserName + '&secondUserName=' + secondUserName) 31 | } 32 | 33 | getChatByFirstUserNameOrSecondUserName(username: any) { 34 | return this.httpClient.get(this.baseUrl + "/chats/getChatByFirstUserNameOrSecondUserName/" + username) 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /frontend/app/src/app/services/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { UserService } from './user.service'; 4 | 5 | describe('UserService', () => { 6 | let service: UserService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(UserService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /frontend/app/src/app/services/user.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | import { User } from '../models/user'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class UserService { 10 | 11 | baseUrl = "http://localhost:8080"; 12 | 13 | constructor(private httpClient: HttpClient) { } 14 | 15 | getAll() { 16 | return this.httpClient.get(this.baseUrl + "/user/getall") 17 | } 18 | 19 | adduser(user: User): Observable { 20 | return this.httpClient.post(this.baseUrl + "/user/add", user); 21 | } 22 | 23 | getUserByUsername(username: any) { 24 | return this.httpClient.get(this.baseUrl + "/user/getbyusername/" + username) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /frontend/app/src/app/user/user.component.css: -------------------------------------------------------------------------------- 1 | .feild { 2 | font-size: 14px; 3 | display: flex; 4 | text-align: center; 5 | justify-content: center; 6 | align-items: center; 7 | } -------------------------------------------------------------------------------- /frontend/app/src/app/user/user.component.html: -------------------------------------------------------------------------------- 1 |
2 | 33 |
34 | 35 | 71 | 72 | 108 | -------------------------------------------------------------------------------- /frontend/app/src/app/user/user.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UserComponent } from './user.component'; 4 | 5 | describe('UserComponent', () => { 6 | let component: UserComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ UserComponent ] 12 | }) 13 | .compileComponents(); 14 | 15 | fixture = TestBed.createComponent(UserComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /frontend/app/src/app/user/user.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormGroup, FormControl, Validators } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { Chat } from '../models/chat'; 5 | import { User } from '../models/user'; 6 | import { ChatService } from '../services/chat.service'; 7 | import { UserService } from '../services/user.service'; 8 | 9 | @Component({ 10 | selector: 'app-user', 11 | templateUrl: './user.component.html', 12 | styleUrls: ['./user.component.css'] 13 | }) 14 | export class UserComponent implements OnInit { 15 | 16 | chatId: any = 0; 17 | registerForm: FormGroup; 18 | loginForm: FormGroup; 19 | successregister: boolean = false; 20 | registermsg = ""; 21 | alert = ""; 22 | loginmsg = ""; 23 | alert2 = ""; 24 | successlogin: boolean = false; 25 | public userObj: User = new User(); 26 | public alluser: any = []; 27 | secondUsername = ""; 28 | chatObj: Chat = new Chat(); 29 | public chatData: any = []; 30 | check = ""; 31 | loggedIn: boolean = false; 32 | loggedOut: boolean = true; 33 | chatbox: boolean = true; 34 | 35 | logout() { 36 | this.loggedIn = false; 37 | this.loggedOut = true; 38 | sessionStorage.clear(); 39 | 40 | this.router.navigateByUrl(''); 41 | } 42 | 43 | constructor(private router: Router, private userService: UserService, private chatService: ChatService) { 44 | this.registerForm = new FormGroup({ 45 | username: new FormControl("", [Validators.required]) 46 | }); 47 | this.loginForm = new FormGroup({ 48 | username: new FormControl("", [Validators.required]) 49 | }); 50 | } 51 | 52 | ngOnInit(): void { 53 | 54 | setInterval(() => { 55 | this.userService.getAll().subscribe((data) => { 56 | // console.log(data); 57 | 58 | this.alluser = data; 59 | 60 | }) 61 | }, 1000); 62 | 63 | } 64 | 65 | adduser() { 66 | if (this.registerForm.valid) { 67 | this.userObj.userName = this.registerForm.value.username; 68 | this.userService.adduser(this.userObj).subscribe( 69 | (data: any) => { 70 | console.log(data); 71 | 72 | this.successregister = true; 73 | this.alert = "success"; 74 | this.registermsg = "Successsfully added"; 75 | 76 | this.registerForm.reset(); 77 | 78 | }, 79 | (error) => { 80 | console.log(error.error); 81 | if (error.status == 409) { 82 | this.successregister = true; 83 | this.alert = "danger"; 84 | this.registermsg = "Already registered" 85 | } else { 86 | this.successregister = true; 87 | this.alert = "danger"; 88 | this.registermsg = "Error" 89 | } 90 | 91 | } 92 | ) 93 | } 94 | 95 | } 96 | 97 | login() { 98 | if (this.loginForm.valid) { 99 | this.userService.getUserByUsername(this.loginForm.value.username).subscribe( 100 | (data: any) => { 101 | console.log(data); 102 | 103 | this.successlogin = true; 104 | this.alert2 = "success"; 105 | this.loginmsg = "Successsfully LoggedIn"; 106 | 107 | sessionStorage.setItem("username", this.loginForm.value.username); 108 | this.check = this.loginForm.value.username; 109 | this.loginForm.reset(); 110 | 111 | this.loggedIn = true; 112 | this.loggedOut = false; 113 | 114 | // this.router.navigateByUrl('/chat'); 115 | }, 116 | (error) => { 117 | console.log(error.error); 118 | if (error.status == 404) { 119 | this.successlogin = true; 120 | this.alert2 = "danger"; 121 | this.loginmsg = "Not a registerd user" 122 | } else { 123 | this.successlogin = true; 124 | this.alert2 = "danger"; 125 | this.loginmsg = "Error" 126 | } 127 | 128 | } 129 | ) 130 | } 131 | 132 | 133 | } 134 | 135 | goToChat(username: any) { 136 | this.chatService.getChatByFirstUserNameAndSecondUserName(username, sessionStorage.getItem("username")).subscribe( 137 | (data) => { 138 | this.chatData = data; 139 | this.chatId = this.chatData[0].chatId; 140 | sessionStorage.setItem("chatId", this.chatId); 141 | this.router.navigateByUrl('/chat'); 142 | }, 143 | (error) => { 144 | if (error.status == 404) { 145 | this.chatObj.firstUserName = sessionStorage.getItem("username"); 146 | this.chatObj.secondUserName = username; 147 | this.chatService.createChatRoom(this.chatObj).subscribe( 148 | (data) => { 149 | this.chatData = data; 150 | sessionStorage.setItem("chatId", this.chatData[0].chatId); 151 | // this.router.navigateByUrl('/chat'); 152 | console.log("2") 153 | }) 154 | } else { 155 | // this.router.navigateByUrl('/chat'); 156 | console.log("3") 157 | } 158 | }); 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /frontend/app/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codreal-yt/chat-application/d6900163fadffc1667f51e6fce09d45bf8f45e3d/frontend/app/src/assets/.gitkeep -------------------------------------------------------------------------------- /frontend/app/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /frontend/app/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /frontend/app/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codreal-yt/chat-application/d6900163fadffc1667f51e6fce09d45bf8f45e3d/frontend/app/src/favicon.ico -------------------------------------------------------------------------------- /frontend/app/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | App 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /frontend/app/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /frontend/app/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including 12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * By default, zone.js will patch all possible macroTask and DomEvents 23 | * user can disable parts of macroTask/DomEvents patch by setting following flags 24 | * because those flags need to be set before `zone.js` being loaded, and webpack 25 | * will put import in the top of bundle, so user need to create a separate file 26 | * in this directory (for example: zone-flags.ts), and put the following flags 27 | * into that file, and then add the following code before importing zone.js. 28 | * import './zone-flags'; 29 | * 30 | * The flags allowed in zone-flags.ts are listed here. 31 | * 32 | * The following flags will work for all browsers. 33 | * 34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 37 | * 38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 40 | * 41 | * (window as any).__Zone_enable_cross_context_check = true; 42 | * 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * Zone JS is required by default for Angular itself. 47 | */ 48 | import 'zone.js'; // Included with Angular CLI. 49 | 50 | 51 | /*************************************************************************************************** 52 | * APPLICATION IMPORTS 53 | */ 54 | -------------------------------------------------------------------------------- /frontend/app/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /frontend/app/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | (id: string): T; 13 | keys(): string[]; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), 21 | ); 22 | 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().forEach(context); 27 | -------------------------------------------------------------------------------- /frontend/app/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /frontend/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "strictNullChecks": false, 15 | "declaration": false, 16 | "downlevelIteration": true, 17 | "experimentalDecorators": true, 18 | "moduleResolution": "node", 19 | "importHelpers": true, 20 | "target": "es2020", 21 | "module": "es2020", 22 | "lib": [ 23 | "es2020", 24 | "dom" 25 | ] 26 | }, 27 | "angularCompilerOptions": { 28 | "enableI18nLegacyMessageIdFormat": false, 29 | "strictInjectionParameters": true, 30 | "strictInputAccessModifiers": true, 31 | "strictTemplates": true 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /frontend/app/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------