├── .gitignore
├── .idea
└── .gitignore
├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── LICENSE
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
├── restore.sql
└── src
├── main
├── java
│ └── innotutor
│ │ └── innotutor_backend
│ │ ├── InnotutorBackendApplication.java
│ │ ├── controller
│ │ ├── SearcherController.java
│ │ ├── SessionController.java
│ │ ├── card
│ │ │ ├── CardController.java
│ │ │ ├── RequestsController.java
│ │ │ └── ServicesController.java
│ │ └── user
│ │ │ ├── ScheduleController.java
│ │ │ ├── StudentsController.java
│ │ │ ├── TutorsController.java
│ │ │ ├── UserController.java
│ │ │ └── WaitingListController.java
│ │ ├── dto
│ │ ├── UserDTO.java
│ │ ├── card
│ │ │ ├── CardDTO.java
│ │ │ ├── SessionRatingDTO.java
│ │ │ └── SubjectDTO.java
│ │ ├── enrollment
│ │ │ ├── EnrollmentDTO.java
│ │ │ ├── WaitingListDTO.java
│ │ │ ├── student
│ │ │ │ ├── MyStudentDTO.java
│ │ │ │ ├── RequestedStudentsListDTO.java
│ │ │ │ └── RequestedStudentsListInfoDTO.java
│ │ │ └── tutor
│ │ │ │ ├── MyTutorDTO.java
│ │ │ │ ├── RespondedTutorsListDTO.java
│ │ │ │ └── RespondedTutorsListInfoDTO.java
│ │ ├── searcher
│ │ │ ├── StudentRequestDTO.java
│ │ │ ├── TutorCvDTO.java
│ │ │ └── UserCard.java
│ │ └── session
│ │ │ ├── ScheduleDTO.java
│ │ │ ├── SessionDTO.java
│ │ │ └── sessionsettings
│ │ │ ├── SessionFormatDTO.java
│ │ │ └── SessionTypeDTO.java
│ │ ├── entity
│ │ ├── card
│ │ │ ├── Card.java
│ │ │ ├── CardSessionFormat.java
│ │ │ ├── CardSessionType.java
│ │ │ └── enrollment
│ │ │ │ ├── CardEnroll.java
│ │ │ │ ├── CardEnrollSessionFormat.java
│ │ │ │ ├── CardEnrollSessionType.java
│ │ │ │ └── EnrollmentStatus.java
│ │ ├── session
│ │ │ ├── Session.java
│ │ │ ├── SessionFormat.java
│ │ │ ├── SessionRating.java
│ │ │ ├── SessionType.java
│ │ │ └── Subject.java
│ │ └── user
│ │ │ ├── Request.java
│ │ │ ├── Service.java
│ │ │ ├── SessionStudent.java
│ │ │ └── User.java
│ │ ├── repository
│ │ ├── card
│ │ │ ├── CardRepository.java
│ │ │ ├── CardSessionFormatRepository.java
│ │ │ ├── CardSessionTypeRepository.java
│ │ │ └── enrollment
│ │ │ │ ├── CardEnrollRepository.java
│ │ │ │ ├── CardEnrollSessionFormatRepository.java
│ │ │ │ ├── CardEnrollSessionTypeRepository.java
│ │ │ │ └── EnrollmentStatusRepository.java
│ │ ├── session
│ │ │ ├── SessionFormatRepository.java
│ │ │ ├── SessionRatingRepository.java
│ │ │ ├── SessionRepository.java
│ │ │ ├── SessionTypeRepository.java
│ │ │ └── SubjectRepository.java
│ │ └── user
│ │ │ ├── RequestRepository.java
│ │ │ ├── ServiceRepository.java
│ │ │ ├── SessionStudentRepository.java
│ │ │ └── UserRepository.java
│ │ ├── security
│ │ ├── CustomPrincipal.java
│ │ ├── SecurityUtils.java
│ │ ├── TokenFilter.java
│ │ └── WebSecurityConfig.java
│ │ └── service
│ │ ├── CardEnrollService.java
│ │ ├── CardService.java
│ │ ├── CardsListService.java
│ │ ├── SearcherService.java
│ │ ├── SessionService.java
│ │ ├── StudentsService.java
│ │ ├── TutorsService.java
│ │ ├── UserService.java
│ │ └── utility
│ │ ├── card
│ │ ├── CardCreatorUser.java
│ │ ├── CardDTOCreator.java
│ │ ├── CardType.java
│ │ ├── Ratings.java
│ │ └── ValidSessionRating.java
│ │ ├── cardmanager
│ │ ├── CardCreator.java
│ │ └── CardUpdater.java
│ │ ├── saver
│ │ ├── SessionFormatsCardSaver.java
│ │ ├── SessionTypesCardSaver.java
│ │ └── UserCardRelationSaver.java
│ │ └── sessionconverter
│ │ ├── SessionConverter.java
│ │ ├── sessionformat
│ │ ├── CardEnrollSessionFormatConverter.java
│ │ ├── CardSessionFormatConverter.java
│ │ ├── SessionFormatConverter.java
│ │ └── SessionFormatEntityConverter.java
│ │ └── sessiontype
│ │ ├── CardEnrollSessionTypeConverter.java
│ │ ├── CardSessionTypeConverter.java
│ │ ├── SessionTypeConverter.java
│ │ └── SessionTypeEntityConverter.java
└── resources
│ └── application.properties
└── test
└── java
└── innotutor
└── innotutor_backend
└── InnoTutorTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 |
4 | # Created by https://www.toptal.com/developers/gitignore/api/intellij,java,dart,flutter
5 | # Edit at https://www.toptal.com/developers/gitignore?templates=intellij,java,dart,flutter
6 |
7 | ### Dart ###
8 | # See https://www.dartlang.org/guides/libraries/private-files
9 |
10 | # Files and directories created by pub
11 | .dart_tool/
12 | .packages
13 | build/
14 | # If you're building an application, you may want to check-in your pubspec.lock
15 | pubspec.lock
16 |
17 | # Directory created by dartdoc
18 | # If you don't generate documentation locally you can remove this line.
19 | doc/api/
20 |
21 | # dotenv environment variables file
22 | .env*
23 |
24 | # Avoid committing generated Javascript files:
25 | *.dart.js
26 | *.info.json # Produced by the --dump-info flag.
27 | *.js # When generated by dart2js. Don't specify *.js if your
28 | # project includes source files written in JavaScript.
29 | *.js_
30 | *.js.deps
31 | *.js.map
32 |
33 | .flutter-plugins
34 | .flutter-plugins-dependencies
35 |
36 | ### Flutter ###
37 | # Flutter/Dart/Pub related
38 | **/doc/api/
39 | .fvm/
40 | .pub-cache/
41 | .pub/
42 | coverage/
43 | lib/generated_plugin_registrant.dart
44 | # For library packages, don’t commit the pubspec.lock file.
45 | # Regenerating the pubspec.lock file lets you test your package against the latest compatible versions of its dependencies.
46 | # See https://dart.dev/guides/libraries/private-files#pubspeclock
47 | #pubspec.lock
48 |
49 | # Android related
50 | **/android/**/gradle-wrapper.jar
51 | **/android/.gradle
52 | **/android/captures/
53 | **/android/gradlew
54 | **/android/gradlew.bat
55 | **/android/key.properties
56 | **/android/local.properties
57 | **/android/**/GeneratedPluginRegistrant.java
58 |
59 | # iOS/XCode related
60 | **/ios/**/*.mode1v3
61 | **/ios/**/*.mode2v3
62 | **/ios/**/*.moved-aside
63 | **/ios/**/*.pbxuser
64 | **/ios/**/*.perspectivev3
65 | **/ios/**/*sync/
66 | **/ios/**/.sconsign.dblite
67 | **/ios/**/.tags*
68 | **/ios/**/.vagrant/
69 | **/ios/**/DerivedData/
70 | **/ios/**/Icon?
71 | **/ios/**/Pods/
72 | **/ios/**/.symlinks/
73 | **/ios/**/profile
74 | **/ios/**/xcuserdata
75 | **/ios/.generated/
76 | **/ios/Flutter/.last_build_id
77 | **/ios/Flutter/App.framework
78 | **/ios/Flutter/Flutter.framework
79 | **/ios/Flutter/Flutter.podspec
80 | **/ios/Flutter/Generated.xcconfig
81 | **/ios/Flutter/app.flx
82 | **/ios/Flutter/app.zip
83 | **/ios/Flutter/flutter_assets/
84 | **/ios/Flutter/flutter_export_environment.sh
85 | **/ios/ServiceDefinitions.json
86 | **/ios/Runner/GeneratedPluginRegistrant.*
87 |
88 | # Exceptions to above rules.
89 | !**/ios/**/default.mode1v3
90 | !**/ios/**/default.mode2v3
91 | !**/ios/**/default.pbxuser
92 | !**/ios/**/default.perspectivev3
93 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
94 |
95 | ### Intellij ###
96 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
97 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
98 |
99 | # User-specific stuff
100 | .idea/**/workspace.xml
101 | .idea/**/tasks.xml
102 | .idea/**/usage.statistics.xml
103 | .idea/**/dictionaries
104 | .idea/**/shelf
105 |
106 | # AWS User-specific
107 | .idea/**/aws.xml
108 |
109 | # Generated files
110 | .idea/**/contentModel.xml
111 |
112 | # Sensitive or high-churn files
113 | .idea/**/dataSources/
114 | .idea/**/dataSources.ids
115 | .idea/**/dataSources.local.xml
116 | .idea/**/sqlDataSources.xml
117 | .idea/**/dynamic.xml
118 | .idea/**/uiDesigner.xml
119 | .idea/**/dbnavigator.xml
120 |
121 | # Gradle
122 | .idea/**/gradle.xml
123 | .idea/**/libraries
124 |
125 | # Gradle and Maven with auto-import
126 | # When using Gradle or Maven with auto-import, you should exclude module files,
127 | # since they will be recreated, and may cause churn. Uncomment if using
128 | # auto-import.
129 | # .idea/artifacts
130 | # .idea/compiler.xml
131 | # .idea/jarRepositories.xml
132 | # .idea/modules.xml
133 | # .idea/*.iml
134 | # .idea/modules
135 | # *.iml
136 | # *.ipr
137 |
138 | # CMake
139 | cmake-build-*/
140 |
141 | # Mongo Explorer plugin
142 | .idea/**/mongoSettings.xml
143 |
144 | # File-based project format
145 | *.iws
146 |
147 | # IntelliJ
148 | out/
149 |
150 | # mpeltonen/sbt-idea plugin
151 | .idea_modules/
152 |
153 | # JIRA plugin
154 | atlassian-ide-plugin.xml
155 |
156 | # Cursive Clojure plugin
157 | .idea/replstate.xml
158 |
159 | # Crashlytics plugin (for Android Studio and IntelliJ)
160 | com_crashlytics_export_strings.xml
161 | crashlytics.properties
162 | crashlytics-build.properties
163 | fabric.properties
164 |
165 | # Editor-based Rest Client
166 | .idea/httpRequests
167 |
168 | # Android studio 3.1+ serialized cache file
169 | .idea/caches/build_file_checksums.ser
170 |
171 | ### Intellij Patch ###
172 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
173 |
174 | # *.iml
175 | # modules.xml
176 | # .idea/misc.xml
177 | # *.ipr
178 |
179 | # Sonarlint plugin
180 | # https://plugins.jetbrains.com/plugin/7973-sonarlint
181 | .idea/**/sonarlint/
182 |
183 | # SonarQube Plugin
184 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
185 | .idea/**/sonarIssues.xml
186 |
187 | # Markdown Navigator plugin
188 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
189 | .idea/**/markdown-navigator.xml
190 | .idea/**/markdown-navigator-enh.xml
191 | .idea/**/markdown-navigator/
192 |
193 | # Cache file creation bug
194 | # See https://youtrack.jetbrains.com/issue/JBR-2257
195 | .idea/$CACHE_FILE$
196 |
197 | # CodeStream plugin
198 | # https://plugins.jetbrains.com/plugin/12206-codestream
199 | .idea/codestream.xml
200 |
201 | ### Java ###
202 | # Compiled class file
203 | *.class
204 |
205 | # Log file
206 | *.log
207 |
208 | # BlueJ files
209 | *.ctxt
210 |
211 | # Mobile Tools for Java (J2ME)
212 | .mtj.tmp/
213 |
214 | # Package Files #
215 | *.jar
216 | *.war
217 | *.nar
218 | *.ear
219 | *.zip
220 | *.tar.gz
221 | *.rar
222 |
223 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
224 | hs_err_pid*
225 |
226 | # End of https://www.toptal.com/developers/gitignore/api/intellij,java,dart,flutter
227 | *.xml
228 | *.iml
229 | src/main/resources/innotutor-324ff-firebase-adminsdk-rnv3h-d53dbeb3ba.json
230 | **/target/classes/
231 | src/main/resources/innotutor-324ff-firebase-adminsdk-rnv3h-90b3888419.json
232 | src/main/resources/innotutor-324ff-firebase-adminsdk-rnv3h-c2f46c4c6d.json
233 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007-present the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | import java.net.*;
17 | import java.io.*;
18 | import java.nio.channels.*;
19 | import java.util.Properties;
20 |
21 | public class MavenWrapperDownloader {
22 |
23 | private static final String WRAPPER_VERSION = "0.5.6";
24 | /**
25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26 | */
27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29 |
30 | /**
31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32 | * use instead of the default one.
33 | */
34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35 | ".mvn/wrapper/maven-wrapper.properties";
36 |
37 | /**
38 | * Path where the maven-wrapper.jar will be saved to.
39 | */
40 | private static final String MAVEN_WRAPPER_JAR_PATH =
41 | ".mvn/wrapper/maven-wrapper.jar";
42 |
43 | /**
44 | * Name of the property which should be used to override the default download url for the wrapper.
45 | */
46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47 |
48 | public static void main(String args[]) {
49 | System.out.println("- Downloader started");
50 | File baseDirectory = new File(args[0]);
51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52 |
53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
54 | // wrapperUrl parameter.
55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56 | String url = DEFAULT_DOWNLOAD_URL;
57 | if(mavenWrapperPropertyFile.exists()) {
58 | FileInputStream mavenWrapperPropertyFileInputStream = null;
59 | try {
60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61 | Properties mavenWrapperProperties = new Properties();
62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64 | } catch (IOException e) {
65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66 | } finally {
67 | try {
68 | if(mavenWrapperPropertyFileInputStream != null) {
69 | mavenWrapperPropertyFileInputStream.close();
70 | }
71 | } catch (IOException e) {
72 | // Ignore ...
73 | }
74 | }
75 | }
76 | System.out.println("- Downloading from: " + url);
77 |
78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79 | if(!outputFile.getParentFile().exists()) {
80 | if(!outputFile.getParentFile().mkdirs()) {
81 | System.out.println(
82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83 | }
84 | }
85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86 | try {
87 | downloadFileFromURL(url, outputFile);
88 | System.out.println("Done");
89 | System.exit(0);
90 | } catch (Throwable e) {
91 | System.out.println("- Error downloading");
92 | e.printStackTrace();
93 | System.exit(1);
94 | }
95 | }
96 |
97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99 | String username = System.getenv("MVNW_USERNAME");
100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101 | Authenticator.setDefault(new Authenticator() {
102 | @Override
103 | protected PasswordAuthentication getPasswordAuthentication() {
104 | return new PasswordAuthentication(username, password);
105 | }
106 | });
107 | }
108 | URL website = new URL(urlString);
109 | ReadableByteChannel rbc;
110 | rbc = Channels.newChannel(website.openStream());
111 | FileOutputStream fos = new FileOutputStream(destination);
112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113 | fos.close();
114 | rbc.close();
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InnoTutor/Backend/de2e308375f37ffa490ecc2443bf77601c675996/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 InnoTutor
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Backend
2 |
3 | 
4 |
5 |
ᅠ [](https://github.com/InnoTutor/Backend/blob/main/LICENSE) ᅠ [](https://hitsofcode.com/github/InnoTutor/Backend/view?branch=main)
6 | **Developers**: Daniil Livitn, Roman Soldatov
7 |
8 |
9 | ## Contents
10 | - [Requirements](#requirements)
11 | - [API](#api)
12 | - [Database](#database)
13 | - [Google credentials](#google-credentials)
14 | - [Hosting and CI](#hosting-and-ci)
15 | - [How to install locally](#how-to-install-locally)
16 | - [Code analysis](#code-analysis)
17 | - [Want to contribute?](#want-to-contribute)
18 |
19 | This is the repository with Backend code for the InnoTutor project. The backend is designed as REST API, so you need the frontend part to access it. Alternatively, you can use [Postman](https://www.postman.com) or [Swagger](https://swagger.io).
20 | The main description of the project is available [here](https://github.com/InnoTutor/README)
21 |
22 | # Requirements
23 | **Technical Stack**:
24 | * **Java, [Spring Framework](https://spring.io/projects/spring-framework), Firebase, Docker, PostgreSQL**:
25 | * IntelliJ IDEA IDE
26 | > For this open-source project, we used the simplest registration way via Google [Firebase](https://firebase.google.com)
27 | > - as a website user, you need to have a Google account
28 | > - as a developer, who is going to host this project version, you need to get your own Google credentials.
29 | >
30 | > In case of using this project in **Innopolis University** we'll change authentication to **innopolis email** login page.
31 |
32 | ## Stakeholders and their roles 👤
33 | * **Backend Development Team**
34 | * **Developer 1** – Backend developer. Implement the backend on Java/Spring which interacts with the PostgreSQL database.
35 | * **Developer 2** – Backend developer. Implement the backend on Java/Spring which returns the result to the frontend via REST API.
36 | * **Developer 3** – Backend developer. Write tests for the Backend.
37 | **Stake**: Development process
38 |
39 | # API
40 | There is documentation with all requests which backend supports.
41 | You can read about API documentation [here](https://documenter.getpostman.com/view/16213957/UUy65PgU)
42 |
43 | # Database
44 | We use Docker and PostgreSQL for the database.
45 | Here is the database [diagram](https://github.com/InnoTutor/README/blob/main/UMLDiagrams/DatabaseDiagram.md)
46 |
47 | - If you want to import our database, you can use [restore.sql](restore.sql) file with empty tables.
48 | - In [application.properties](/src/main/resources/application.properties) file specify your database's `URL`, `username` and `password`.
49 | > - Guide how to import your database: [link](https://www.postgresql.org/docs/9.1/backup-dump.html)
50 | > - Guide how to use PostgreSQL in Docker: [link](https://youtu.be/aHbE3pTyG-Q)
51 |
52 | # Google credentials
53 | To log in, you need to provide your Google credentials created [here](https://firebase.google.com).
54 | Then open [application.properties](/src/main/resources/application.properties) file and input your JSON Google credentials file as a single string in `GOOGLE_CREDENTIALS` field.
55 | You can use this online service to convert JSON into a string with escape characters: [link](https://www.freeformatter.com/json-escape.html)
56 | > In case of any problems refer to this [guide](https://medium.com/@renceabishek/how-to-add-google-api-credentials-key-on-heroku-spring-boot-16b03e2a2363)
57 |
58 | # Hosting and CI
59 | We use [Heroku](https://heroku.com/) to host the backend. [Here](https://innotutor.herokuapp.com) is the deployed version of it.
60 | For continuous integration, we have to make a pull request into the `main` branch. Then Heroku will automatically deploy a new version on the server.
61 |
62 | To build the project on Heroku's server you need to provide **config vars**: `DATABASE_URL` and `GOOGLE_CREDENTIALS`. Also, add this buildpack `https://github.com/buyersight/heroku-google-application-credentials-buildpack.git`
63 | > Guide how to work with config vars: [link](https://devcenter.heroku.com/articles/config-vars)
64 |
65 | # How to install locally
66 | - Download this project
67 | - Open it in IntelliJ IDEA
68 | - Set up database and Google credentials (check instructions above [Database](#database) and [Google credentials](#google-credentials))
69 | - Open `InnotutorBackendApplication` java class and press `ctrl+R`
70 | > Guide how to run Spring project: [link](https://www.jetbrains.com/help/idea/your-first-spring-application.html)
71 | ## Another way of install project but without IDE (note: you should have Maven installed)
72 | 1) Clone this repository to your machine using: `https://github.com/InnoTutor/Backend.git`
73 | 2) You need to create a database and specify the path to it in the `application.properties`. Besides this, you need to specify your username, password and google credentials.
Note: Path to `application.properties`: [application.properties](/src/main/resources/application.properties)
74 | ```
75 | spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/innotutor}
76 | spring.datasource.username=${SPRING_DATASOURCE_USERNAME:postgres}
77 | spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:root}
78 | ...
79 | GOOGLE_CREDENTIALS=
80 | ```
81 | 3) Using the command line, navigate to the root folder of the project and run the command:
82 | ```
83 | mvn clean install
84 | ```
85 | 4) After a successful build, you need to run the command:
86 | ```
87 | java -jar .target/innotutor_backend-0.0.1-SNAPSHOT.jar
88 |
89 | or
90 |
91 | java -jar target/innotutor_backend-0.0.1-SNAPSHOT.jar
92 | ```
93 |
94 | # Code analysis
95 | * [The result of PMD static analyzer](https://github.com/InnoTutor/README/blob/main/StaticAnaylyzer/result.md). Do not be scared by such a huge number of violations. We fixed all the violations that we could fix. Other violations can not be fixed due to spring framework-specific code which requires to follow special name convention, so the framework could understand fields and create particular [Beans](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-definition).
96 |
97 | # Want to contribute?
98 | You can contribute to this project. Just fork the repository from the `develop` branch, implement changes you want to propose and make a pull request.
99 | Also, there are [issues](https://github.com/InnoTutor/Backend/issues), so feel free to submit a new one or participate in existing.
100 |
--------------------------------------------------------------------------------
/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 "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\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/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124 |
125 | FOR /F "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%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.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% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
162 | if ERRORLEVEL 1 goto error
163 | goto end
164 |
165 | :error
166 | set ERROR_CODE=1
167 |
168 | :end
169 | @endlocal & set ERROR_CODE=%ERROR_CODE%
170 |
171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
175 | :skipRcPost
176 |
177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
179 |
180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
181 |
182 | exit /B %ERROR_CODE%
183 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.5.4
9 |
10 |
11 | innotutor
12 | innotutor_backend
13 | 0.0.1-SNAPSHOT
14 | innotutor_backend
15 | Project for the SSAD course
16 |
17 | 11
18 | 8
19 | 8
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-data-jpa
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-security
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-web
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-devtools
37 | runtime
38 | true
39 |
40 |
41 | org.postgresql
42 | postgresql
43 | runtime
44 |
45 |
46 | org.projectlombok
47 | lombok
48 | true
49 |
50 |
51 | org.modelmapper
52 | modelmapper
53 | 2.3.5
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-starter-test
58 | test
59 |
60 |
61 | org.springframework.security
62 | spring-security-test
63 | test
64 |
65 |
66 | io.zonky.test
67 | embedded-database-spring-test
68 | 2.0.1
69 | test
70 |
71 |
72 | org.springframework
73 | spring-test
74 |
75 |
76 |
77 | com.google.firebase
78 | firebase-admin
79 | 8.1.0
80 |
81 |
82 | junit
83 | junit
84 | 4.12
85 | test
86 |
87 |
88 |
89 | org.json
90 | json
91 | 20210307
92 |
93 |
94 |
95 |
96 |
97 |
98 | org.springframework.boot
99 | spring-boot-maven-plugin
100 |
101 |
102 |
103 | org.projectlombok
104 | lombok
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/InnotutorBackendApplication.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import com.google.auth.oauth2.GoogleCredentials;
5 | import com.google.firebase.FirebaseApp;
6 | import com.google.firebase.FirebaseOptions;
7 | import lombok.NoArgsConstructor;
8 | import org.json.JSONObject;
9 | import org.modelmapper.ModelMapper;
10 | import org.springframework.beans.factory.annotation.Value;
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 | import org.springframework.context.annotation.Bean;
14 | import org.springframework.context.annotation.Primary;
15 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
16 |
17 | import java.io.ByteArrayInputStream;
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 |
21 | @NoArgsConstructor
22 | @SpringBootApplication
23 | public class InnotutorBackendApplication {
24 | @Value("${GOOGLE_CREDENTIALS}")
25 | private String gservicesConfig;
26 |
27 | public static void main(final String[] args) {
28 | SpringApplication.run(InnotutorBackendApplication.class, args);
29 | }
30 |
31 | @Bean
32 | public ModelMapper modelMapper() {
33 | return new ModelMapper();
34 | }
35 |
36 | @Bean
37 | public FirebaseApp provideFirebaseOptions() throws IOException {
38 | final JSONObject jsonObject = new JSONObject(gservicesConfig);
39 | final InputStream inputStream = new ByteArrayInputStream(jsonObject.toString().getBytes()); //NOPMD - suppressed LawOfDemeter - This is not our class implementation
40 | final FirebaseOptions options = new FirebaseOptions.Builder()
41 | .setCredentials(GoogleCredentials.fromStream(inputStream))
42 | .build();
43 |
44 | return FirebaseApp.initializeApp(options);
45 | }
46 |
47 | @Bean
48 | @Primary
49 | public ObjectMapper jacksonObjectMapper(final Jackson2ObjectMapperBuilder builder) {
50 | return builder.build();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/SearcherController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller;
2 |
3 | import innotutor.innotutor_backend.dto.searcher.StudentRequestDTO;
4 | import innotutor.innotutor_backend.dto.searcher.TutorCvDTO;
5 | import innotutor.innotutor_backend.security.CustomPrincipal;
6 | import innotutor.innotutor_backend.service.SearcherService;
7 | import innotutor.innotutor_backend.service.UserService;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.http.ResponseEntity;
11 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
12 | import org.springframework.web.bind.annotation.*;
13 |
14 | import java.util.List;
15 |
16 | @RestController
17 | @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
18 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET})
19 | public class SearcherController {
20 |
21 | private final transient SearcherService searcherService;
22 | private final transient UserService userService;
23 |
24 | public SearcherController(final SearcherService searcherService, final UserService userService) {
25 | this.searcherService = searcherService;
26 | this.userService = userService;
27 | }
28 |
29 | @GetMapping(value = "/tutors-list", produces = MediaType.APPLICATION_JSON_VALUE)
30 | public ResponseEntity> getTutorsList(
31 | @RequestParam(name = "subject", required = false) final String subject,
32 | @RequestParam(name = "format", required = false) final String format,
33 | @RequestParam(name = "type", required = false) final String type,
34 | @RequestParam(name = "sorting", required = false) final String sorting,
35 | @RequestParam(name = "requested", required = false) final Boolean requested,
36 | @AuthenticationPrincipal final CustomPrincipal user) {
37 | final List tutors = searcherService.getTutorCvDTOList(subject, format, type, sorting, requested, userService.getUserId(user));
38 | return tutors == null
39 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
40 | : new ResponseEntity<>(tutors, HttpStatus.OK);
41 | }
42 |
43 | @GetMapping(value = "/students-list", produces = MediaType.APPLICATION_JSON_VALUE)
44 | public ResponseEntity> getStudentsList(
45 | @RequestParam(name = "subject", required = false) final String subject,
46 | @RequestParam(name = "format", required = false) final String format,
47 | @RequestParam(name = "type", required = false) final String type,
48 | @RequestParam(name = "offered", required = false) final Boolean offered,
49 | @AuthenticationPrincipal final CustomPrincipal user) {
50 | final List students = searcherService.getStudentRequestDTOList(subject, format, type, offered,
51 | userService.getUserId(user));
52 | return students == null
53 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
54 | : new ResponseEntity<>(students, HttpStatus.OK);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/SessionController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller;
2 |
3 | import innotutor.innotutor_backend.dto.UserDTO;
4 | import innotutor.innotutor_backend.dto.card.SessionRatingDTO;
5 | import innotutor.innotutor_backend.dto.card.SubjectDTO;
6 | import innotutor.innotutor_backend.dto.session.SessionDTO;
7 | import innotutor.innotutor_backend.dto.session.sessionsettings.SessionFormatDTO;
8 | import innotutor.innotutor_backend.dto.session.sessionsettings.SessionTypeDTO;
9 | import innotutor.innotutor_backend.security.CustomPrincipal;
10 | import innotutor.innotutor_backend.service.SessionService;
11 | import innotutor.innotutor_backend.service.UserService;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.http.MediaType;
14 | import org.springframework.http.ResponseEntity;
15 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
16 | import org.springframework.web.bind.annotation.*;
17 |
18 | import java.util.List;
19 |
20 | @RestController
21 | @RequestMapping(value = "/session", produces = MediaType.APPLICATION_JSON_VALUE)
22 | @CrossOrigin(origins = "*", allowedHeaders = "*",
23 | methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
24 | public class SessionController {
25 | private final transient SessionService sessionService;
26 | private final transient UserService userService;
27 |
28 | public SessionController(final SessionService sessionService, final UserService userService) {
29 | this.sessionService = sessionService;
30 | this.userService = userService;
31 | }
32 |
33 | @GetMapping(value = "/formats", produces = MediaType.APPLICATION_JSON_VALUE)
34 | public ResponseEntity> getSessionFormats() {
35 | return new ResponseEntity<>(sessionService.getSessionFormats(), HttpStatus.OK);
36 | }
37 |
38 | @GetMapping(value = "/types", produces = MediaType.APPLICATION_JSON_VALUE)
39 | public ResponseEntity> getSessionTypes() {
40 | return new ResponseEntity<>(sessionService.getSessionTypes(), HttpStatus.OK);
41 | }
42 |
43 | @GetMapping(value = "/subjects", produces = MediaType.APPLICATION_JSON_VALUE)
44 | public ResponseEntity> getSubjects() {
45 | return new ResponseEntity<>(sessionService.getSubjects(), HttpStatus.OK);
46 | }
47 |
48 | @GetMapping(value = "/students", produces = MediaType.APPLICATION_JSON_VALUE)
49 | public ResponseEntity> getStudents(
50 | @RequestParam(name = "subject", required = false) final String subject,
51 | @RequestParam(name = "format", required = false) final String format,
52 | @RequestParam(name = "type", required = false) final String type,
53 | @AuthenticationPrincipal final CustomPrincipal user) {
54 | final List students
55 | = sessionService.filterStudentsForSession(userService.getUserId(user), subject, format, type);
56 | return students == null
57 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
58 | : new ResponseEntity<>(students, HttpStatus.OK);
59 | }
60 |
61 | @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
62 | public ResponseEntity postSession(@RequestBody final SessionDTO sessionDTO,
63 | @AuthenticationPrincipal final CustomPrincipal user) {
64 | ResponseEntity response;
65 | if (sessionDTO == null) {
66 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
67 | } else {
68 | final SessionDTO result = sessionService.postSession(sessionDTO, userService.getUserId(user));
69 | response = result == null
70 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
71 | : new ResponseEntity<>(result, HttpStatus.CREATED);
72 | }
73 | return response;
74 | }
75 |
76 | @DeleteMapping(value = "/cancel/{sessionId}", produces = MediaType.APPLICATION_JSON_VALUE)
77 | public ResponseEntity> cancelSession(@PathVariable final Long sessionId,
78 | @AuthenticationPrincipal final CustomPrincipal user) {
79 | ResponseEntity> response;
80 | if (sessionId == null) {
81 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
82 | } else {
83 | Boolean result = sessionService.cancelSession(sessionId, userService.getUserId(user));
84 | if (result == null) {
85 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
86 | } else {
87 | response = result
88 | ? new ResponseEntity<>(HttpStatus.OK)
89 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
90 | }
91 | }
92 | return response;
93 | }
94 |
95 | @PutMapping(value = "/rate", produces = MediaType.APPLICATION_JSON_VALUE)
96 | public ResponseEntity rateSession(@RequestBody final SessionRatingDTO sessionRatingDTO,
97 | @AuthenticationPrincipal final CustomPrincipal user) {
98 | ResponseEntity response;
99 | if (sessionRatingDTO == null) {
100 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
101 | } else {
102 | final SessionRatingDTO result = sessionService.rateSession(sessionRatingDTO, userService.getUserId(user));
103 | if (result == null) {
104 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
105 | } else {
106 | response = new ResponseEntity<>(result, HttpStatus.OK);
107 | }
108 | }
109 | return response;
110 | }
111 |
112 | @DeleteMapping(value = "/rate/{sessionId}", produces = MediaType.APPLICATION_JSON_VALUE)
113 | public ResponseEntity> deleteRating(@PathVariable final Long sessionId,
114 | @AuthenticationPrincipal final CustomPrincipal user) {
115 | ResponseEntity> response;
116 | if (sessionId == null) {
117 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
118 | } else {
119 | response = sessionService.deleteRating(sessionId, userService.getUserId(user))
120 | ? new ResponseEntity<>(HttpStatus.OK)
121 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
122 |
123 | }
124 | return response;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/card/CardController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.card;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.EnrollmentDTO;
4 | import innotutor.innotutor_backend.dto.searcher.UserCard;
5 | import innotutor.innotutor_backend.security.CustomPrincipal;
6 | import innotutor.innotutor_backend.service.CardEnrollService;
7 | import innotutor.innotutor_backend.service.CardService;
8 | import innotutor.innotutor_backend.service.UserService;
9 | import org.springframework.http.HttpStatus;
10 | import org.springframework.http.MediaType;
11 | import org.springframework.http.ResponseEntity;
12 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
13 | import org.springframework.web.bind.annotation.*;
14 |
15 | @RestController
16 | @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
17 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE})
18 | public class CardController {
19 |
20 | private final transient UserService userService;
21 | private final transient CardService cardService;
22 | private final transient CardEnrollService cardEnrollService;
23 |
24 | public CardController(final UserService userService, final CardService cardService, final CardEnrollService cardEnrollService) {
25 | this.userService = userService;
26 | this.cardService = cardService;
27 | this.cardEnrollService = cardEnrollService;
28 | }
29 |
30 | @GetMapping(value = "/card/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
31 | public ResponseEntity getCard(@PathVariable final Long cardId, @AuthenticationPrincipal final CustomPrincipal user) {
32 | if (cardId == null) {
33 | new ResponseEntity<>(HttpStatus.BAD_REQUEST);
34 | }
35 | final UserCard card = cardService.getCardFullInfoById(cardId, userService.getUserId(user));
36 | return card == null
37 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
38 | : new ResponseEntity<>(card, HttpStatus.OK);
39 | }
40 |
41 | @PostMapping(value = "/enroll", produces = MediaType.APPLICATION_JSON_VALUE)
42 | public ResponseEntity postTutorCardEnroll(@RequestBody final EnrollmentDTO enrollmentDTO,
43 | @AuthenticationPrincipal final CustomPrincipal user) {
44 | ResponseEntity responseEntity;
45 | if (enrollmentDTO == null) {
46 | responseEntity = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
47 | } else {
48 | enrollmentDTO.setEnrollerId(userService.getUserId(user));
49 | final EnrollmentDTO result = cardEnrollService.postCardEnroll(enrollmentDTO);
50 | responseEntity = result == null
51 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
52 | : new ResponseEntity<>(result, HttpStatus.CREATED);
53 | }
54 | return responseEntity;
55 | }
56 |
57 | @DeleteMapping(value = "/unenroll/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
58 | public ResponseEntity> deleteCardEnrollByCardId(@PathVariable final Long cardId,
59 | @AuthenticationPrincipal final CustomPrincipal user) {
60 | ResponseEntity> response;
61 | if (cardId == null) {
62 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
63 | } else {
64 | response = cardEnrollService.deleteCardEnrollByCardId(userService.getUserId(user), cardId)
65 | ? new ResponseEntity<>(HttpStatus.OK)
66 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
67 | }
68 | return response;
69 | }
70 |
71 | public ResponseEntity> deleteCardById(final Long cardId, final CustomPrincipal user) {
72 | ResponseEntity> response;
73 | if (cardId == null) {
74 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
75 | } else {
76 | response = cardService.deleteCardById(cardId, userService.getUserId(user))
77 | ? new ResponseEntity<>(HttpStatus.OK)
78 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
79 | }
80 | return response;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/card/RequestsController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.card;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.dto.card.SubjectDTO;
5 | import innotutor.innotutor_backend.security.CustomPrincipal;
6 | import innotutor.innotutor_backend.service.CardService;
7 | import innotutor.innotutor_backend.service.CardsListService;
8 | import innotutor.innotutor_backend.service.SessionService;
9 | import innotutor.innotutor_backend.service.UserService;
10 | import org.springframework.http.HttpStatus;
11 | import org.springframework.http.MediaType;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
14 | import org.springframework.web.bind.annotation.*;
15 |
16 | import java.util.List;
17 |
18 | @RestController
19 | @RequestMapping(value = "/requests", produces = MediaType.APPLICATION_JSON_VALUE)
20 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {
21 | RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
22 | public class RequestsController {
23 |
24 | private final transient CardController cardController;
25 | private final transient CardService cardService;
26 | private final transient CardsListService cardsListService;
27 | private final transient UserService userService;
28 | private final transient SessionService sessionService;
29 |
30 | public RequestsController(final CardController cardController, final CardService cardService,
31 | final CardsListService cardsListService, final UserService userService,
32 | final SessionService sessionService) {
33 | this.cardController = cardController;
34 | this.cardService = cardService;
35 | this.cardsListService = cardsListService;
36 | this.userService = userService;
37 | this.sessionService = sessionService;
38 | }
39 |
40 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
41 | public ResponseEntity> getRequests(@AuthenticationPrincipal final CustomPrincipal user) {
42 | final List requests = cardsListService.getRequests(userService.getUserId(user));
43 | return requests == null
44 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
45 | : new ResponseEntity<>(requests, HttpStatus.OK);
46 | }
47 |
48 | @GetMapping(value = "/subjects", produces = MediaType.APPLICATION_JSON_VALUE)
49 | public ResponseEntity> getAvailableRequestSubjects(@AuthenticationPrincipal final CustomPrincipal user) {
50 | final List result = sessionService.getAvailableRequestSubjects(userService.getUserId(user));
51 | return result == null
52 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
53 | : new ResponseEntity<>(result, HttpStatus.OK);
54 | }
55 |
56 | @GetMapping(value = "/user/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
57 | public ResponseEntity> getUserRequestsById(@PathVariable final Long userId,
58 | @AuthenticationPrincipal final CustomPrincipal user) {
59 | ResponseEntity> response;
60 | if (userService.isUserEqualsId(user, userId)) {
61 | response = this.getRequests(user);
62 | } else {
63 | final List result = cardsListService.getUserRequests(userId);
64 | response = result == null
65 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
66 | : new ResponseEntity<>(result, HttpStatus.OK);
67 | }
68 | return response;
69 | }
70 |
71 | @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
72 | public ResponseEntity postRequestCard(@RequestBody final CardDTO cardDTO,
73 | @AuthenticationPrincipal final CustomPrincipal user) {
74 | ResponseEntity response;
75 | if (cardDTO == null) {
76 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
77 | } else {
78 | final CardDTO result = cardService.postRequestCard(cardDTO, userService.getUserId(user));
79 | response = result == null
80 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
81 | : new ResponseEntity<>(result, HttpStatus.CREATED);
82 | }
83 | return response;
84 | }
85 |
86 | @PutMapping(value = "/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
87 | public ResponseEntity putRequestCard(@PathVariable final Long cardId,
88 | @RequestBody final CardDTO cardDTO,
89 | @AuthenticationPrincipal final CustomPrincipal user) {
90 | ResponseEntity response;
91 | if (cardDTO == null || cardId == null) {
92 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
93 | } else {
94 | final CardDTO result = cardService.putRequestCard(cardId, cardDTO, userService.getUserId(user));
95 | if (result == null) {
96 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
97 | } else {
98 | response = new ResponseEntity<>(
99 | result,
100 | result.getCardId().equals(cardDTO.getCardId())
101 | ? HttpStatus.OK
102 | : HttpStatus.CREATED
103 | );
104 | }
105 | }
106 | return response;
107 | }
108 |
109 | @DeleteMapping(value = "/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
110 | public ResponseEntity> deleteRequestCardById(@PathVariable final Long cardId,
111 | @AuthenticationPrincipal final CustomPrincipal user) {
112 | return cardController.deleteCardById(cardId, user);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/card/ServicesController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.card;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.dto.card.SubjectDTO;
5 | import innotutor.innotutor_backend.security.CustomPrincipal;
6 | import innotutor.innotutor_backend.service.CardService;
7 | import innotutor.innotutor_backend.service.CardsListService;
8 | import innotutor.innotutor_backend.service.SessionService;
9 | import innotutor.innotutor_backend.service.UserService;
10 | import org.springframework.http.HttpStatus;
11 | import org.springframework.http.MediaType;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
14 | import org.springframework.web.bind.annotation.*;
15 |
16 | import java.util.List;
17 |
18 | @RestController
19 | @RequestMapping(value = "/services", produces = MediaType.APPLICATION_JSON_VALUE)
20 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {
21 | RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
22 | public class ServicesController {
23 |
24 | private final transient CardController cardController;
25 | private final transient CardService cardService;
26 | private final transient CardsListService cardsListService;
27 | private final transient UserService userService;
28 | private final transient SessionService sessionService;
29 |
30 | public ServicesController(final CardController cardController, final CardService cardService,
31 | final CardsListService cardsListService, final UserService userService,
32 | final SessionService sessionService) {
33 | this.cardController = cardController;
34 | this.cardService = cardService;
35 | this.cardsListService = cardsListService;
36 | this.userService = userService;
37 | this.sessionService = sessionService;
38 | }
39 |
40 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
41 | public ResponseEntity> getServices(@AuthenticationPrincipal final CustomPrincipal user) {
42 | final List services = cardsListService.getServices(userService.getUserId(user));
43 | return services == null
44 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
45 | : new ResponseEntity<>(services, HttpStatus.OK);
46 | }
47 |
48 | @GetMapping(value = "/subjects", produces = MediaType.APPLICATION_JSON_VALUE)
49 | public ResponseEntity> getAvailableSubjects(@AuthenticationPrincipal final CustomPrincipal user) {
50 | final List result = sessionService.getAvailableServiceSubjects(userService.getUserId(user));
51 | return result == null
52 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
53 | : new ResponseEntity<>(result, HttpStatus.OK);
54 | }
55 |
56 | @GetMapping(value = "/user/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
57 | public ResponseEntity> getUserServicesById(@PathVariable final Long userId,
58 | @AuthenticationPrincipal final CustomPrincipal user) {
59 | ResponseEntity> response;
60 | if (userService.isUserEqualsId(user, userId)) {
61 | response = this.getServices(user);
62 | } else {
63 | final List result = cardsListService.getUserServices(userId);
64 | response = result == null
65 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
66 | : new ResponseEntity<>(result, HttpStatus.OK);
67 | }
68 | return response;
69 | }
70 |
71 | @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
72 | public ResponseEntity postCvCard(@RequestBody final CardDTO cardDTO,
73 | @AuthenticationPrincipal final CustomPrincipal user) {
74 | ResponseEntity response;
75 | if (cardDTO == null) {
76 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
77 | } else {
78 | final CardDTO result = cardService.postCvCard(cardDTO, userService.getUserId(user));
79 | response = result == null
80 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
81 | : new ResponseEntity<>(result, HttpStatus.CREATED);
82 | }
83 | return response;
84 | }
85 |
86 | @PutMapping(value = "/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
87 | public ResponseEntity putCvCard(@PathVariable final Long cardId,
88 | @RequestBody final CardDTO cardDTO,
89 | @AuthenticationPrincipal final CustomPrincipal user) {
90 | ResponseEntity response;
91 | if (cardDTO == null || cardId == null) {
92 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
93 | } else {
94 | final CardDTO result = cardService.putCvCard(cardId, cardDTO, userService.getUserId(user));
95 | if (result == null) {
96 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
97 | } else {
98 | response = new ResponseEntity<>(
99 | result,
100 | result.getCardId().equals(cardDTO.getCardId())
101 | ? HttpStatus.OK
102 | : HttpStatus.CREATED
103 | );
104 | }
105 | }
106 | return response;
107 | }
108 |
109 | @DeleteMapping(value = "/{cardId}", produces = MediaType.APPLICATION_JSON_VALUE)
110 | public ResponseEntity> deleteCvCardById(@PathVariable final Long cardId,
111 | @AuthenticationPrincipal final CustomPrincipal user) {
112 | return cardController.deleteCardById(cardId, user);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/user/ScheduleController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.user;
2 |
3 | import innotutor.innotutor_backend.dto.session.ScheduleDTO;
4 | import innotutor.innotutor_backend.security.CustomPrincipal;
5 | import innotutor.innotutor_backend.service.SessionService;
6 | import innotutor.innotutor_backend.service.UserService;
7 | import org.springframework.http.HttpStatus;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | @RestController
14 | @RequestMapping(value = "/schedule", produces = MediaType.APPLICATION_JSON_VALUE)
15 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET})
16 | public class ScheduleController {
17 | private final transient SessionService sessionService;
18 | private final transient UserService userService;
19 |
20 | public ScheduleController(final SessionService sessionService, final UserService userService) {
21 | this.sessionService = sessionService;
22 | this.userService = userService;
23 | }
24 |
25 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
26 | public ResponseEntity getSchedule(@AuthenticationPrincipal final CustomPrincipal user) {
27 | final ScheduleDTO schedule = sessionService.getSchedule(userService.getUserId(user));
28 | return schedule == null
29 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
30 | : new ResponseEntity<>(schedule, HttpStatus.OK);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/user/StudentsController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.user;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.student.RequestedStudentsListInfoDTO;
4 | import innotutor.innotutor_backend.security.CustomPrincipal;
5 | import innotutor.innotutor_backend.service.CardEnrollService;
6 | import innotutor.innotutor_backend.service.StudentsService;
7 | import innotutor.innotutor_backend.service.UserService;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.http.ResponseEntity;
11 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
12 | import org.springframework.web.bind.annotation.*;
13 |
14 | @RestController
15 | @RequestMapping(value = "/my-students", produces = MediaType.APPLICATION_JSON_VALUE)
16 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.PUT, RequestMethod.DELETE})
17 | public class StudentsController {
18 | private final transient StudentsService studentsService;
19 | private final transient CardEnrollService cardEnrollService;
20 | private final transient UserService userService;
21 |
22 | public StudentsController(final StudentsService studentsService, final CardEnrollService cardEnrollService, final UserService userService) {
23 | this.studentsService = studentsService;
24 | this.cardEnrollService = cardEnrollService;
25 | this.userService = userService;
26 | }
27 |
28 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
29 | public ResponseEntity getStudentsList(@AuthenticationPrincipal final CustomPrincipal user) {
30 | final RequestedStudentsListInfoDTO students = studentsService.getUserStudentsListFullInfo(userService.getUserId(user));
31 | return students == null
32 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
33 | : new ResponseEntity<>(students, HttpStatus.OK);
34 | }
35 |
36 | @PutMapping(value = "accept/{enrollmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
37 | public ResponseEntity> acceptStudent(@PathVariable final Long enrollmentId, @AuthenticationPrincipal final CustomPrincipal user) {
38 | ResponseEntity> response;
39 | if (enrollmentId == null) {
40 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
41 | } else {
42 | response = cardEnrollService.acceptStudent(userService.getUserId(user), enrollmentId)
43 | ? new ResponseEntity<>(HttpStatus.OK)
44 | : new ResponseEntity<>(HttpStatus.BAD_REQUEST);
45 | }
46 | return response;
47 | }
48 |
49 | @DeleteMapping(value = "remove/{enrollmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
50 | public ResponseEntity> removeStudent(@PathVariable final Long enrollmentId, @AuthenticationPrincipal final CustomPrincipal user) {
51 | ResponseEntity> response;
52 | if (enrollmentId == null) {
53 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
54 | } else {
55 | response = cardEnrollService.removeStudent(userService.getUserId(user), enrollmentId)
56 | ? new ResponseEntity<>(HttpStatus.OK)
57 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
58 | }
59 | return response;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/user/TutorsController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.user;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.tutor.RespondedTutorsListInfoDTO;
4 | import innotutor.innotutor_backend.security.CustomPrincipal;
5 | import innotutor.innotutor_backend.service.CardEnrollService;
6 | import innotutor.innotutor_backend.service.TutorsService;
7 | import innotutor.innotutor_backend.service.UserService;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.http.ResponseEntity;
11 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
12 | import org.springframework.web.bind.annotation.*;
13 |
14 | @RestController
15 | @RequestMapping(value = "/my-tutors", produces = MediaType.APPLICATION_JSON_VALUE)
16 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.PUT, RequestMethod.DELETE})
17 | public class TutorsController {
18 | private final transient TutorsService tutorsService;
19 | private final transient CardEnrollService cardEnrollService;
20 | private final transient UserService userService;
21 |
22 | public TutorsController(final TutorsService tutorsService,
23 | final CardEnrollService cardEnrollService,
24 | final UserService userService) {
25 | this.tutorsService = tutorsService;
26 | this.cardEnrollService = cardEnrollService;
27 | this.userService = userService;
28 | }
29 |
30 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
31 | public ResponseEntity getTutorsList(
32 | @AuthenticationPrincipal final CustomPrincipal user) {
33 | final RespondedTutorsListInfoDTO tutors
34 | = tutorsService.getUserTutorsListFullInfo(userService.getUserId(user));
35 | return tutors == null
36 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
37 | : new ResponseEntity<>(tutors, HttpStatus.OK);
38 | }
39 |
40 | @PutMapping(value = "accept/{enrollmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
41 | public ResponseEntity> acceptTutor(@PathVariable final Long enrollmentId,
42 | @AuthenticationPrincipal final CustomPrincipal user) {
43 | ResponseEntity> response;
44 | if (enrollmentId == null) {
45 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
46 | } else {
47 | response = cardEnrollService.acceptTutor(userService.getUserId(user), enrollmentId)
48 | ? new ResponseEntity<>(HttpStatus.OK)
49 | : new ResponseEntity<>(HttpStatus.BAD_REQUEST);
50 | }
51 | return response;
52 | }
53 |
54 | @DeleteMapping(value = "remove/{enrollmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
55 | public ResponseEntity> removeTutor(@PathVariable final Long enrollmentId,
56 | @AuthenticationPrincipal final CustomPrincipal user) {
57 | ResponseEntity> response;
58 | if (enrollmentId == null) {
59 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
60 | } else {
61 | response = cardEnrollService.removeTutor(userService.getUserId(user), enrollmentId)
62 | ? new ResponseEntity<>(HttpStatus.OK)
63 | : new ResponseEntity<>(HttpStatus.NOT_FOUND);
64 | }
65 | return response;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/user/UserController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.user;
2 |
3 | import innotutor.innotutor_backend.dto.UserDTO;
4 | import innotutor.innotutor_backend.security.CustomPrincipal;
5 | import innotutor.innotutor_backend.service.UserService;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.MediaType;
8 | import org.springframework.http.ResponseEntity;
9 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
10 | import org.springframework.web.bind.annotation.*;
11 |
12 | @RestController
13 | @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
14 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.PUT})
15 | public class UserController {
16 |
17 | private final transient UserService userService;
18 |
19 | public UserController(final UserService userService) {
20 | this.userService = userService;
21 | }
22 |
23 | @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
24 | public ResponseEntity homePage(@AuthenticationPrincipal final CustomPrincipal user) {
25 | return this.getUserProfile(user);
26 | }
27 |
28 | @GetMapping(value = "/user/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
29 | public ResponseEntity getUserById(@PathVariable final Long userId, @AuthenticationPrincipal final CustomPrincipal user) {
30 | ResponseEntity response;
31 | if (userService.isUserEqualsId(user, userId)) {
32 | response = this.getUserProfile(user);
33 | } else {
34 | final UserDTO userDTO = userService.getUserById(userId);
35 | response = userDTO == null
36 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
37 | : new ResponseEntity<>(userDTO, HttpStatus.OK);
38 | }
39 | return response;
40 | }
41 |
42 | @GetMapping(value = "/profile", produces = MediaType.APPLICATION_JSON_VALUE)
43 | public ResponseEntity getUserProfile(@AuthenticationPrincipal final CustomPrincipal user) {
44 | ResponseEntity response;
45 | final String email = user.getEmail();
46 | final UserDTO userDTO = userService.getUserByEmail(email);
47 | if (userDTO == null) {
48 | if (userService.addUserToDatabase(user)) {
49 | response = new ResponseEntity<>(userService.getUserByEmail(email), HttpStatus.CREATED);
50 | } else {
51 | response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
52 | }
53 | } else {
54 | response = new ResponseEntity<>(userDTO, HttpStatus.OK);
55 | }
56 | return response;
57 | }
58 |
59 | @PutMapping(value = "/profile", produces = MediaType.APPLICATION_JSON_VALUE)
60 | public ResponseEntity updateUserProfile(@RequestBody final UserDTO userDTO,
61 | @AuthenticationPrincipal final CustomPrincipal user) {
62 | ResponseEntity response;
63 | if (userDTO == null) {
64 | response = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
65 | } else {
66 | userDTO.setUserId(userService.getUserId(user));
67 | userDTO.setPicture(user.getPicture());
68 | final UserDTO result = userService.updateUserProfile(userDTO);
69 | response = result == null
70 | ? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
71 | : new ResponseEntity<>(result, HttpStatus.OK);
72 | }
73 | return response;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/controller/user/WaitingListController.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.controller.user;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.WaitingListDTO;
4 | import innotutor.innotutor_backend.security.CustomPrincipal;
5 | import innotutor.innotutor_backend.service.CardEnrollService;
6 | import innotutor.innotutor_backend.service.UserService;
7 | import org.springframework.http.HttpStatus;
8 | import org.springframework.http.MediaType;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | @RestController
14 | @RequestMapping(value = "/waiting-list", produces = MediaType.APPLICATION_JSON_VALUE)
15 | @CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET})
16 | public class WaitingListController {
17 | private final transient CardEnrollService cardEnrollService;
18 | private final transient UserService userService;
19 |
20 | public WaitingListController(final CardEnrollService cardEnrollService, final UserService userService) {
21 | this.cardEnrollService = cardEnrollService;
22 | this.userService = userService;
23 | }
24 |
25 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
26 | public ResponseEntity getWaitingList(@AuthenticationPrincipal final CustomPrincipal user) {
27 | final WaitingListDTO waitingList = cardEnrollService.getWaitingList(userService.getUserId(user));
28 | return waitingList == null
29 | ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
30 | : new ResponseEntity<>(waitingList, HttpStatus.OK);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/UserDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class UserDTO {
11 | private Long userId;
12 | private String name;
13 | private String surname;
14 | private String email;
15 | private String contacts;
16 | private String description;
17 | private String picture;
18 | // Upcoming events
19 | //private SessionsListDTO sessionsList;
20 | // You provide help via creating own CV cards
21 | //private List servicesList;
22 | // Students who requested to your CV cards
23 | //private RequestedStudentsListDTO myStudentsList;
24 | // You ask for help via creating own Request Card
25 | //private List requestsList;
26 | // Tutors who responded to your Request cards
27 | //private RespondedTutorsListDTO myTutorsList;
28 | // Cards to which you assigned or asked to be
29 | //private AssignedCardsDTO assignedCardsList;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/card/CardDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.card;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class CardDTO {
13 | private Long cardId;
14 | private Long creatorId;
15 | private String subject;
16 | private Double rating;
17 | private Integer countVoted;
18 | private String description;
19 | private boolean hidden;
20 | private List sessionFormat;
21 | private List sessionType;
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/card/SessionRatingDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.card;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class SessionRatingDTO {
11 | private Long sessionId;
12 | private Integer mark;
13 | private String feedback;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/card/SubjectDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.card;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class SubjectDTO {
11 | private Long subjectId;
12 | private String name;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/EnrollmentDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class EnrollmentDTO {
13 | private Long enrollmentId;
14 | private Long enrollerId;
15 | private Long cardId;
16 | private String description;
17 | private List sessionFormat;
18 | private List sessionType;
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/WaitingListDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class WaitingListDTO {
13 | private List studentsRequested;
14 | private List studentsRejected;
15 | private List tutorsRequested;
16 | private List tutorsRejected;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/student/MyStudentDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.student;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class MyStudentDTO {
13 | private Long enrollmentId;
14 | private Long studentId;
15 | private String studentName;
16 | private String studentSurname;
17 | private String studentEmail;
18 | private String studentContacts;
19 | private String studentDescription;
20 | private String studentPicture;
21 | private Long cardId;
22 | private String subject;
23 | private Double cardRating;
24 | private Integer cardCountVoted;
25 | private String cardDescription;
26 | private Boolean hidden;
27 | private String enrollmentDescription;
28 | private List sessionFormat;
29 | private List sessionType;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/student/RequestedStudentsListDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.student;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.EnrollmentDTO;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.List;
9 |
10 | @Data
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | public class RequestedStudentsListDTO {
14 | private List newStudents;
15 | private List acceptedStudents;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/student/RequestedStudentsListInfoDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.student;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class RequestedStudentsListInfoDTO {
13 | private List newStudents;
14 | private List acceptedStudents;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/tutor/MyTutorDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.tutor;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class MyTutorDTO {
13 | private Long enrollmentId;
14 | private Long tutorId;
15 | private String tutorName;
16 | private String tutorSurname;
17 | private String tutorEmail;
18 | private String tutorContacts;
19 | private String tutorDescription;
20 | private String tutorPicture;
21 | private Long cardId;
22 | private String subject;
23 | private String cardDescription;
24 | private Boolean hidden;
25 | private String enrollmentDescription;
26 | private List sessionFormat;
27 | private List sessionType;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/tutor/RespondedTutorsListDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.tutor;
2 |
3 | import innotutor.innotutor_backend.dto.enrollment.EnrollmentDTO;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.List;
9 |
10 | @Data
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | public class RespondedTutorsListDTO {
14 | private List newTutors;
15 | private List acceptedTutors;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/enrollment/tutor/RespondedTutorsListInfoDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.enrollment.tutor;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class RespondedTutorsListInfoDTO {
13 | private List newTutors;
14 | private List acceptedTutors;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/searcher/StudentRequestDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.searcher;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | import java.util.List;
10 |
11 | @Data
12 | @NoArgsConstructor
13 | @AllArgsConstructor
14 | public class StudentRequestDTO implements UserCard {
15 | private Long studentId;
16 | private String studentName;
17 | private String studentSurname;
18 | private Long cardId;
19 | private String description;
20 | private String subject;
21 | private List sessionFormat;
22 | private List sessionType;
23 | private Boolean offered;
24 |
25 | @Override
26 | @JsonIgnore
27 | @JsonProperty("creatorId")
28 | public Long getCreatorId() {
29 | return studentId;
30 | }
31 |
32 | @Override
33 | @JsonIgnore
34 | @JsonProperty("enrolled")
35 | public Boolean isEnrolled() {
36 | return offered;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/searcher/TutorCvDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.searcher;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | import java.util.List;
10 |
11 | @Data
12 | @NoArgsConstructor
13 | @AllArgsConstructor
14 | public class TutorCvDTO implements UserCard {
15 | private Long tutorId;
16 | private String tutorName;
17 | private String tutorSurname;
18 | private Long cardId;
19 | private Double rating;
20 | private Integer countVoted;
21 | private String description;
22 | private String subject;
23 | private List sessionFormat;
24 | private List sessionType;
25 | private Boolean requested;
26 |
27 | @Override
28 | @JsonIgnore
29 | @JsonProperty("creatorId")
30 | public Long getCreatorId() {
31 | return tutorId;
32 | }
33 |
34 | @Override
35 | @JsonIgnore
36 | @JsonProperty("enrolled")
37 | public Boolean isEnrolled() {
38 | return requested;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/searcher/UserCard.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.searcher;
2 |
3 | import java.util.List;
4 |
5 | public interface UserCard {
6 | Long getCreatorId();
7 |
8 | String getSubject();
9 |
10 | List getSessionFormat();
11 |
12 | List getSessionType();
13 |
14 | Boolean isEnrolled();
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/session/ScheduleDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.session;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | public class ScheduleDTO {
13 | private List studyingSessionsConducted;
14 | private List studyingSessionsUpcoming;
15 | private List teachingSessionsConducted;
16 | private List teachingSessionsUpcoming;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/session/SessionDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.session;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.time.LocalDateTime;
9 | import java.util.List;
10 |
11 | @Data
12 | @NoArgsConstructor
13 | @AllArgsConstructor
14 | public class SessionDTO {
15 | private Long sessionId;
16 | private Long tutorId;
17 | private List studentIDsList;
18 | private String subject;
19 | @JsonFormat(pattern = "yyyy-MM-dd@HH:mm:ss.SSSSSS")
20 | private LocalDateTime startTime;
21 | @JsonFormat(pattern = "yyyy-MM-dd@HH:mm:ss.SSSSSS")
22 | private LocalDateTime endTime;
23 | private String sessionFormat;
24 | private String sessionType;
25 | private String description;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/session/sessionsettings/SessionFormatDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.session.sessionsettings;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class SessionFormatDTO {
11 | private Long sessionFormatId;
12 | private String name;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/dto/session/sessionsettings/SessionTypeDTO.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.dto.session.sessionsettings;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class SessionTypeDTO {
11 | private Long sessionTypeId;
12 | private String name;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/Card.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnroll;
4 | import innotutor.innotutor_backend.entity.session.Subject;
5 | import innotutor.innotutor_backend.entity.user.Request;
6 | import innotutor.innotutor_backend.entity.user.Service;
7 | import lombok.NoArgsConstructor;
8 |
9 | import javax.persistence.*;
10 | import java.sql.Timestamp;
11 | import java.util.Collection;
12 | import java.util.Objects;
13 |
14 | @NoArgsConstructor
15 | @Entity
16 | @Table(name = "card", schema = "public", catalog = "innotutor")
17 | public class Card { //NOPMD - suppressed ShortClassName - It has the same database table name.
18 | private final static String CARD_BY_CARD_ID = "cardByCardId";
19 | // So, we follow such convention
20 | private Long cardId;
21 | private Long subjectId;
22 | private String description;
23 | private Boolean hidden;
24 | private Timestamp creationDate;
25 | private Timestamp lastUpdate;
26 | private Subject subjectBySubjectId;
27 | private Request requestByCardId;
28 | private Service serviceByCardId;
29 | private Collection cardEnrollsByCardId;
30 | private Collection cardSessionFormatsByCardId;
31 | private Collection cardSessionTypesByCardId;
32 |
33 | public Card(final Long subjectId, final String description, final Boolean hidden, final Subject subjectBySubjectId) {
34 | this.subjectId = subjectId;
35 | this.description = description;
36 | this.hidden = hidden;
37 | this.subjectBySubjectId = subjectBySubjectId;
38 | }
39 |
40 | @Id
41 | @GeneratedValue(strategy = GenerationType.IDENTITY)
42 | @Column(name = "card_id", nullable = false)
43 | public Long getCardId() {
44 | return cardId;
45 | }
46 |
47 | public void setCardId(final Long cardId) {
48 | this.cardId = cardId;
49 | }
50 |
51 | @Basic
52 | @Column(name = "subject_id", nullable = false, insertable = false, updatable = false)
53 | public Long getSubjectId() {
54 | return subjectId;
55 | }
56 |
57 | public void setSubjectId(final Long subjectId) {
58 | this.subjectId = subjectId;
59 | }
60 |
61 | @Basic
62 | @Column(name = "description", length = 1024)
63 | public String getDescription() {
64 | return description;
65 | }
66 |
67 | public void setDescription(final String description) {
68 | this.description = description;
69 | }
70 |
71 | @Basic
72 | @Column(name = "hidden", nullable = false)
73 | public Boolean getHidden() {
74 | return hidden;
75 | }
76 |
77 | public void setHidden(final Boolean hidden) {
78 | this.hidden = hidden;
79 | }
80 |
81 | @Basic
82 | @Column(name = "creation_date")
83 | public Timestamp getCreationDate() {
84 | return creationDate;
85 | }
86 |
87 | public void setCreationDate(final Timestamp creationDate) {
88 | this.creationDate = creationDate;
89 | }
90 |
91 | @Basic
92 | @Column(name = "last_update")
93 | public Timestamp getLastUpdate() {
94 | return lastUpdate;
95 | }
96 |
97 | public void setLastUpdate(final Timestamp lastUpdate) {
98 | this.lastUpdate = lastUpdate;
99 | }
100 |
101 | @Override
102 | public boolean equals(final Object object) {
103 | if (this == object) {
104 | return true;
105 | }
106 | if (object == null || getClass() != object.getClass()) {
107 | return false;
108 | }
109 | final Card card = (Card) object;
110 | if (!Objects.equals(cardId, card.cardId)) {
111 | return false;
112 | }
113 | if (!Objects.equals(subjectId, card.subjectId)) {
114 | return false;
115 | }
116 | if (!Objects.equals(description, card.description)) {
117 | return false;
118 | }
119 | if (!Objects.equals(creationDate, card.creationDate)) {
120 | return false;
121 | }
122 | return Objects.equals(lastUpdate, card.lastUpdate);
123 | }
124 |
125 | @Override
126 | public int hashCode() {
127 | int result = cardId == null ? 0 : cardId.hashCode();
128 | result = 31 * result + (subjectId == null ? 0 : subjectId.hashCode());
129 | result = 31 * result + (description == null ? 0 : description.hashCode());
130 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
131 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
132 | return result;
133 | }
134 |
135 | @ManyToOne
136 | @JoinColumn(name = "subject_id", referencedColumnName = "subject_id", nullable = false)
137 | public Subject getSubjectBySubjectId() {
138 | return subjectBySubjectId;
139 | }
140 |
141 | public void setSubjectBySubjectId(final Subject subjectBySubjectId) {
142 | this.subjectBySubjectId = subjectBySubjectId;
143 | }
144 |
145 | @OneToMany(mappedBy = CARD_BY_CARD_ID, cascade = CascadeType.REMOVE, orphanRemoval = true)
146 | public Collection getCardEnrollsByCardId() {
147 | return cardEnrollsByCardId;
148 | }
149 |
150 | public void setCardEnrollsByCardId(final Collection cardEnrollsByCardId) {
151 | this.cardEnrollsByCardId = cardEnrollsByCardId;
152 | }
153 |
154 | @OneToMany(mappedBy = CARD_BY_CARD_ID)
155 | public Collection getCardSessionFormatsByCardId() {
156 | return cardSessionFormatsByCardId;
157 | }
158 |
159 | public void setCardSessionFormatsByCardId(final Collection cardSessionFormatsByCardId) {
160 | this.cardSessionFormatsByCardId = cardSessionFormatsByCardId;
161 | }
162 |
163 | @OneToMany(mappedBy = CARD_BY_CARD_ID)
164 | public Collection getCardSessionTypesByCardId() {
165 | return cardSessionTypesByCardId;
166 | }
167 |
168 | public void setCardSessionTypesByCardId(final Collection cardSessionTypesByCardId) {
169 | this.cardSessionTypesByCardId = cardSessionTypesByCardId;
170 | }
171 |
172 | @OneToOne(mappedBy = CARD_BY_CARD_ID)
173 | public Request getRequestByCardId() {
174 | return requestByCardId;
175 | }
176 |
177 | public void setRequestByCardId(final Request requestByCardId) {
178 | this.requestByCardId = requestByCardId;
179 | }
180 |
181 | @OneToOne(mappedBy = CARD_BY_CARD_ID)
182 | public Service getServiceByCardId() {
183 | return serviceByCardId;
184 | }
185 |
186 | public void setServiceByCardId(final Service serviceByCardId) {
187 | this.serviceByCardId = serviceByCardId;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/CardSessionFormat.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionFormat;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "card_session_format", schema = "public", catalog = "innotutor")
12 | public class CardSessionFormat {
13 | private Long cardId;
14 | private Long sessionFormatId;
15 | private Long cardSessionFormatId;
16 | private Card cardByCardId;
17 | private SessionFormat sessionFormatBySessionFormatId;
18 |
19 | public CardSessionFormat(final Long cardId, final Long sessionFormatId, final Card cardByCardId, final SessionFormat sessionFormatBySessionFormatId) {
20 | this.cardId = cardId;
21 | this.sessionFormatId = sessionFormatId;
22 | this.cardByCardId = cardByCardId;
23 | this.sessionFormatBySessionFormatId = sessionFormatBySessionFormatId;
24 | }
25 |
26 | @Basic
27 | @Column(name = "card_id", nullable = false, insertable = false, updatable = false)
28 | public Long getCardId() {
29 | return cardId;
30 | }
31 |
32 | public void setCardId(final Long cardId) {
33 | this.cardId = cardId;
34 | }
35 |
36 | @Basic
37 | @Column(name = "session_format_id", nullable = false, insertable = false, updatable = false)
38 | public Long getSessionFormatId() {
39 | return sessionFormatId;
40 | }
41 |
42 | public void setSessionFormatId(final Long sessionFormatId) {
43 | this.sessionFormatId = sessionFormatId;
44 | }
45 |
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | @Column(name = "card_session_format_id", nullable = false)
49 | public Long getCardSessionFormatId() {
50 | return cardSessionFormatId;
51 | }
52 |
53 | public void setCardSessionFormatId(final Long cardSessionFormatId) {
54 | this.cardSessionFormatId = cardSessionFormatId;
55 | }
56 |
57 | @Override
58 | public boolean equals(final Object object) {
59 | if (this == object) {
60 | return true;
61 | }
62 | if (object == null || getClass() != object.getClass()) {
63 | return false;
64 | }
65 | final CardSessionFormat that = (CardSessionFormat) object;
66 | if (!Objects.equals(cardId, that.cardId)) {
67 | return false;
68 | }
69 | if (!Objects.equals(sessionFormatId, that.sessionFormatId)) {
70 | return false;
71 | }
72 | return Objects.equals(cardSessionFormatId, that.cardSessionFormatId);
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | int result = cardId == null ? 0 : cardId.hashCode();
78 | result = 31 * result + (sessionFormatId == null ? 0 : sessionFormatId.hashCode());
79 | result = 31 * result + (cardSessionFormatId == null ? 0 : cardSessionFormatId.hashCode());
80 | return result;
81 | }
82 |
83 | @ManyToOne
84 | @JoinColumn(name = "card_id", referencedColumnName = "card_id", nullable = false)
85 | public Card getCardByCardId() {
86 | return cardByCardId;
87 | }
88 |
89 | public void setCardByCardId(final Card cardByCardId) {
90 | this.cardByCardId = cardByCardId;
91 | }
92 |
93 | @ManyToOne
94 | @JoinColumn(name = "session_format_id", referencedColumnName = "session_format_id", nullable = false)
95 | public SessionFormat getSessionFormatBySessionFormatId() {
96 | return sessionFormatBySessionFormatId;
97 | }
98 |
99 | public void setSessionFormatBySessionFormatId(final SessionFormat sessionFormatBySessionFormatId) {
100 | this.sessionFormatBySessionFormatId = sessionFormatBySessionFormatId;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/CardSessionType.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionType;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "card_session_type", schema = "public", catalog = "innotutor")
12 | public class CardSessionType {
13 | private Long cardId;
14 | private Long sessionTypeId;
15 | private Long cardSessionTypeId;
16 | private Card cardByCardId;
17 | private SessionType sessionTypeBySessionTypeId;
18 |
19 | public CardSessionType(final Long cardId, final Long sessionTypeId, final Card cardByCardId, final SessionType sessionTypeBySessionTypeId) {
20 | this.cardId = cardId;
21 | this.sessionTypeId = sessionTypeId;
22 | this.cardByCardId = cardByCardId;
23 | this.sessionTypeBySessionTypeId = sessionTypeBySessionTypeId;
24 | }
25 |
26 | @Basic
27 | @Column(name = "card_id", nullable = false, insertable = false, updatable = false)
28 | public Long getCardId() {
29 | return cardId;
30 | }
31 |
32 | public void setCardId(final Long cardId) {
33 | this.cardId = cardId;
34 | }
35 |
36 | @Basic
37 | @Column(name = "session_type_id", nullable = false, insertable = false, updatable = false)
38 | public Long getSessionTypeId() {
39 | return sessionTypeId;
40 | }
41 |
42 | public void setSessionTypeId(final Long sessionTypeId) {
43 | this.sessionTypeId = sessionTypeId;
44 | }
45 |
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | @Column(name = "card_session_type_id", nullable = false)
49 | public Long getCardSessionTypeId() {
50 | return cardSessionTypeId;
51 | }
52 |
53 | public void setCardSessionTypeId(final Long cardSessionTypeId) {
54 | this.cardSessionTypeId = cardSessionTypeId;
55 | }
56 |
57 | @Override
58 | public boolean equals(final Object object) {
59 | if (this == object) {
60 | return true;
61 | }
62 | if (object == null || getClass() != object.getClass()) {
63 | return false;
64 | }
65 | final CardSessionType that = (CardSessionType) object;
66 | if (!Objects.equals(cardId, that.cardId)) {
67 | return false;
68 | }
69 | if (!Objects.equals(sessionTypeId, that.sessionTypeId)) {
70 | return false;
71 | }
72 | return Objects.equals(cardSessionTypeId, that.cardSessionTypeId);
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | int result = cardId == null ? 0 : cardId.hashCode();
78 | result = 31 * result + (sessionTypeId == null ? 0 : sessionTypeId.hashCode());
79 | result = 31 * result + (cardSessionTypeId == null ? 0 : cardSessionTypeId.hashCode());
80 | return result;
81 | }
82 |
83 | @ManyToOne
84 | @JoinColumn(name = "card_id", referencedColumnName = "card_id", nullable = false)
85 | public Card getCardByCardId() {
86 | return cardByCardId;
87 | }
88 |
89 | public void setCardByCardId(final Card cardByCardId) {
90 | this.cardByCardId = cardByCardId;
91 | }
92 |
93 | @ManyToOne
94 | @JoinColumn(name = "session_type_id", referencedColumnName = "session_type_id", nullable = false)
95 | public SessionType getSessionTypeBySessionTypeId() {
96 | return sessionTypeBySessionTypeId;
97 | }
98 |
99 | public void setSessionTypeBySessionTypeId(final SessionType sessionTypeBySessionTypeId) {
100 | this.sessionTypeBySessionTypeId = sessionTypeBySessionTypeId;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/enrollment/CardEnroll.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import innotutor.innotutor_backend.entity.user.User;
5 | import lombok.NoArgsConstructor;
6 | import org.hibernate.annotations.CreationTimestamp;
7 | import org.hibernate.annotations.UpdateTimestamp;
8 |
9 | import javax.persistence.*;
10 | import java.sql.Timestamp;
11 | import java.util.Collection;
12 | import java.util.Objects;
13 |
14 | @NoArgsConstructor
15 | @Entity
16 | @Table(name = "card_enroll", schema = "public", catalog = "innotutor")
17 | public class CardEnroll {
18 | private Long cardEnrollId;
19 | private Long cardId;
20 | private Long userId;
21 | private Long statusId;
22 | private String description;
23 | private Timestamp creationDate;
24 | private Timestamp lastUpdate;
25 | private Card cardByCardId;
26 | private User userByUserId;
27 | private EnrollmentStatus enrollmentStatusByStatusId;
28 | private Collection cardEnrollSessionFormatsByCardId;
29 | private Collection cardEnrollSessionTypesByCardId;
30 |
31 | public CardEnroll(final Long cardId, final Long userId, final Long statusId, final String description,
32 | final Card cardByCardId, final User userByUserId,
33 | final EnrollmentStatus enrollmentStatusByStatusId) {
34 | this.cardId = cardId;
35 | this.userId = userId;
36 | this.statusId = statusId;
37 | this.description = description;
38 | this.cardByCardId = cardByCardId;
39 | this.userByUserId = userByUserId;
40 | this.enrollmentStatusByStatusId = enrollmentStatusByStatusId;
41 | }
42 |
43 | @Id
44 | @GeneratedValue(strategy = GenerationType.IDENTITY)
45 | @Column(name = "card_enroll_id", nullable = false)
46 | public Long getCardEnrollId() {
47 | return cardEnrollId;
48 | }
49 |
50 | public void setCardEnrollId(final Long cardEnrollId) {
51 | this.cardEnrollId = cardEnrollId;
52 | }
53 |
54 | @Basic
55 | @Column(name = "card_id", nullable = false, insertable = false, updatable = false)
56 | public Long getCardId() {
57 | return cardId;
58 | }
59 |
60 | public void setCardId(final Long cardId) {
61 | this.cardId = cardId;
62 | }
63 |
64 | @Basic
65 | @Column(name = "user_id", nullable = false, insertable = false, updatable = false)
66 | public Long getUserId() {
67 | return userId;
68 | }
69 |
70 | public void setUserId(final Long userId) {
71 | this.userId = userId;
72 | }
73 |
74 | @Basic
75 | @Column(name = "status_id", nullable = false, insertable = false, updatable = false)
76 | public Long getStatusId() {
77 | return statusId;
78 | }
79 |
80 | public void setStatusId(final Long statusId) {
81 | this.statusId = statusId;
82 | }
83 |
84 | @Basic
85 | @Column(name = "description", length = 1024)
86 | public String getDescription() {
87 | return description;
88 | }
89 |
90 | public void setDescription(final String description) {
91 | this.description = description;
92 | }
93 |
94 | @Basic
95 | @CreationTimestamp
96 | @Column(name = "creation_date", insertable = false, updatable = false)
97 | public Timestamp getCreationDate() {
98 | return creationDate;
99 | }
100 |
101 | public void setCreationDate(final Timestamp creationDate) {
102 | this.creationDate = creationDate;
103 | }
104 |
105 | @Basic
106 | @UpdateTimestamp
107 | @Column(name = "last_update", insertable = false)
108 | public Timestamp getLastUpdate() {
109 | return lastUpdate;
110 | }
111 |
112 | public void setLastUpdate(final Timestamp lastUpdate) {
113 | this.lastUpdate = lastUpdate;
114 | }
115 |
116 | @Override
117 | public boolean equals(final Object object) {
118 | if (this == object) {
119 | return true;
120 | }
121 | if (object == null || getClass() != object.getClass()) {
122 | return false;
123 | }
124 | final CardEnroll cardEnroll = (CardEnroll) object;
125 | if (!Objects.equals(cardEnrollId, cardEnroll.cardEnrollId)) {
126 | return false;
127 | }
128 | if (!Objects.equals(cardId, cardEnroll.cardId)) {
129 | return false;
130 | }
131 | if (!Objects.equals(userId, cardEnroll.userId)) {
132 | return false;
133 | }
134 | if (!Objects.equals(statusId, cardEnroll.statusId)) {
135 | return false;
136 | }
137 | if (!Objects.equals(description, cardEnroll.description)) {
138 | return false;
139 | }
140 | if (!Objects.equals(creationDate, cardEnroll.creationDate)) {
141 | return false;
142 | }
143 | return Objects.equals(lastUpdate, cardEnroll.lastUpdate);
144 | }
145 |
146 | @Override
147 | public int hashCode() {
148 | int result = cardEnrollId == null ? 0 : cardEnrollId.hashCode();
149 | result = 31 * result + (cardId == null ? 0 : cardId.hashCode());
150 | result = 31 * result + (userId == null ? 0 : userId.hashCode());
151 | result = 31 * result + (statusId == null ? 0 : statusId.hashCode());
152 | result = 31 * result + (description == null ? 0 : description.hashCode());
153 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
154 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
155 | return result;
156 | }
157 |
158 | @ManyToOne
159 | @JoinColumn(name = "card_id", referencedColumnName = "card_id", nullable = false)
160 | public Card getCardByCardId() {
161 | return cardByCardId;
162 | }
163 |
164 | public void setCardByCardId(final Card cardByCardId) {
165 | this.cardByCardId = cardByCardId;
166 | }
167 |
168 | @ManyToOne
169 | @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
170 | public User getUserByUserId() {
171 | return userByUserId;
172 | }
173 |
174 | public void setUserByUserId(final User userByUserId) {
175 | this.userByUserId = userByUserId;
176 | }
177 |
178 | @ManyToOne
179 | @JoinColumn(name = "status_id", referencedColumnName = "status_id", nullable = false)
180 | public EnrollmentStatus getEnrollmentStatusByStatusId() {
181 | return enrollmentStatusByStatusId;
182 | }
183 |
184 | public void setEnrollmentStatusByStatusId(final EnrollmentStatus enrollmentStatusByStatusId) {
185 | this.enrollmentStatusByStatusId = enrollmentStatusByStatusId;
186 | }
187 |
188 | @OneToMany(mappedBy = "cardEnrollByCardEnrollId", orphanRemoval = true)
189 | public Collection getCardEnrollSessionFormatsByCardId() {
190 | return cardEnrollSessionFormatsByCardId;
191 | }
192 |
193 | public void setCardEnrollSessionFormatsByCardId(final Collection cardEnrollSessionFormatsByCardId) {
194 | this.cardEnrollSessionFormatsByCardId = cardEnrollSessionFormatsByCardId;
195 | }
196 |
197 | @OneToMany(mappedBy = "cardEnrollByCardEnrollId", orphanRemoval = true)
198 | public Collection getCardEnrollSessionTypesByCardId() {
199 | return cardEnrollSessionTypesByCardId;
200 | }
201 |
202 | public void setCardEnrollSessionTypesByCardId(final Collection cardEnrollSessionTypesByCardId) {
203 | this.cardEnrollSessionTypesByCardId = cardEnrollSessionTypesByCardId;
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/enrollment/CardEnrollSessionFormat.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionFormat;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "card_enroll_session_format", schema = "public", catalog = "innotutor")
12 | public class CardEnrollSessionFormat {
13 | private Long cardEnrollId;
14 | private Long sessionFormatId;
15 | private Long cardEnrollSessionFormatId;
16 | private CardEnroll cardEnrollByCardEnrollId;
17 | private SessionFormat sessionFormatBySessionFormatId;
18 |
19 | public CardEnrollSessionFormat(final Long cardEnrollId, final Long sessionFormatId, final CardEnroll cardEnrollByCardEnrollId,
20 | final SessionFormat sessionFormatBySessionFormatId) {
21 | this.cardEnrollId = cardEnrollId;
22 | this.sessionFormatId = sessionFormatId;
23 | this.cardEnrollByCardEnrollId = cardEnrollByCardEnrollId;
24 | this.sessionFormatBySessionFormatId = sessionFormatBySessionFormatId;
25 | }
26 |
27 | @Basic
28 | @Column(name = "card_enroll_id", nullable = false, insertable = false, updatable = false)
29 | public Long getCardEnrollId() {
30 | return cardEnrollId;
31 | }
32 |
33 | public void setCardEnrollId(final Long cardEnrollId) {
34 | this.cardEnrollId = cardEnrollId;
35 | }
36 |
37 | @Basic
38 | @Column(name = "session_format_id", nullable = false, insertable = false, updatable = false)
39 | public Long getSessionFormatId() {
40 | return sessionFormatId;
41 | }
42 |
43 | public void setSessionFormatId(final Long sessionFormatId) {
44 | this.sessionFormatId = sessionFormatId;
45 | }
46 |
47 | @Id
48 | @GeneratedValue(strategy = GenerationType.IDENTITY)
49 | @Column(name = "card_enroll_session_format_id", nullable = false)
50 | public Long getCardEnrollSessionFormatId() {
51 | return cardEnrollSessionFormatId;
52 | }
53 |
54 | public void setCardEnrollSessionFormatId(final Long cardEnrollSessionFormatId) {
55 | this.cardEnrollSessionFormatId = cardEnrollSessionFormatId;
56 | }
57 |
58 | @Override
59 | public boolean equals(final Object object) {
60 | if (this == object) {
61 | return true;
62 | }
63 | if (object == null || getClass() != object.getClass()) {
64 | return false;
65 | }
66 | final CardEnrollSessionFormat that = (CardEnrollSessionFormat) object;
67 | if (!Objects.equals(cardEnrollId, that.cardEnrollId)) {
68 | return false;
69 | }
70 | if (!Objects.equals(sessionFormatId, that.sessionFormatId)) {
71 | return false;
72 | }
73 | return Objects.equals(cardEnrollSessionFormatId, that.cardEnrollSessionFormatId);
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | int result = cardEnrollId == null ? 0 : cardEnrollId.hashCode();
79 | result = 31 * result + (sessionFormatId == null ? 0 : sessionFormatId.hashCode());
80 | result = 31 * result + (cardEnrollSessionFormatId == null ? 0 : cardEnrollSessionFormatId.hashCode());
81 | return result;
82 | }
83 |
84 | @ManyToOne
85 | @JoinColumn(name = "card_enroll_id", referencedColumnName = "card_enroll_id", nullable = false)
86 | public CardEnroll getCardEnrollByCardEnrollId() {
87 | return cardEnrollByCardEnrollId;
88 | }
89 |
90 | public void setCardEnrollByCardEnrollId(final CardEnroll cardEnrollByCardEnrollId) {
91 | this.cardEnrollByCardEnrollId = cardEnrollByCardEnrollId;
92 | }
93 |
94 | @ManyToOne
95 | @JoinColumn(name = "session_format_id", referencedColumnName = "session_format_id", nullable = false)
96 | public SessionFormat getSessionFormatBySessionFormatId() {
97 | return sessionFormatBySessionFormatId;
98 | }
99 |
100 | public void setSessionFormatBySessionFormatId(final SessionFormat sessionFormatBySessionFormatId) {
101 | this.sessionFormatBySessionFormatId = sessionFormatBySessionFormatId;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/enrollment/CardEnrollSessionType.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionType;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "card_enroll_session_type", schema = "public", catalog = "innotutor")
12 | public class CardEnrollSessionType {
13 | private Long cardEnrollId;
14 | private Long sessionTypeId;
15 | private Long cardEnrollSessionTypeId;
16 | private CardEnroll cardEnrollByCardEnrollId;
17 | private SessionType sessionTypeBySessionTypeId;
18 |
19 | public CardEnrollSessionType(final Long cardEnrollId, final Long sessionTypeId, final CardEnroll cardEnrollByCardEnrollId,
20 | final SessionType sessionTypeBySessionTypeId) {
21 | this.cardEnrollId = cardEnrollId;
22 | this.sessionTypeId = sessionTypeId;
23 | this.cardEnrollByCardEnrollId = cardEnrollByCardEnrollId;
24 | this.sessionTypeBySessionTypeId = sessionTypeBySessionTypeId;
25 | }
26 |
27 | @Basic
28 | @Column(name = "card_enroll_id", nullable = false, insertable = false, updatable = false)
29 | public Long getCardEnrollId() {
30 | return cardEnrollId;
31 | }
32 |
33 | public void setCardEnrollId(final Long cardEnrollId) {
34 | this.cardEnrollId = cardEnrollId;
35 | }
36 |
37 | @Basic
38 | @Column(name = "session_type_id", nullable = false, insertable = false, updatable = false)
39 | public Long getSessionTypeId() {
40 | return sessionTypeId;
41 | }
42 |
43 | public void setSessionTypeId(final Long sessionTypeId) {
44 | this.sessionTypeId = sessionTypeId;
45 | }
46 |
47 | @Id
48 | @GeneratedValue(strategy = GenerationType.IDENTITY)
49 | @Column(name = "card_enroll_session_type_id", nullable = false)
50 | public Long getCardEnrollSessionTypeId() {
51 | return cardEnrollSessionTypeId;
52 | }
53 |
54 | public void setCardEnrollSessionTypeId(final Long cardEnrollSessionTypeId) {
55 | this.cardEnrollSessionTypeId = cardEnrollSessionTypeId;
56 | }
57 |
58 | @Override
59 | public boolean equals(final Object object) {
60 | if (this == object) {
61 | return true;
62 | }
63 | if (object == null || getClass() != object.getClass()) {
64 | return false;
65 | }
66 | final CardEnrollSessionType that = (CardEnrollSessionType) object;
67 | if (!Objects.equals(cardEnrollId, that.cardEnrollId)) {
68 | return false;
69 | }
70 | if (!Objects.equals(sessionTypeId, that.sessionTypeId)) {
71 | return false;
72 | }
73 | return Objects.equals(cardEnrollSessionTypeId, that.cardEnrollSessionTypeId);
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | int result = cardEnrollId == null ? 0 : cardEnrollId.hashCode();
79 | result = 31 * result + (sessionTypeId == null ? 0 : sessionTypeId.hashCode());
80 | result = 31 * result + (cardEnrollSessionTypeId == null ? 0 : cardEnrollSessionTypeId.hashCode());
81 | return result;
82 | }
83 |
84 | @ManyToOne
85 | @JoinColumn(name = "card_enroll_id", referencedColumnName = "card_enroll_id", nullable = false)
86 | public CardEnroll getCardEnrollByCardEnrollId() {
87 | return cardEnrollByCardEnrollId;
88 | }
89 |
90 | public void setCardEnrollByCardEnrollId(final CardEnroll cardEnrollByCardEnrollId) {
91 | this.cardEnrollByCardEnrollId = cardEnrollByCardEnrollId;
92 | }
93 |
94 | @ManyToOne
95 | @JoinColumn(name = "session_type_id", referencedColumnName = "session_type_id", nullable = false)
96 | public SessionType getSessionTypeBySessionTypeId() {
97 | return sessionTypeBySessionTypeId;
98 | }
99 |
100 | public void setSessionTypeBySessionTypeId(final SessionType sessionTypeBySessionTypeId) {
101 | this.sessionTypeBySessionTypeId = sessionTypeBySessionTypeId;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/card/enrollment/EnrollmentStatus.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.card.enrollment;
2 |
3 | import lombok.NoArgsConstructor;
4 | import org.hibernate.annotations.CreationTimestamp;
5 | import org.hibernate.annotations.UpdateTimestamp;
6 |
7 | import javax.persistence.*;
8 | import java.sql.Timestamp;
9 | import java.util.Collection;
10 | import java.util.Objects;
11 |
12 | @NoArgsConstructor
13 | @Entity
14 | @Table(name = "enrollment_status", schema = "public", catalog = "innotutor")
15 | public class EnrollmentStatus {
16 | private Long statusId;
17 | private String status;
18 | private Timestamp creationDate;
19 | private Timestamp lastUpdate;
20 | private Collection cardEnrollsByStatusId;
21 |
22 | @Id
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
24 | @Column(name = "status_id", nullable = false)
25 | public Long getStatusId() {
26 | return statusId;
27 | }
28 |
29 | public void setStatusId(final Long statusId) {
30 | this.statusId = statusId;
31 | }
32 |
33 | @Basic
34 | @Column(name = "status", nullable = false, length = 64)
35 | public String getStatus() {
36 | return status;
37 | }
38 |
39 | public void setStatus(final String status) {
40 | this.status = status;
41 | }
42 |
43 | @Basic
44 | @CreationTimestamp
45 | @Column(name = "creation_date", insertable = false, updatable = false)
46 | public Timestamp getCreationDate() {
47 | return creationDate;
48 | }
49 |
50 | public void setCreationDate(final Timestamp creationDate) {
51 | this.creationDate = creationDate;
52 | }
53 |
54 | @Basic
55 | @UpdateTimestamp
56 | @Column(name = "last_update", insertable = false)
57 | public Timestamp getLastUpdate() {
58 | return lastUpdate;
59 | }
60 |
61 | public void setLastUpdate(final Timestamp lastUpdate) {
62 | this.lastUpdate = lastUpdate;
63 | }
64 |
65 | @Override
66 | public boolean equals(final Object object) {
67 | if (this == object) {
68 | return true;
69 | }
70 | if (object == null || getClass() != object.getClass()) {
71 | return false;
72 | }
73 | final EnrollmentStatus that = (EnrollmentStatus) object;
74 | if (!Objects.equals(statusId, that.statusId)) {
75 | return false;
76 | }
77 | if (!Objects.equals(status, that.status)) {
78 | return false;
79 | }
80 | if (!Objects.equals(creationDate, that.creationDate)) {
81 | return false;
82 | }
83 | return Objects.equals(lastUpdate, that.lastUpdate);
84 | }
85 |
86 | @Override
87 | public int hashCode() {
88 | int result = statusId == null ? 0 : statusId.hashCode();
89 | result = 31 * result + (status == null ? 0 : status.hashCode());
90 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
91 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
92 | return result;
93 | }
94 |
95 | @OneToMany(mappedBy = "enrollmentStatusByStatusId", cascade = CascadeType.REMOVE, orphanRemoval = true)
96 | public Collection getCardEnrollsByStatusId() {
97 | return cardEnrollsByStatusId;
98 | }
99 |
100 | public void setCardEnrollsByStatusId(final Collection cardEnrollsByStatusId) {
101 | this.cardEnrollsByStatusId = cardEnrollsByStatusId;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/session/SessionFormat.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.session;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionFormat;
4 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionFormat;
5 | import lombok.NoArgsConstructor;
6 | import org.hibernate.annotations.CreationTimestamp;
7 | import org.hibernate.annotations.UpdateTimestamp;
8 |
9 | import javax.persistence.*;
10 | import java.sql.Timestamp;
11 | import java.util.Collection;
12 | import java.util.Objects;
13 |
14 | @NoArgsConstructor
15 | @Entity
16 | @Table(name = "session_format", schema = "public", catalog = "innotutor")
17 | public class SessionFormat {
18 | private Long sessionFormatId;
19 | private String name;
20 | private Timestamp creationDate;
21 | private Timestamp lastUpdate;
22 | private Collection cardEnrollSessionFormatsBySessionFormatId;
23 | private Collection cardSessionFormatsBySessionFormatId;
24 | private Collection sessionsBySessionFormatId;
25 |
26 | @Id
27 | @GeneratedValue(strategy = GenerationType.IDENTITY)
28 | @Column(name = "session_format_id", nullable = false)
29 | public Long getSessionFormatId() {
30 | return sessionFormatId;
31 | }
32 |
33 | public void setSessionFormatId(final Long sessionFormatId) {
34 | this.sessionFormatId = sessionFormatId;
35 | }
36 |
37 | @Basic
38 | @Column(name = "name", nullable = false, length = 64)
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(final String name) {
44 | this.name = name;
45 | }
46 |
47 | @Basic
48 | @CreationTimestamp
49 | @Column(name = "creation_date", insertable = false, updatable = false)
50 | public Timestamp getCreationDate() {
51 | return creationDate;
52 | }
53 |
54 | public void setCreationDate(final Timestamp creationDate) {
55 | this.creationDate = creationDate;
56 | }
57 |
58 | @Basic
59 | @UpdateTimestamp
60 | @Column(name = "last_update", insertable = false)
61 | public Timestamp getLastUpdate() {
62 | return lastUpdate;
63 | }
64 |
65 | public void setLastUpdate(final Timestamp lastUpdate) {
66 | this.lastUpdate = lastUpdate;
67 | }
68 |
69 | @Override
70 | public boolean equals(final Object object) {
71 | if (this == object) {
72 | return true;
73 | }
74 | if (object == null || getClass() != object.getClass()) {
75 | return false;
76 | }
77 | final SessionFormat that = (SessionFormat) object;
78 | if (!Objects.equals(sessionFormatId, that.sessionFormatId)) {
79 | return false;
80 | }
81 | if (!Objects.equals(name, that.name)) {
82 | return false;
83 | }
84 | if (!Objects.equals(creationDate, that.creationDate)) {
85 | return false;
86 | }
87 | return Objects.equals(lastUpdate, that.lastUpdate);
88 | }
89 |
90 | @Override
91 | public int hashCode() {
92 | int result = sessionFormatId == null ? 0 : sessionFormatId.hashCode();
93 | result = 31 * result + (name == null ? 0 : name.hashCode());
94 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
95 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
96 | return result;
97 | }
98 |
99 | @OneToMany(mappedBy = "sessionFormatBySessionFormatId")
100 | public Collection getCardEnrollSessionFormatsBySessionFormatId() {
101 | return cardEnrollSessionFormatsBySessionFormatId;
102 | }
103 |
104 | public void setCardEnrollSessionFormatsBySessionFormatId(final Collection cardEnrollSessionFormatsBySessionFormatId) {
105 | this.cardEnrollSessionFormatsBySessionFormatId = cardEnrollSessionFormatsBySessionFormatId;
106 | }
107 |
108 | @OneToMany(mappedBy = "sessionFormatBySessionFormatId")
109 | public Collection getCardSessionFormatsBySessionFormatId() {
110 | return cardSessionFormatsBySessionFormatId;
111 | }
112 |
113 | public void setCardSessionFormatsBySessionFormatId(final Collection cardSessionFormatsBySessionFormatId) {
114 | this.cardSessionFormatsBySessionFormatId = cardSessionFormatsBySessionFormatId;
115 | }
116 |
117 | @OneToMany(mappedBy = "sessionFormatBySessionFormatId")
118 | public Collection getSessionsBySessionFormatId() {
119 | return sessionsBySessionFormatId;
120 | }
121 |
122 | public void setSessionsBySessionFormatId(final Collection sessionsBySessionFormatId) {
123 | this.sessionsBySessionFormatId = sessionsBySessionFormatId;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/session/SessionRating.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.session;
2 |
3 | import innotutor.innotutor_backend.entity.user.User;
4 | import lombok.NoArgsConstructor;
5 | import org.hibernate.annotations.CreationTimestamp;
6 | import org.hibernate.annotations.UpdateTimestamp;
7 |
8 | import javax.persistence.*;
9 | import java.sql.Timestamp;
10 | import java.util.Objects;
11 |
12 | @NoArgsConstructor
13 | @Entity
14 | @Table(name = "session_rating", schema = "public", catalog = "innotutor")
15 | public class SessionRating {
16 | private Long sessionRatingId;
17 | private Long sessionId;
18 | private Long userId;
19 | private Integer mark;
20 | private String feedback;
21 | private Timestamp creationDate;
22 | private Timestamp lastUpdate;
23 | private Session sessionBySessionId;
24 | private User userByUserId;
25 |
26 | public SessionRating(final Long sessionId, final Long userId, final Integer mark, final String feedback,
27 | final Session sessionBySessionId, final User userByUserId) {
28 | this.sessionId = sessionId;
29 | this.userId = userId;
30 | this.mark = mark;
31 | this.feedback = feedback;
32 | this.sessionBySessionId = sessionBySessionId;
33 | this.userByUserId = userByUserId;
34 | }
35 |
36 | @Id
37 | @GeneratedValue(strategy = GenerationType.IDENTITY)
38 | @Column(name = "session_rating_id", nullable = false)
39 | public Long getSessionRatingId() {
40 | return sessionRatingId;
41 | }
42 |
43 | public void setSessionRatingId(final Long sessionRatingId) {
44 | this.sessionRatingId = sessionRatingId;
45 | }
46 |
47 | @Basic
48 | @Column(name = "session_id", nullable = false, insertable = false, updatable = false)
49 | public Long getSessionId() {
50 | return sessionId;
51 | }
52 |
53 | public void setSessionId(final Long sessionId) {
54 | this.sessionId = sessionId;
55 | }
56 |
57 | @Basic
58 | @Column(name = "user_id", nullable = false, insertable = false, updatable = false)
59 | public Long getUserId() {
60 | return userId;
61 | }
62 |
63 | public void setUserId(final Long userId) {
64 | this.userId = userId;
65 | }
66 |
67 | @Basic
68 | @Column(name = "mark", nullable = false)
69 | public Integer getMark() {
70 | return mark;
71 | }
72 |
73 | public void setMark(final Integer mark) {
74 | this.mark = mark;
75 | }
76 |
77 | @Basic
78 | @Column(name = "feedback", length = 256)
79 | public String getFeedback() {
80 | return feedback;
81 | }
82 |
83 | public void setFeedback(final String feedback) {
84 | this.feedback = feedback;
85 | }
86 |
87 | @Basic
88 | @CreationTimestamp
89 | @Column(name = "creation_date", insertable = false, updatable = false)
90 | public Timestamp getCreationDate() {
91 | return creationDate;
92 | }
93 |
94 | public void setCreationDate(final Timestamp creationDate) {
95 | this.creationDate = creationDate;
96 | }
97 |
98 | @Basic
99 | @UpdateTimestamp
100 | @Column(name = "last_update", insertable = false)
101 | public Timestamp getLastUpdate() {
102 | return lastUpdate;
103 | }
104 |
105 | public void setLastUpdate(final Timestamp lastUpdate) {
106 | this.lastUpdate = lastUpdate;
107 | }
108 |
109 | @Override
110 | public boolean equals(final Object object) {
111 | if (this == object) {
112 | return true;
113 | }
114 | if (object == null || getClass() != object.getClass()) {
115 | return false;
116 | }
117 | final SessionRating that = (SessionRating) object;
118 | if (!Objects.equals(sessionRatingId, that.sessionRatingId)) {
119 | return false;
120 | }
121 | if (!Objects.equals(sessionId, that.sessionId)) {
122 | return false;
123 | }
124 | if (!Objects.equals(userId, that.userId)) {
125 | return false;
126 | }
127 | if (!Objects.equals(mark, that.mark)) {
128 | return false;
129 | }
130 | if (!Objects.equals(feedback, that.feedback)) {
131 | return false;
132 | }
133 | if (!Objects.equals(creationDate, that.creationDate)) {
134 | return false;
135 | }
136 | return Objects.equals(lastUpdate, that.lastUpdate);
137 | }
138 |
139 | @Override
140 | public int hashCode() {
141 | int result = sessionRatingId == null ? 0 : sessionRatingId.hashCode();
142 | result = 31 * result + (sessionId == null ? 0 : sessionId.hashCode());
143 | result = 31 * result + (userId == null ? 0 : userId.hashCode());
144 | result = 31 * result + (mark == null ? 0 : mark.hashCode());
145 | result = 31 * result + (feedback == null ? 0 : feedback.hashCode());
146 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
147 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
148 | return result;
149 | }
150 |
151 | @ManyToOne
152 | @JoinColumn(name = "session_id", referencedColumnName = "session_id", nullable = false)
153 | public Session getSessionBySessionId() {
154 | return sessionBySessionId;
155 | }
156 |
157 | public void setSessionBySessionId(final Session sessionBySessionId) {
158 | this.sessionBySessionId = sessionBySessionId;
159 | }
160 |
161 | @ManyToOne
162 | @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
163 | public User getUserByUserId() {
164 | return userByUserId;
165 | }
166 |
167 | public void setUserByUserId(final User userByUserId) {
168 | this.userByUserId = userByUserId;
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/session/SessionType.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.session;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionType;
4 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionType;
5 | import lombok.NoArgsConstructor;
6 | import org.hibernate.annotations.CreationTimestamp;
7 | import org.hibernate.annotations.UpdateTimestamp;
8 |
9 | import javax.persistence.*;
10 | import java.sql.Timestamp;
11 | import java.util.Collection;
12 | import java.util.Objects;
13 |
14 | @NoArgsConstructor
15 | @Entity
16 | @Table(name = "session_type", schema = "public", catalog = "innotutor")
17 | public class SessionType {
18 | private Long sessionTypeId;
19 | private String name;
20 | private Timestamp creationDate;
21 | private Timestamp lastUpdate;
22 | private Collection cardEnrollSessionTypesBySessionTypeId;
23 | private Collection cardSessionTypesBySessionTypeId;
24 | private Collection sessionsBySessionTypeId;
25 |
26 | @Id
27 | @GeneratedValue(strategy = GenerationType.IDENTITY)
28 | @Column(name = "session_type_id", nullable = false)
29 | public Long getSessionTypeId() {
30 | return sessionTypeId;
31 | }
32 |
33 | public void setSessionTypeId(final Long sessionTypeId) {
34 | this.sessionTypeId = sessionTypeId;
35 | }
36 |
37 | @Basic
38 | @Column(name = "name", nullable = false, length = 64)
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(final String name) {
44 | this.name = name;
45 | }
46 |
47 | @Basic
48 | @CreationTimestamp
49 | @Column(name = "creation_date", insertable = false, updatable = false)
50 | public Timestamp getCreationDate() {
51 | return creationDate;
52 | }
53 |
54 | public void setCreationDate(final Timestamp creationDate) {
55 | this.creationDate = creationDate;
56 | }
57 |
58 | @Basic
59 | @UpdateTimestamp
60 | @Column(name = "last_update", insertable = false)
61 | public Timestamp getLastUpdate() {
62 | return lastUpdate;
63 | }
64 |
65 | public void setLastUpdate(final Timestamp lastUpdate) {
66 | this.lastUpdate = lastUpdate;
67 | }
68 |
69 | @Override
70 | public boolean equals(final Object object) {
71 | if (this == object) {
72 | return true;
73 | }
74 | if (object == null || getClass() != object.getClass()) {
75 | return false;
76 | }
77 | final SessionType that = (SessionType) object;
78 | if (!Objects.equals(sessionTypeId, that.sessionTypeId)) {
79 | return false;
80 | }
81 | if (!Objects.equals(name, that.name)) {
82 | return false;
83 | }
84 | if (!Objects.equals(creationDate, that.creationDate)) {
85 | return false;
86 | }
87 | return Objects.equals(lastUpdate, that.lastUpdate);
88 | }
89 |
90 | @Override
91 | public int hashCode() {
92 | int result = sessionTypeId == null ? 0 : sessionTypeId.hashCode();
93 | result = 31 * result + (name == null ? 0 : name.hashCode());
94 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
95 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
96 | return result;
97 | }
98 |
99 | @OneToMany(mappedBy = "sessionTypeBySessionTypeId")
100 | public Collection getCardEnrollSessionTypesBySessionTypeId() {
101 | return cardEnrollSessionTypesBySessionTypeId;
102 | }
103 |
104 | public void setCardEnrollSessionTypesBySessionTypeId(final Collection cardEnrollSessionTypesBySessionTypeId) {
105 | this.cardEnrollSessionTypesBySessionTypeId = cardEnrollSessionTypesBySessionTypeId;
106 | }
107 |
108 | @OneToMany(mappedBy = "sessionTypeBySessionTypeId")
109 | public Collection getCardSessionTypesBySessionTypeId() {
110 | return cardSessionTypesBySessionTypeId;
111 | }
112 |
113 | public void setCardSessionTypesBySessionTypeId(final Collection cardSessionTypesBySessionTypeId) {
114 | this.cardSessionTypesBySessionTypeId = cardSessionTypesBySessionTypeId;
115 | }
116 |
117 | @OneToMany(mappedBy = "sessionTypeBySessionTypeId")
118 | public Collection getSessionsBySessionTypeId() {
119 | return sessionsBySessionTypeId;
120 | }
121 |
122 | public void setSessionsBySessionTypeId(final Collection sessionsBySessionTypeId) {
123 | this.sessionsBySessionTypeId = sessionsBySessionTypeId;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/session/Subject.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.session;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import lombok.NoArgsConstructor;
5 | import org.hibernate.annotations.CreationTimestamp;
6 | import org.hibernate.annotations.UpdateTimestamp;
7 |
8 | import javax.persistence.*;
9 | import java.sql.Timestamp;
10 | import java.util.Collection;
11 | import java.util.Objects;
12 |
13 | @NoArgsConstructor
14 | @Entity
15 | @Table(name = "subject", schema = "public", catalog = "innotutor")
16 | public class Subject {
17 | private Long subjectId;
18 | private String name;
19 | private Timestamp creationDate;
20 | private Timestamp lastUpdate;
21 | private Collection cardsBySubjectId;
22 | private Collection sessionsBySubjectId;
23 |
24 | @Id
25 | @GeneratedValue(strategy = GenerationType.IDENTITY)
26 | @Column(name = "subject_id", nullable = false)
27 | public Long getSubjectId() {
28 | return subjectId;
29 | }
30 |
31 | public void setSubjectId(final Long subjectId) {
32 | this.subjectId = subjectId;
33 | }
34 |
35 | @Basic
36 | @Column(name = "name", nullable = false, length = 64)
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(final String name) {
42 | this.name = name;
43 | }
44 |
45 | @Basic
46 | @CreationTimestamp
47 | @Column(name = "creation_date", insertable = false, updatable = false)
48 | public Timestamp getCreationDate() {
49 | return creationDate;
50 | }
51 |
52 | public void setCreationDate(final Timestamp creationDate) {
53 | this.creationDate = creationDate;
54 | }
55 |
56 | @Basic
57 | @UpdateTimestamp
58 | @Column(name = "last_update", insertable = false)
59 | public Timestamp getLastUpdate() {
60 | return lastUpdate;
61 | }
62 |
63 | public void setLastUpdate(final Timestamp lastUpdate) {
64 | this.lastUpdate = lastUpdate;
65 | }
66 |
67 | @Override
68 | public boolean equals(final Object object) {
69 | if (this == object) {
70 | return true;
71 | }
72 | if (object == null || getClass() != object.getClass()) {
73 | return false;
74 | }
75 | final Subject subject = (Subject) object;
76 | if (!Objects.equals(subjectId, subject.subjectId)) {
77 | return false;
78 | }
79 | if (!Objects.equals(name, subject.name)) {
80 | return false;
81 | }
82 | if (!Objects.equals(creationDate, subject.creationDate)) {
83 | return false;
84 | }
85 | return Objects.equals(lastUpdate, subject.lastUpdate);
86 | }
87 |
88 | @Override
89 | public int hashCode() {
90 | int result = subjectId == null ? 0 : subjectId.hashCode();
91 | result = 31 * result + (name == null ? 0 : name.hashCode());
92 | result = 31 * result + (creationDate == null ? 0 : creationDate.hashCode());
93 | result = 31 * result + (lastUpdate == null ? 0 : lastUpdate.hashCode());
94 | return result;
95 | }
96 |
97 | @OneToMany(mappedBy = "subjectBySubjectId")
98 | public Collection getCardsBySubjectId() {
99 | return cardsBySubjectId;
100 | }
101 |
102 | public void setCardsBySubjectId(final Collection cardsBySubjectId) {
103 | this.cardsBySubjectId = cardsBySubjectId;
104 | }
105 |
106 | @OneToMany(mappedBy = "subjectBySubjectId")
107 | public Collection getSessionsBySubjectId() {
108 | return sessionsBySubjectId;
109 | }
110 |
111 | public void setSessionsBySubjectId(final Collection sessionsBySubjectId) {
112 | this.sessionsBySubjectId = sessionsBySubjectId;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/user/Request.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.user;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "request", schema = "public", catalog = "innotutor")
12 | public class Request {
13 | private Long studentId;
14 | private Long cardId;
15 | private Long requestId;
16 | private User userByStudentId;
17 | private Card cardByCardId;
18 |
19 | public Request(final Long studentId, final Long cardId, final User userByStudentId, final Card cardByCardId) {
20 | this.studentId = studentId;
21 | this.cardId = cardId;
22 | this.userByStudentId = userByStudentId;
23 | this.cardByCardId = cardByCardId;
24 | }
25 |
26 | @Basic
27 | @Column(name = "student_id", nullable = false, insertable = false, updatable = false)
28 | public Long getStudentId() {
29 | return studentId;
30 | }
31 |
32 | public void setStudentId(final Long studentId) {
33 | this.studentId = studentId;
34 | }
35 |
36 | @Basic
37 | @Column(name = "card_id", nullable = false, insertable = false, updatable = false)
38 | public Long getCardId() {
39 | return cardId;
40 | }
41 |
42 | public void setCardId(final Long cardId) {
43 | this.cardId = cardId;
44 | }
45 |
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | @Column(name = "request_id", nullable = false)
49 | public Long getRequestId() {
50 | return requestId;
51 | }
52 |
53 | public void setRequestId(final Long requestId) {
54 | this.requestId = requestId;
55 | }
56 |
57 | @Override
58 | public boolean equals(final Object object) {
59 | if (this == object) {
60 | return true;
61 | }
62 | if (object == null || getClass() != object.getClass()) {
63 | return false;
64 | }
65 | final Request request = (Request) object;
66 | if (!Objects.equals(studentId, request.studentId)) {
67 | return false;
68 | }
69 | if (!Objects.equals(cardId, request.cardId)) {
70 | return false;
71 | }
72 | return Objects.equals(requestId, request.requestId);
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | int result = studentId == null ? 0 : studentId.hashCode();
78 | result = 31 * result + (cardId == null ? 0 : cardId.hashCode());
79 | result = 31 * result + (requestId == null ? 0 : requestId.hashCode());
80 | return result;
81 | }
82 |
83 | @ManyToOne
84 | @JoinColumn(name = "student_id", referencedColumnName = "user_id", nullable = false)
85 | public User getUserByStudentId() {
86 | return userByStudentId;
87 | }
88 |
89 | public void setUserByStudentId(final User userByStudentId) {
90 | this.userByStudentId = userByStudentId;
91 | }
92 |
93 | @OneToOne
94 | @JoinColumn(name = "card_id", referencedColumnName = "card_id", nullable = false)
95 | public Card getCardByCardId() {
96 | return cardByCardId;
97 | }
98 |
99 | public void setCardByCardId(final Card cardByCardId) {
100 | this.cardByCardId = cardByCardId;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/user/Service.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.user;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "service", schema = "public", catalog = "innotutor")
12 | public class Service {
13 | private Long tutorId;
14 | private Long cardId;
15 | private Long serviceId;
16 | private User userByTutorId;
17 | private Card cardByCardId;
18 |
19 | public Service(final Long tutorId, final Long cardId, final User userByTutorId, final Card cardByCardId) {
20 | this.tutorId = tutorId;
21 | this.cardId = cardId;
22 | this.userByTutorId = userByTutorId;
23 | this.cardByCardId = cardByCardId;
24 | }
25 |
26 | @Basic
27 | @Column(name = "tutor_id", nullable = false, insertable = false, updatable = false)
28 | public Long getTutorId() {
29 | return tutorId;
30 | }
31 |
32 | public void setTutorId(final Long tutorId) {
33 | this.tutorId = tutorId;
34 | }
35 |
36 | @Basic
37 | @Column(name = "card_id", nullable = false, insertable = false, updatable = false)
38 | public Long getCardId() {
39 | return cardId;
40 | }
41 |
42 | public void setCardId(final Long cardId) {
43 | this.cardId = cardId;
44 | }
45 |
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | @Column(name = "service_id", nullable = false)
49 | public Long getServiceId() {
50 | return serviceId;
51 | }
52 |
53 | public void setServiceId(final Long serviceId) {
54 | this.serviceId = serviceId;
55 | }
56 |
57 | @Override
58 | public boolean equals(final Object object) {
59 | if (this == object) {
60 | return true;
61 | }
62 | if (object == null || getClass() != object.getClass()) {
63 | return false;
64 | }
65 | final Service service = (Service) object;
66 | if (!Objects.equals(tutorId, service.tutorId)) {
67 | return false;
68 | }
69 | if (!Objects.equals(cardId, service.cardId)) {
70 | return false;
71 | }
72 | return Objects.equals(serviceId, service.serviceId);
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | int result = tutorId == null ? 0 : tutorId.hashCode();
78 | result = 31 * result + (cardId == null ? 0 : cardId.hashCode());
79 | result = 31 * result + (serviceId == null ? 0 : serviceId.hashCode());
80 | return result;
81 | }
82 |
83 | @ManyToOne
84 | @JoinColumn(name = "tutor_id", referencedColumnName = "user_id", nullable = false)
85 | public User getUserByTutorId() {
86 | return userByTutorId;
87 | }
88 |
89 | public void setUserByTutorId(final User userByTutorId) {
90 | this.userByTutorId = userByTutorId;
91 | }
92 |
93 | @OneToOne
94 | @JoinColumn(name = "card_id", referencedColumnName = "card_id", nullable = false)
95 | public Card getCardByCardId() {
96 | return cardByCardId;
97 | }
98 |
99 | public void setCardByCardId(final Card cardByCardId) {
100 | this.cardByCardId = cardByCardId;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/entity/user/SessionStudent.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.entity.user;
2 |
3 | import innotutor.innotutor_backend.entity.session.Session;
4 | import lombok.NoArgsConstructor;
5 |
6 | import javax.persistence.*;
7 | import java.util.Objects;
8 |
9 | @NoArgsConstructor
10 | @Entity
11 | @Table(name = "session_student", schema = "public", catalog = "innotutor")
12 | public class SessionStudent {
13 | private Long sessionId;
14 | private Long studentId;
15 | private Long sessionStudentId;
16 | private Session sessionBySessionId;
17 | private User userByStudentId;
18 |
19 | public SessionStudent(final Long sessionId, final Long studentId, final Session sessionBySessionId, final User userByStudentId) {
20 | this.sessionId = sessionId;
21 | this.studentId = studentId;
22 | this.sessionBySessionId = sessionBySessionId;
23 | this.userByStudentId = userByStudentId;
24 | }
25 |
26 | @Basic
27 | @Column(name = "session_id", nullable = false, insertable = false, updatable = false)
28 | public Long getSessionId() {
29 | return sessionId;
30 | }
31 |
32 | public void setSessionId(final Long sessionId) {
33 | this.sessionId = sessionId;
34 | }
35 |
36 | @Basic
37 | @Column(name = "student_id", nullable = false, insertable = false, updatable = false)
38 | public Long getStudentId() {
39 | return studentId;
40 | }
41 |
42 | public void setStudentId(final Long studentId) {
43 | this.studentId = studentId;
44 | }
45 |
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | @Column(name = "session_student_id", nullable = false)
49 | public Long getSessionStudentId() {
50 | return sessionStudentId;
51 | }
52 |
53 | public void setSessionStudentId(final Long sessionStudentId) {
54 | this.sessionStudentId = sessionStudentId;
55 | }
56 |
57 | @Override
58 | public boolean equals(final Object object) {
59 | if (this == object) {
60 | return true;
61 | }
62 | if (object == null || getClass() != object.getClass()) {
63 | return false;
64 | }
65 | final SessionStudent that = (SessionStudent) object;
66 | if (!Objects.equals(sessionId, that.sessionId)) {
67 | return false;
68 | }
69 | if (!Objects.equals(studentId, that.studentId)) {
70 | return false;
71 | }
72 | return Objects.equals(sessionStudentId, that.sessionStudentId);
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | int result = sessionId == null ? 0 : sessionId.hashCode();
78 | result = 31 * result + (studentId == null ? 0 : studentId.hashCode());
79 | result = 31 * result + (sessionStudentId == null ? 0 : sessionStudentId.hashCode());
80 | return result;
81 | }
82 |
83 | @ManyToOne
84 | @JoinColumn(name = "session_id", referencedColumnName = "session_id", nullable = false)
85 | public Session getSessionBySessionId() {
86 | return sessionBySessionId;
87 | }
88 |
89 | public void setSessionBySessionId(final Session sessionBySessionId) {
90 | this.sessionBySessionId = sessionBySessionId;
91 | }
92 |
93 | @ManyToOne
94 | @JoinColumn(name = "student_id", referencedColumnName = "user_id", nullable = false)
95 | public User getUserByStudentId() {
96 | return userByStudentId;
97 | }
98 |
99 | public void setUserByStudentId(final User userByStudentId) {
100 | this.userByStudentId = userByStudentId;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/CardRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface CardRepository extends JpaRepository {
11 | List findBySubjectId(Long subjectId);
12 |
13 | List findByHidden(Boolean hidden);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/CardSessionFormatRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionFormat;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 |
9 | public interface CardSessionFormatRepository extends JpaRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/CardSessionTypeRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionType;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 |
9 | public interface CardSessionTypeRepository extends JpaRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/enrollment/CardEnrollRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnroll;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface CardEnrollRepository extends JpaRepository {
11 | List findByUserId(Long userId);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/enrollment/CardEnrollSessionFormatRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionFormat;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface CardEnrollSessionFormatRepository extends JpaRepository {
9 | void deleteByCardEnrollId(Long cardEnrollId);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/enrollment/CardEnrollSessionTypeRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionType;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface CardEnrollSessionTypeRepository extends JpaRepository {
9 | void deleteByCardEnrollId(Long cardEnrollId);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/card/enrollment/EnrollmentStatusRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.card.enrollment;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.EnrollmentStatus;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface EnrollmentStatusRepository extends JpaRepository {
9 | EnrollmentStatus findEnrollmentStatusByStatus(String status);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/session/SessionFormatRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.session;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionFormat;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface SessionFormatRepository extends JpaRepository {
9 | SessionFormat findSessionFormatByName(String name);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/session/SessionRatingRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.session;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionRating;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 |
9 | public interface SessionRatingRepository extends JpaRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/session/SessionRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.session;
2 |
3 | import innotutor.innotutor_backend.entity.session.Session;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 |
9 | public interface SessionRepository extends JpaRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/session/SessionTypeRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.session;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionType;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface SessionTypeRepository extends JpaRepository {
9 | SessionType findSessionTypeByName(String name);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/session/SubjectRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.session;
2 |
3 | import innotutor.innotutor_backend.entity.session.Subject;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface SubjectRepository extends JpaRepository {
9 | Subject findSubjectByName(String name);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/user/RequestRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.user;
2 |
3 | import innotutor.innotutor_backend.entity.user.Request;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface RequestRepository extends JpaRepository {
11 | Request findByCardId(Long cardId);
12 |
13 | List deleteByCardId(Long cardId);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/user/ServiceRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.user;
2 |
3 | import innotutor.innotutor_backend.entity.user.Service;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface ServiceRepository extends JpaRepository {
11 | Service findByCardId(Long cardId);
12 |
13 | List deleteByCardId(Long cardId);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/user/SessionStudentRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.user;
2 |
3 | import innotutor.innotutor_backend.entity.user.SessionStudent;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface SessionStudentRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/repository/user/UserRepository.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.repository.user;
2 |
3 | import innotutor.innotutor_backend.entity.user.User;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.Optional;
8 |
9 | @Repository
10 | public interface UserRepository extends JpaRepository {
11 | Optional findByEmail(String email);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/security/CustomPrincipal.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.security;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class CustomPrincipal {
7 | private String email;
8 | private String fullName;
9 | private String picture;
10 | }
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/security/SecurityUtils.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.security;
2 |
3 | import lombok.NoArgsConstructor;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.util.StringUtils;
6 | import org.springframework.web.util.WebUtils;
7 |
8 | import javax.servlet.http.Cookie;
9 | import javax.servlet.http.HttpServletRequest;
10 |
11 | @NoArgsConstructor
12 | @Component
13 | public class SecurityUtils {
14 |
15 | public String getTokenFromRequest(final HttpServletRequest request) {
16 | String token = null; //NOPMD - suppressed DataflowAnomalyAnalysis
17 | final Cookie cookieToken = WebUtils.getCookie(request, "token");
18 | if (cookieToken == null) {
19 | final String bearerToken = request.getHeader("Authorization");
20 | if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
21 | token = bearerToken.substring(7);
22 | }
23 | } else {
24 | token = cookieToken.getValue();
25 | }
26 | return token;
27 | }
28 | }
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/security/TokenFilter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.security;
2 |
3 | import com.google.firebase.auth.FirebaseAuth;
4 | import com.google.firebase.auth.FirebaseAuthException;
5 | import com.google.firebase.auth.FirebaseToken;
6 | import lombok.NoArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
10 | import org.springframework.security.core.context.SecurityContextHolder;
11 | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
12 | import org.springframework.web.filter.OncePerRequestFilter;
13 |
14 | import javax.servlet.FilterChain;
15 | import javax.servlet.ServletException;
16 | import javax.servlet.http.HttpServletRequest;
17 | import javax.servlet.http.HttpServletResponse;
18 | import java.io.IOException;
19 |
20 | @NoArgsConstructor
21 | @Slf4j
22 | public class TokenFilter extends OncePerRequestFilter {
23 |
24 | @Autowired
25 | private SecurityUtils securityUtils;
26 |
27 | @Override
28 | protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
29 | final FilterChain filterChain)
30 | throws ServletException, IOException {
31 | final String idToken = securityUtils.getTokenFromRequest(request);
32 | FirebaseToken decodedToken = null; //NOPMD - suppressed DataflowAnomalyAnalysis
33 | try {
34 | decodedToken = FirebaseAuth.getInstance().verifyIdToken(idToken);
35 | } catch (FirebaseAuthException e) {
36 | if (log.isErrorEnabled()) {
37 | log.error("Firebase Exception {}", e.getLocalizedMessage());
38 | }
39 |
40 | }
41 | if (decodedToken != null) {
42 | final CustomPrincipal customPrincipal = new CustomPrincipal();
43 | customPrincipal.setEmail((String) decodedToken.getClaims().get("email"));
44 | customPrincipal.setFullName((String) decodedToken.getClaims().get("name"));
45 | customPrincipal.setPicture((String) decodedToken.getClaims().get("picture"));
46 | final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
47 | customPrincipal, decodedToken, null);
48 | authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
49 | SecurityContextHolder.getContext().setAuthentication(authentication);
50 | }
51 | filterChain.doFilter(request, response);
52 | }
53 | }
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/security/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.security;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import lombok.NoArgsConstructor;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12 | import org.springframework.security.config.http.SessionCreationPolicy;
13 | import org.springframework.security.web.AuthenticationEntryPoint;
14 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
15 |
16 | import java.sql.Timestamp;
17 | import java.util.Date;
18 | import java.util.Map;
19 | import java.util.concurrent.ConcurrentHashMap;
20 |
21 | @NoArgsConstructor
22 | @EnableWebSecurity
23 | @Configuration
24 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
25 |
26 | private static final int ERROR_CODE = 403;
27 | private ObjectMapper objectMapper;
28 |
29 | @Autowired
30 | public WebSecurityConfig(final ObjectMapper objectMapper) {
31 | super();
32 | this.objectMapper = objectMapper;
33 | }
34 |
35 | @Bean
36 | public TokenFilter tokenAuthenticationFilter() {
37 | return new TokenFilter();
38 | }
39 |
40 | @Bean
41 | public AuthenticationEntryPoint restAuthenticationEntryPoint() {
42 | return (httpServletRequest, httpServletResponse, exception) -> {
43 | final Map errorObject = new ConcurrentHashMap<>();
44 | errorObject.put("message", "Access Denied");
45 | errorObject.put("error", HttpStatus.FORBIDDEN);
46 | errorObject.put("code", ERROR_CODE);
47 | errorObject.put("timestamp", new Timestamp(new Date().getTime()));
48 | httpServletResponse.setContentType("application/json;charset=UTF-8");
49 | httpServletResponse.setStatus(ERROR_CODE);
50 | httpServletResponse.getWriter().write(objectMapper.writeValueAsString(errorObject));
51 | };
52 | }
53 |
54 | @Override
55 | protected void configure(final HttpSecurity http) throws Exception {
56 | http.cors().and()
57 | .sessionManagement()
58 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
59 | .and().csrf().disable()
60 | .formLogin().disable()
61 | .httpBasic().disable()
62 | .exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint())
63 | .and().authorizeRequests()
64 | // .antMatchers().permitAll()
65 | .anyRequest().authenticated();
66 | http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
67 | }
68 | }
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/CardService.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.dto.searcher.UserCard;
5 | import innotutor.innotutor_backend.entity.card.Card;
6 | import innotutor.innotutor_backend.entity.user.Request;
7 | import innotutor.innotutor_backend.entity.user.User;
8 | import innotutor.innotutor_backend.repository.card.CardRepository;
9 | import innotutor.innotutor_backend.repository.card.CardSessionFormatRepository;
10 | import innotutor.innotutor_backend.repository.card.CardSessionTypeRepository;
11 | import innotutor.innotutor_backend.repository.session.SessionFormatRepository;
12 | import innotutor.innotutor_backend.repository.session.SessionTypeRepository;
13 | import innotutor.innotutor_backend.repository.session.SubjectRepository;
14 | import innotutor.innotutor_backend.repository.user.RequestRepository;
15 | import innotutor.innotutor_backend.repository.user.ServiceRepository;
16 | import innotutor.innotutor_backend.repository.user.UserRepository;
17 | import innotutor.innotutor_backend.service.utility.card.CardCreatorUser;
18 | import innotutor.innotutor_backend.service.utility.card.CardDTOCreator;
19 | import innotutor.innotutor_backend.service.utility.card.CardType;
20 | import innotutor.innotutor_backend.service.utility.cardmanager.CardUpdater;
21 | import lombok.AllArgsConstructor;
22 | import org.springframework.stereotype.Service;
23 |
24 | import java.util.Optional;
25 |
26 | @Service
27 | @AllArgsConstructor
28 | public class CardService {
29 | private final CardEnrollService cardEnrollService;
30 | private final CardRepository cardRepository;
31 | private final UserRepository userRepository;
32 | private final SessionFormatRepository sessionFormatRepository;
33 | private final SessionTypeRepository sessionTypeRepository;
34 | private final SubjectRepository subjectRepository;
35 | private final ServiceRepository serviceRepository;
36 | private final RequestRepository requestRepository;
37 | private final CardSessionFormatRepository cardSessionFormatRepository;
38 | private final CardSessionTypeRepository cardSessionTypeRepository;
39 |
40 | public CardDTO getCardById(final Long cardId, final Long userId) {
41 | final Optional cardOptional = cardRepository.findById(cardId);
42 | if (cardOptional.isPresent()) {
43 | final Card card = cardOptional.get();
44 | final User creator = new CardCreatorUser(card).creator();
45 | if (!card.getHidden() || userId.equals(creator.getUserId())) {
46 | return new CardDTOCreator(card, creator, cardEnrollService, userId).create();
47 | }
48 | }
49 | return null;
50 | }
51 |
52 | public UserCard getCardFullInfoById(final Long cardId, final Long userId) {
53 | final Optional cardOptional = cardRepository.findById(cardId);
54 | if (cardOptional.isPresent()) {
55 | final Card card = cardOptional.get();
56 | final User creator = new CardCreatorUser(card).creator();
57 | if (!card.getHidden() || userId.equals(creator.getUserId())) {
58 | innotutor.innotutor_backend.entity.user.Service service = card.getServiceByCardId();
59 | Request request = card.getRequestByCardId();
60 | if (service != null) {
61 | return new CardDTOCreator(card, creator, cardEnrollService, userId).createTutorCvDTO();
62 | } else if (request != null) {
63 | return new CardDTOCreator(card, creator, cardEnrollService, userId).createStudentRequestDTO();
64 | }
65 | }
66 | }
67 | return null;
68 | }
69 |
70 | public CardDTO postCvCard(final CardDTO cardDTO, final Long userId) {
71 | return this.postCard(CardType.SERVICE, cardDTO, userId);
72 | }
73 |
74 | public CardDTO postRequestCard(final CardDTO cardDTO, final Long userId) {
75 | return this.postCard(CardType.REQUEST, cardDTO, userId);
76 | }
77 |
78 | public CardDTO putCvCard(final Long cardId, final CardDTO cardDTO, final Long userId) {
79 | return this.putCard(cardId, CardType.SERVICE, cardDTO, userId);
80 | }
81 |
82 | public CardDTO putRequestCard(final Long cardId, final CardDTO cardDTO, final Long userId) {
83 | return this.putCard(cardId, CardType.REQUEST, cardDTO, userId);
84 | }
85 |
86 | public boolean deleteCardById(final Long cardId, final Long userId) {
87 | final Optional cardOptional = cardRepository.findById(cardId);
88 | final Optional userOptional = userRepository.findById(userId);
89 | if (!cardOptional.isPresent() || !userOptional.isPresent()) {
90 | return false;
91 | }
92 | final innotutor.innotutor_backend.entity.user.Service service = serviceRepository.findByCardId(cardId);
93 | if (service != null && service.getTutorId().equals(userId)) {
94 | cardRepository.deleteById(cardId);
95 | return true;
96 | }
97 | final Request request = requestRepository.findByCardId(cardId);
98 | if (request != null && request.getStudentId().equals(userId)) {
99 | cardRepository.deleteById(cardId);
100 | return true;
101 | }
102 | return false;
103 | }
104 |
105 | private CardDTO postCard(final CardType cardType, final CardDTO cardDTO, final Long userId) {
106 | cardDTO.setCreatorId(userId);
107 | return new innotutor.innotutor_backend.service.utility.cardmanager.CardCreator(cardDTO,
108 | cardType,
109 | cardRepository,
110 | userRepository,
111 | subjectRepository,
112 | sessionFormatRepository,
113 | sessionTypeRepository,
114 | serviceRepository,
115 | requestRepository,
116 | cardSessionFormatRepository,
117 | cardSessionTypeRepository).postCard();
118 | }
119 |
120 | private CardDTO putCard(final Long cardId, final CardType cardType, final CardDTO cardDTO, final Long userId) {
121 | cardDTO.setCreatorId(userId);
122 | cardDTO.setCardId(cardId);
123 | return new CardUpdater(cardDTO,
124 | cardType,
125 | userId,
126 | cardRepository,
127 | userRepository,
128 | subjectRepository,
129 | sessionFormatRepository,
130 | sessionTypeRepository,
131 | serviceRepository,
132 | requestRepository,
133 | cardSessionFormatRepository,
134 | cardSessionTypeRepository,
135 | cardEnrollService).putCard();
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/CardsListService.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.entity.user.User;
5 | import innotutor.innotutor_backend.repository.user.UserRepository;
6 | import innotutor.innotutor_backend.service.utility.card.CardDTOCreator;
7 | import lombok.AllArgsConstructor;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Optional;
13 | import java.util.stream.Collectors;
14 |
15 | @Service
16 | @AllArgsConstructor
17 | public class CardsListService {
18 | private final UserRepository userRepository;
19 | private final CardEnrollService cardEnrollService;
20 |
21 | public List getServices(final Long userId) { //NOPMD - suppressed ReturnEmptyCollectionRatherThanNull - null indicates that such collection doesn't exist
22 | final Optional userOptional = userRepository.findById(userId);
23 | if (userOptional.isPresent()) {
24 | final User user = userOptional.get();
25 | final List services = new ArrayList<>();
26 | user.getServicesByUserId().forEach(service ->
27 | services.add(
28 | new CardDTOCreator(
29 | service.getCardByCardId(),
30 | user,
31 | cardEnrollService,
32 | userId).create()
33 | )
34 | );
35 | return services;
36 | }
37 | return null;
38 | }
39 |
40 | public List getUserServices(final Long userId) {
41 | return userRepository.findById(userId).isPresent()
42 | ? this.getServices(userId).stream().filter(card -> !card.isHidden()).collect(Collectors.toList())
43 | : null;
44 | }
45 |
46 | public List getRequests(final Long userId) { //NOPMD - suppressed ReturnEmptyCollectionRatherThanNull - null indicates that such collection doesn't exist
47 | final Optional userOptional = userRepository.findById(userId);
48 | if (userOptional.isPresent()) {
49 | final User user = userOptional.get();
50 | final List requests = new ArrayList<>();
51 | user.getRequestsByUserId().forEach(request ->
52 | requests.add(
53 | new CardDTOCreator(request.getCardByCardId(),
54 | user,
55 | cardEnrollService,
56 | userId).create()
57 | )
58 | );
59 | return requests;
60 | }
61 | return null;
62 | }
63 |
64 | public List getUserRequests(final Long userId) {
65 | return userRepository.findById(userId).isPresent()
66 | ? this.getRequests(userId).stream().filter(card -> !card.isHidden()).collect(Collectors.toList())
67 | : null;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/TutorsService.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service;
2 |
3 | import innotutor.innotutor_backend.dto.UserDTO;
4 | import innotutor.innotutor_backend.dto.card.CardDTO;
5 | import innotutor.innotutor_backend.dto.enrollment.EnrollmentDTO;
6 | import innotutor.innotutor_backend.dto.enrollment.tutor.MyTutorDTO;
7 | import innotutor.innotutor_backend.dto.enrollment.tutor.RespondedTutorsListDTO;
8 | import innotutor.innotutor_backend.dto.enrollment.tutor.RespondedTutorsListInfoDTO;
9 | import innotutor.innotutor_backend.entity.card.Card;
10 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnroll;
11 | import innotutor.innotutor_backend.entity.user.User;
12 | import innotutor.innotutor_backend.repository.card.enrollment.EnrollmentStatusRepository;
13 | import innotutor.innotutor_backend.repository.user.ServiceRepository;
14 | import innotutor.innotutor_backend.repository.user.UserRepository;
15 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.CardEnrollSessionFormatConverter;
16 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.CardSessionFormatConverter;
17 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.CardEnrollSessionTypeConverter;
18 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.CardSessionTypeConverter;
19 | import lombok.AllArgsConstructor;
20 | import org.springframework.stereotype.Service;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 | import java.util.Objects;
25 | import java.util.Optional;
26 | import java.util.stream.Collectors;
27 |
28 | @Service
29 | @AllArgsConstructor
30 | public class TutorsService {
31 | private final UserRepository userRepository;
32 | private final ServiceRepository serviceRepository;
33 | private final EnrollmentStatusRepository enrollmentStatusRepository;
34 | private final UserService userService;
35 | private final CardService cardService;
36 |
37 | public RespondedTutorsListDTO getUserTutorsList(final Long userId) {
38 | final Optional userOptional = userRepository.findById(userId);
39 | if (userOptional.isPresent()) {
40 | final User user = userOptional.get();
41 | final List newTutorsList = this.getNewTutorsList(user);
42 | final List acceptedTutorsList = this.getAcceptedTutorsList(user);
43 | return new RespondedTutorsListDTO(newTutorsList, acceptedTutorsList);
44 | }
45 | return null;
46 | }
47 |
48 | public RespondedTutorsListInfoDTO getUserTutorsListFullInfo(final Long userId) {
49 | RespondedTutorsListDTO tutors = this.getUserTutorsList(userId);
50 | if (tutors != null) {
51 | List newTutors = tutors.getNewTutors().stream()
52 | .map(this::convertEnrollmentDTOToEnrollmentInfoDTO)
53 | .filter(Objects::nonNull)
54 | .collect(Collectors.toList());
55 | List acceptedTutors = tutors.getAcceptedTutors().stream()
56 | .map(this::convertEnrollmentDTOToEnrollmentInfoDTO)
57 | .filter(Objects::nonNull)
58 | .collect(Collectors.toList());
59 | return new RespondedTutorsListInfoDTO(newTutors, acceptedTutors);
60 | }
61 | return null;
62 | }
63 |
64 | private List getNewTutorsList(User user) {
65 | final Long requestedStatusId = enrollmentStatusRepository.findEnrollmentStatusByStatus("requested").getStatusId();
66 | return this.getTutorsListByStatusId(user, requestedStatusId);
67 | }
68 |
69 | private List getAcceptedTutorsList(User user) {
70 | final Long acceptedStatusId = enrollmentStatusRepository.findEnrollmentStatusByStatus("accepted").getStatusId();
71 | final List acceptedTutorsList = this.getTutorsListByStatusId(user, acceptedStatusId);
72 | acceptedTutorsList.addAll(this.getTutorsToWhomRequested(user, acceptedStatusId));
73 | return acceptedTutorsList;
74 | }
75 |
76 | private List getTutorsListByStatusId(final User user, final Long statusId) {
77 | final List tutorsList = new ArrayList<>();
78 | user.getRequestsByUserId().forEach(request -> request.getCardByCardId().getCardEnrollsByCardId()
79 | .forEach(cardEnroll -> {
80 | if (cardEnroll.getStatusId().equals(statusId)) {
81 | tutorsList.add(new EnrollmentDTO(
82 | cardEnroll.getCardEnrollId(),
83 | cardEnroll.getUserId(),
84 | cardEnroll.getCardId(),
85 | cardEnroll.getDescription(),
86 | new CardEnrollSessionFormatConverter(cardEnroll.getCardEnrollSessionFormatsByCardId()).stringList(),
87 | new CardEnrollSessionTypeConverter(cardEnroll.getCardEnrollSessionTypesByCardId()).stringList()
88 | ));
89 | }
90 | }));
91 | return tutorsList;
92 | }
93 |
94 | private List getTutorsToWhomRequested(final User student, final Long acceptedStatusId) {
95 | final List tutorsList = new ArrayList<>();
96 | for (final innotutor.innotutor_backend.entity.user.Service service : serviceRepository.findAll()) {
97 | final Card card = service.getCardByCardId();
98 | for (final CardEnroll cardEnroll : card.getCardEnrollsByCardId()) {
99 | if (cardEnroll.getUserId().equals(student.getUserId()) && cardEnroll.getStatusId().equals(acceptedStatusId)) {
100 | tutorsList.add(new EnrollmentDTO(
101 | cardEnroll.getCardEnrollId(),
102 | service.getTutorId(),
103 | card.getCardId(),
104 | cardEnroll.getDescription(),
105 | new CardSessionFormatConverter(card.getCardSessionFormatsByCardId()).stringList(),
106 | new CardSessionTypeConverter(card.getCardSessionTypesByCardId()).stringList()
107 | ));
108 | break;
109 | }
110 | }
111 | }
112 | return tutorsList;
113 | }
114 |
115 | private MyTutorDTO convertEnrollmentDTOToEnrollmentInfoDTO(EnrollmentDTO enrollmentDTO) {
116 | Long enrollerId = enrollmentDTO.getEnrollerId();
117 | Long cardId = enrollmentDTO.getCardId();
118 | UserDTO enroller = userService.getUserById(enrollerId);
119 | CardDTO card = cardService.getCardById(cardId, enrollerId);
120 | if (enroller != null && card != null) {
121 | return new MyTutorDTO(
122 | enrollmentDTO.getEnrollmentId(),
123 | enrollerId,
124 | enroller.getName(),
125 | enroller.getSurname(),
126 | enroller.getEmail(),
127 | enroller.getContacts(),
128 | enroller.getDescription(),
129 | enroller.getPicture(),
130 | cardId,
131 | card.getSubject(),
132 | card.getDescription(),
133 | card.isHidden(),
134 | enrollmentDTO.getDescription(),
135 | enrollmentDTO.getSessionFormat(),
136 | enrollmentDTO.getSessionType()
137 | );
138 | }
139 | return null;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/UserService.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service;
2 |
3 | import innotutor.innotutor_backend.dto.UserDTO;
4 | import innotutor.innotutor_backend.entity.user.User;
5 | import innotutor.innotutor_backend.repository.user.UserRepository;
6 | import innotutor.innotutor_backend.security.CustomPrincipal;
7 | import lombok.AllArgsConstructor;
8 | import org.modelmapper.ModelMapper;
9 | import org.springframework.stereotype.Service;
10 |
11 | import java.util.Optional;
12 |
13 | @Service
14 | @AllArgsConstructor
15 | public class UserService {
16 |
17 | private final UserRepository userRepository;
18 | private final ModelMapper modelMapper;
19 |
20 | public UserDTO getUserById(final Long userId) {
21 | return userRepository.findById(userId).map(user -> modelMapper.map(user, UserDTO.class)).orElse(null);
22 | }
23 |
24 | public UserDTO getUserByEmail(final String email) {
25 | return userRepository.findByEmail(email).map(user -> modelMapper.map(user, UserDTO.class)).orElse(null);
26 | }
27 |
28 | public Long getUserId(final CustomPrincipal user) {
29 | final String email = user.getEmail();
30 | final UserDTO userDTO = getUserByEmail(email);
31 | return userDTO.getUserId();
32 | }
33 |
34 | public Boolean isUserEqualsId(final CustomPrincipal user, final Long userId) {
35 | return this.getUserId(user).equals(userId);
36 | }
37 |
38 | public boolean addUserToDatabase(final CustomPrincipal user) {
39 | if (user != null) {
40 | final String email = user.getEmail();
41 | final String fullName = user.getFullName();
42 | final String[] nameSurname = fullName.split(" ");
43 | final String name = nameSurname[0];
44 | final String surname = nameSurname[1];
45 | final String picture = user.getPicture();
46 | final User userToInsert = new User();
47 | userToInsert.setEmail(email);
48 | userToInsert.setName(name);
49 | userToInsert.setSurname(surname);
50 | userToInsert.setPicture(picture);
51 | userRepository.save(userToInsert);
52 | return true;
53 | }
54 | return false;
55 | }
56 |
57 | public UserDTO updateUserProfile(final UserDTO userDTO) {
58 | final Optional userOptional = userRepository.findById(userDTO.getUserId());
59 | if (userOptional.isPresent()) {
60 | final User user = userOptional.get();
61 | user.setName(userDTO.getName());
62 | user.setSurname(userDTO.getSurname());
63 | user.setContacts(userDTO.getContacts());
64 | user.setDescription(userDTO.getDescription());
65 | user.setPicture(userDTO.getPicture());
66 | return modelMapper.map(userRepository.save(user), UserDTO.class);
67 | }
68 | return null;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/card/CardCreatorUser.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.card;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import innotutor.innotutor_backend.entity.user.User;
5 |
6 | public class CardCreatorUser {
7 | private final transient Card card;
8 |
9 | public CardCreatorUser(final Card card) {
10 | this.card = card;
11 | }
12 |
13 | public Long creatorId() {
14 | if (card.getServiceByCardId() != null) {
15 | return card.getServiceByCardId().getTutorId();
16 | }
17 | if (card.getRequestByCardId() != null) {
18 | return card.getRequestByCardId().getStudentId();
19 | }
20 | return null;
21 | }
22 |
23 | public User creator() {
24 | if (card.getServiceByCardId() != null) {
25 | return card.getServiceByCardId().getUserByTutorId();
26 | }
27 | if (card.getRequestByCardId() != null) {
28 | return card.getRequestByCardId().getUserByStudentId();
29 | }
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/card/CardDTOCreator.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.card;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.dto.searcher.StudentRequestDTO;
5 | import innotutor.innotutor_backend.dto.searcher.TutorCvDTO;
6 | import innotutor.innotutor_backend.entity.card.Card;
7 | import innotutor.innotutor_backend.entity.user.User;
8 | import innotutor.innotutor_backend.service.CardEnrollService;
9 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.CardSessionFormatConverter;
10 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.CardSessionTypeConverter;
11 |
12 | public class CardDTOCreator {
13 | private final transient Card card;
14 | private final transient User creator;
15 | private final transient CardEnrollService cardEnrollService;
16 | private final transient Long userId;
17 |
18 | public CardDTOCreator(final Card card, final User creator,
19 | final CardEnrollService cardEnrollService, final Long userId) {
20 | this.card = card;
21 | this.creator = creator;
22 | this.cardEnrollService = cardEnrollService;
23 | this.userId = userId;
24 | }
25 |
26 | public CardDTO create() {
27 | final Ratings ratings = new Ratings(creator, card.getSubjectId());
28 | return new CardDTO(
29 | card.getCardId(),
30 | creator.getUserId(),
31 | card.getSubjectBySubjectId().getName(),
32 | ratings.averageRating(),
33 | ratings.countVoted(),
34 | card.getDescription(),
35 | card.getHidden(),
36 | new CardSessionFormatConverter(card.getCardSessionFormatsByCardId()).stringList(),
37 | new CardSessionTypeConverter(card.getCardSessionTypesByCardId()).stringList()
38 | );
39 | }
40 |
41 | public TutorCvDTO createTutorCvDTO() {
42 | final Long cardId = card.getCardId();
43 | final Ratings ratings = new Ratings(creator, card.getSubjectId());
44 | return new TutorCvDTO(
45 | creator.getUserId(),
46 | creator.getName(),
47 | creator.getSurname(),
48 | cardId,
49 | ratings.averageRating(),
50 | ratings.countVoted(),
51 | card.getDescription(),
52 | card.getSubjectBySubjectId().getName(),
53 | new CardSessionFormatConverter(card.getCardSessionFormatsByCardId()).stringList(),
54 | new CardSessionTypeConverter(card.getCardSessionTypesByCardId()).stringList(),
55 | cardEnrollService.isEnrolled(cardId, userId)
56 | );
57 | }
58 |
59 | public StudentRequestDTO createStudentRequestDTO() {
60 | final Long cardId = card.getCardId();
61 | return new StudentRequestDTO(
62 | creator.getUserId(),
63 | creator.getName(),
64 | creator.getSurname(),
65 | cardId,
66 | card.getDescription(),
67 | card.getSubjectBySubjectId().getName(),
68 | new CardSessionFormatConverter(card.getCardSessionFormatsByCardId()).stringList(),
69 | new CardSessionTypeConverter(card.getCardSessionTypesByCardId()).stringList(),
70 | cardEnrollService.isEnrolled(cardId, userId)
71 | );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/card/CardType.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.card;
2 |
3 | public enum CardType {
4 | SERVICE, REQUEST
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/card/Ratings.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.card;
2 |
3 | import innotutor.innotutor_backend.entity.session.Session;
4 | import innotutor.innotutor_backend.entity.session.SessionRating;
5 | import innotutor.innotutor_backend.entity.user.User;
6 |
7 | import java.util.Collection;
8 | import java.util.List;
9 | import java.util.stream.Collectors;
10 |
11 | public class Ratings {
12 |
13 | private final List marks;
14 |
15 | public Ratings(final User tutor, final Long subjectId) {
16 | this.marks = tutor.getSessionsByUserId()
17 | .stream()
18 | .filter(session -> session.getSubjectId().equals(subjectId))
19 | .map(Session::getSessionRatingsBySessionId)
20 | .flatMap(Collection::stream)
21 | .map(SessionRating::getMark)
22 | .collect(Collectors.toList());
23 | }
24 |
25 | public Double averageRating() {
26 | if (marks.isEmpty()) {
27 | return null;
28 | }
29 | double sum = 0;
30 | for (final Integer mark : marks) {
31 | sum += mark;
32 | }
33 | return sum / marks.size();
34 | }
35 |
36 | public Integer countVoted() {
37 | return marks.size();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/card/ValidSessionRating.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.card;
2 |
3 | public class ValidSessionRating {
4 |
5 | private final Integer mark;
6 | private final int LOW_MARK = 0;
7 | private final int HIGH_MARK = 5;
8 |
9 | public ValidSessionRating(final Integer mark) {
10 | this.mark = mark;
11 | }
12 |
13 | public boolean isValid() {
14 | return mark != null && mark >= LOW_MARK && mark <= HIGH_MARK;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/cardmanager/CardCreator.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.cardmanager;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.entity.card.Card;
5 | import innotutor.innotutor_backend.entity.session.SessionFormat;
6 | import innotutor.innotutor_backend.entity.session.SessionType;
7 | import innotutor.innotutor_backend.entity.session.Subject;
8 | import innotutor.innotutor_backend.entity.user.User;
9 | import innotutor.innotutor_backend.repository.card.CardRepository;
10 | import innotutor.innotutor_backend.repository.card.CardSessionFormatRepository;
11 | import innotutor.innotutor_backend.repository.card.CardSessionTypeRepository;
12 | import innotutor.innotutor_backend.repository.session.SessionFormatRepository;
13 | import innotutor.innotutor_backend.repository.session.SessionTypeRepository;
14 | import innotutor.innotutor_backend.repository.session.SubjectRepository;
15 | import innotutor.innotutor_backend.repository.user.RequestRepository;
16 | import innotutor.innotutor_backend.repository.user.ServiceRepository;
17 | import innotutor.innotutor_backend.repository.user.UserRepository;
18 | import innotutor.innotutor_backend.service.utility.card.CardType;
19 | import innotutor.innotutor_backend.service.utility.saver.SessionFormatsCardSaver;
20 | import innotutor.innotutor_backend.service.utility.saver.SessionTypesCardSaver;
21 | import innotutor.innotutor_backend.service.utility.saver.UserCardRelationSaver;
22 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.SessionFormatConverter;
23 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.SessionFormatEntityConverter;
24 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.SessionTypeConverter;
25 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.SessionTypeEntityConverter;
26 |
27 | import java.util.List;
28 |
29 | public class CardCreator {
30 | private final transient CardDTO cardDTO;
31 | private final transient CardType type;
32 | private final transient User creator;
33 | private final transient Subject subject;
34 | private final transient List sessionFormats;
35 | private final transient List sessionTypes;
36 | private final transient CardRepository cardRepository;
37 | private final transient ServiceRepository serviceRepository;
38 | private final transient RequestRepository requestRepository;
39 | private final transient CardSessionFormatRepository cardSessionFormatRepository;
40 | private final transient CardSessionTypeRepository cardSessionTypeRepository;
41 |
42 | public CardCreator(final CardDTO cardDTO,
43 | final CardType type,
44 | final CardRepository cardRepository,
45 | final UserRepository userRepository,
46 | final SubjectRepository subjectRepository,
47 | final SessionFormatRepository sessionFormatRepository,
48 | final SessionTypeRepository sessionTypeRepository,
49 | final ServiceRepository serviceRepository,
50 | final RequestRepository requestRepository,
51 | final CardSessionFormatRepository cardSessionFormatRepository,
52 | final CardSessionTypeRepository cardSessionTypeRepository) {
53 | this.cardDTO = cardDTO;
54 | this.type = type;
55 | this.cardRepository = cardRepository;
56 | this.serviceRepository = serviceRepository;
57 | this.requestRepository = requestRepository;
58 | this.cardSessionFormatRepository = cardSessionFormatRepository;
59 | this.cardSessionTypeRepository = cardSessionTypeRepository;
60 | creator = userRepository.findById(cardDTO.getCreatorId()).orElse(null);
61 | subject = subjectRepository.findSubjectByName(cardDTO.getSubject());
62 | sessionFormats = new SessionFormatEntityConverter(cardDTO.getSessionFormat(), sessionFormatRepository)
63 | .toEntityList();
64 | sessionTypes = new SessionTypeEntityConverter(cardDTO.getSessionType(), sessionTypeRepository).toEntityList();
65 | }
66 |
67 | public CardDTO postCard() {
68 | if (creator != null && subject != null && !sessionFormats.isEmpty() && !sessionTypes.isEmpty()) {
69 | return createCard();
70 | }
71 | return null;
72 | }
73 |
74 | private CardDTO createCard() {
75 | try {
76 | if (this.isUniquePair()) {
77 | Card card = cardRepository.save(new Card(
78 | subject.getSubjectId(),
79 | cardDTO.getDescription(),
80 | false,
81 | subject)
82 | );
83 | new UserCardRelationSaver(creator, card, type, serviceRepository, requestRepository).save();
84 | card = new SessionFormatsCardSaver(card, sessionFormats, cardSessionFormatRepository).save();
85 | card = new SessionTypesCardSaver(card, sessionTypes, cardSessionTypeRepository).save();
86 | return new CardDTO(
87 | card.getCardId(),
88 | creator.getUserId(),
89 | subject.getName(),
90 | null,
91 | 0,
92 | cardDTO.getDescription(),
93 | false,
94 | new SessionFormatConverter(sessionFormats).stringList(),
95 | new SessionTypeConverter(sessionTypes).stringList());
96 | }
97 | return null;
98 | } catch (IllegalAccessException e) {
99 | return null;
100 | }
101 | }
102 |
103 | private boolean isUniquePair() throws IllegalAccessException {
104 | switch (type) {
105 | case SERVICE:
106 | for (final Card card : cardRepository.findBySubjectId(subject.getSubjectId())) {
107 | if (card.getServiceByCardId() != null && card.getServiceByCardId().getTutorId().equals(creator.getUserId())) {
108 | return false;
109 | }
110 | }
111 | return true;
112 | case REQUEST:
113 | return true;
114 | default:
115 | throw new IllegalAccessException("The card type is not specified");
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/cardmanager/CardUpdater.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.cardmanager;
2 |
3 | import innotutor.innotutor_backend.dto.card.CardDTO;
4 | import innotutor.innotutor_backend.entity.card.Card;
5 | import innotutor.innotutor_backend.entity.session.SessionFormat;
6 | import innotutor.innotutor_backend.entity.session.SessionType;
7 | import innotutor.innotutor_backend.repository.card.CardRepository;
8 | import innotutor.innotutor_backend.repository.card.CardSessionFormatRepository;
9 | import innotutor.innotutor_backend.repository.card.CardSessionTypeRepository;
10 | import innotutor.innotutor_backend.repository.session.SessionFormatRepository;
11 | import innotutor.innotutor_backend.repository.session.SessionTypeRepository;
12 | import innotutor.innotutor_backend.repository.session.SubjectRepository;
13 | import innotutor.innotutor_backend.repository.user.RequestRepository;
14 | import innotutor.innotutor_backend.repository.user.ServiceRepository;
15 | import innotutor.innotutor_backend.repository.user.UserRepository;
16 | import innotutor.innotutor_backend.service.CardEnrollService;
17 | import innotutor.innotutor_backend.service.utility.card.CardCreatorUser;
18 | import innotutor.innotutor_backend.service.utility.card.CardDTOCreator;
19 | import innotutor.innotutor_backend.service.utility.card.CardType;
20 | import innotutor.innotutor_backend.service.utility.saver.SessionFormatsCardSaver;
21 | import innotutor.innotutor_backend.service.utility.saver.SessionTypesCardSaver;
22 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat.SessionFormatEntityConverter;
23 | import innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype.SessionTypeEntityConverter;
24 |
25 | import java.util.List;
26 |
27 |
28 | public class CardUpdater {
29 | private final transient CardDTO cardDTO;
30 | private final transient CardType type;
31 | private final transient Card card;
32 | private final transient List sessionFormats;
33 | private final transient List sessionTypes;
34 | private final transient Long userId;
35 | private final transient CardRepository cardRepository;
36 | private final transient UserRepository userRepository;
37 | private final transient SubjectRepository subjectRepository;
38 | private final transient SessionFormatRepository sessionFormatRepository;
39 | private final transient SessionTypeRepository sessionTypeRepository;
40 | private final transient ServiceRepository serviceRepository;
41 | private final transient RequestRepository requestRepository;
42 | private final transient CardSessionFormatRepository cardSessionFormatRepository;
43 | private final transient CardSessionTypeRepository cardSessionTypeRepository;
44 | private final transient CardEnrollService cardEnrollService;
45 |
46 | public CardUpdater(final CardDTO cardDTO,
47 | final CardType type,
48 | final Long userId,
49 | final CardRepository cardRepository,
50 | final UserRepository userRepository,
51 | final SubjectRepository subjectRepository,
52 | final SessionFormatRepository sessionFormatRepository,
53 | final SessionTypeRepository sessionTypeRepository,
54 | final ServiceRepository serviceRepository,
55 | final RequestRepository requestRepository,
56 | final CardSessionFormatRepository cardSessionFormatRepository,
57 | final CardSessionTypeRepository cardSessionTypeRepository,
58 | final CardEnrollService cardEnrollService) {
59 | this.cardDTO = cardDTO;
60 | this.type = type;
61 | this.userId = userId;
62 | this.cardRepository = cardRepository;
63 | this.userRepository = userRepository;
64 | this.subjectRepository = subjectRepository;
65 | this.sessionFormatRepository = sessionFormatRepository;
66 | this.sessionTypeRepository = sessionTypeRepository;
67 | this.serviceRepository = serviceRepository;
68 | this.requestRepository = requestRepository;
69 | this.cardSessionFormatRepository = cardSessionFormatRepository;
70 | this.cardSessionTypeRepository = cardSessionTypeRepository;
71 | this.cardEnrollService = cardEnrollService;
72 | card = cardRepository.findById(cardDTO.getCardId()).orElse(null);
73 | sessionFormats = new SessionFormatEntityConverter(
74 | cardDTO.getSessionFormat(),
75 | sessionFormatRepository
76 | ).toEntityList();
77 | sessionTypes = new SessionTypeEntityConverter(
78 | cardDTO.getSessionType(),
79 | sessionTypeRepository
80 | ).toEntityList();
81 | }
82 |
83 | public CardDTO putCard() {
84 | if (card == null) {
85 | return new innotutor.innotutor_backend.service.utility.cardmanager.CardCreator(cardDTO,
86 | type,
87 | cardRepository,
88 | userRepository,
89 | subjectRepository,
90 | sessionFormatRepository,
91 | sessionTypeRepository,
92 | serviceRepository,
93 | requestRepository,
94 | cardSessionFormatRepository,
95 | cardSessionTypeRepository).postCard();
96 | }
97 | if (cardDTO.getCreatorId().equals(new CardCreatorUser(card).creatorId())
98 | && !sessionFormats.isEmpty() && !sessionTypes.isEmpty()) {
99 | return this.updateCard();
100 | }
101 | return null;
102 | }
103 |
104 | private CardDTO updateCard() {
105 | card.setDescription(cardDTO.getDescription());
106 | card.setHidden(cardDTO.isHidden());
107 | Card savedCard = cardRepository.save(card);
108 | savedCard = this.updateSessionFormats(savedCard);
109 | savedCard = this.updateSessionTypes(savedCard);
110 | return new CardDTOCreator(savedCard, new CardCreatorUser(savedCard).creator(), cardEnrollService, userId).create();
111 | }
112 |
113 | private Card updateSessionFormats(final Card card) {
114 | cardSessionFormatRepository.deleteAll(card.getCardSessionFormatsByCardId());
115 | return new SessionFormatsCardSaver(card, sessionFormats, cardSessionFormatRepository).save();
116 | }
117 |
118 | private Card updateSessionTypes(final Card card) {
119 | cardSessionTypeRepository.deleteAll(card.getCardSessionTypesByCardId());
120 | return new SessionTypesCardSaver(card, sessionTypes, cardSessionTypeRepository).save();
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/saver/SessionFormatsCardSaver.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.saver;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import innotutor.innotutor_backend.entity.card.CardSessionFormat;
5 | import innotutor.innotutor_backend.entity.session.SessionFormat;
6 | import innotutor.innotutor_backend.repository.card.CardSessionFormatRepository;
7 | import lombok.AllArgsConstructor;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Collection;
11 | import java.util.List;
12 |
13 | @AllArgsConstructor
14 | public class SessionFormatsCardSaver {
15 | private final Card card;
16 | private final List sessionFormats;
17 | private final CardSessionFormatRepository cardSessionFormatRepository;
18 |
19 | public Card save() {
20 | final Collection cardSessionFormatsByCardId = new ArrayList<>();
21 | sessionFormats.forEach(format -> {
22 | final CardSessionFormat cardSessionFormat = new CardSessionFormat(
23 | card.getCardId(), format.getSessionFormatId(), card, format
24 | );
25 | cardSessionFormatRepository.save(cardSessionFormat);
26 | cardSessionFormatsByCardId.add(cardSessionFormat);
27 | });
28 | card.setCardSessionFormatsByCardId(cardSessionFormatsByCardId);
29 | return card;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/saver/SessionTypesCardSaver.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.saver;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import innotutor.innotutor_backend.entity.card.CardSessionType;
5 | import innotutor.innotutor_backend.entity.session.SessionType;
6 | import innotutor.innotutor_backend.repository.card.CardSessionTypeRepository;
7 | import lombok.AllArgsConstructor;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Collection;
11 | import java.util.List;
12 |
13 | @AllArgsConstructor
14 |
15 | public class SessionTypesCardSaver {
16 | private final Card card;
17 | private final List sessionTypes;
18 | private final CardSessionTypeRepository cardSessionTypeRepository;
19 |
20 | public Card save() {
21 | final Collection cardSessionTypesByCardId = new ArrayList<>();
22 | sessionTypes.forEach(type -> {
23 | final CardSessionType cardSessionType = new CardSessionType(card.getCardId(), type.getSessionTypeId(), card, type);
24 | cardSessionTypeRepository.save(cardSessionType);
25 | cardSessionTypesByCardId.add(cardSessionType);
26 | });
27 | card.setCardSessionTypesByCardId(cardSessionTypesByCardId);
28 | return card;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/saver/UserCardRelationSaver.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.saver;
2 |
3 | import innotutor.innotutor_backend.entity.card.Card;
4 | import innotutor.innotutor_backend.entity.user.Request;
5 | import innotutor.innotutor_backend.entity.user.Service;
6 | import innotutor.innotutor_backend.entity.user.User;
7 | import innotutor.innotutor_backend.repository.user.RequestRepository;
8 | import innotutor.innotutor_backend.repository.user.ServiceRepository;
9 | import innotutor.innotutor_backend.service.utility.card.CardType;
10 | import lombok.AllArgsConstructor;
11 |
12 | @AllArgsConstructor
13 | public class UserCardRelationSaver {
14 | private final User creator;
15 | private final Card card;
16 | private final CardType type;
17 | private final ServiceRepository serviceRepository;
18 | private final RequestRepository requestRepository;
19 |
20 | public void save() {
21 | switch (type) {
22 | case SERVICE:
23 | serviceRepository.save(new Service(creator.getUserId(), card.getCardId(), creator, card));
24 | break;
25 | case REQUEST:
26 | requestRepository.save(new Request(creator.getUserId(), card.getCardId(), creator, card));
27 | break;
28 | default:
29 | break;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/SessionConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter;
2 |
3 | import java.util.List;
4 |
5 | public interface SessionConverter {
6 | List stringList();
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessionformat/CardEnrollSessionFormatConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionFormat;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 |
11 | @AllArgsConstructor
12 | public class CardEnrollSessionFormatConverter implements SessionConverter {
13 | private final Collection formats;
14 |
15 | @Override
16 | public List stringList() {
17 | final List formatsNames = new ArrayList<>();
18 | for (final CardEnrollSessionFormat format : formats) {
19 | formatsNames.add(format.getSessionFormatBySessionFormatId().getName());
20 | }
21 | return formatsNames;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessionformat/CardSessionFormatConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionFormat;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 |
11 | @AllArgsConstructor
12 | public class CardSessionFormatConverter implements SessionConverter {
13 | private final Collection formats;
14 |
15 | @Override
16 | public List stringList() {
17 | final List formatsNames = new ArrayList<>();
18 | for (final CardSessionFormat format : formats) {
19 | formatsNames.add(format.getSessionFormatBySessionFormatId().getName());
20 | }
21 | return formatsNames;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessionformat/SessionFormatConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionFormat;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | @AllArgsConstructor
11 | public class SessionFormatConverter implements SessionConverter {
12 |
13 | private final List sessionFormat;
14 |
15 | @Override
16 | public List stringList() {
17 | final List formatsNames = new ArrayList<>();
18 | for (final SessionFormat format : sessionFormat) {
19 | formatsNames.add(format.getName());
20 | }
21 | return formatsNames;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessionformat/SessionFormatEntityConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessionformat;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionFormat;
4 | import innotutor.innotutor_backend.repository.session.SessionFormatRepository;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | @AllArgsConstructor
11 | public class SessionFormatEntityConverter {
12 | private final List formats;
13 | private final SessionFormatRepository sessionFormatRepository;
14 |
15 | public List toEntityList() {
16 | final List sessionFormats = new ArrayList<>();
17 | for (final String formatName : formats) {
18 | final SessionFormat sessionFormat = sessionFormatRepository.findSessionFormatByName(formatName);
19 | if (sessionFormat != null) {
20 | sessionFormats.add(sessionFormat);
21 | }
22 | }
23 | return sessionFormats;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessiontype/CardEnrollSessionTypeConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype;
2 |
3 | import innotutor.innotutor_backend.entity.card.enrollment.CardEnrollSessionType;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 |
11 | @AllArgsConstructor
12 | public class CardEnrollSessionTypeConverter implements SessionConverter {
13 | private final Collection types;
14 |
15 | @Override
16 | public List stringList() {
17 | final List formatsNames = new ArrayList<>();
18 | for (final CardEnrollSessionType type : types) {
19 | formatsNames.add(type.getSessionTypeBySessionTypeId().getName());
20 | }
21 | return formatsNames;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessiontype/CardSessionTypeConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype;
2 |
3 | import innotutor.innotutor_backend.entity.card.CardSessionType;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 |
11 | @AllArgsConstructor
12 | public class CardSessionTypeConverter implements SessionConverter {
13 |
14 | private final Collection types;
15 |
16 | @Override
17 | public List stringList() {
18 | final List formatsNames = new ArrayList<>();
19 | for (final CardSessionType type : types) {
20 | formatsNames.add(type.getSessionTypeBySessionTypeId().getName());
21 | }
22 | return formatsNames;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessiontype/SessionTypeConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionType;
4 | import innotutor.innotutor_backend.service.utility.sessionconverter.SessionConverter;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | @AllArgsConstructor
11 | public class SessionTypeConverter implements SessionConverter {
12 | private final List sessionType;
13 |
14 | @Override
15 | public List stringList() {
16 | final List typesNames = new ArrayList<>();
17 | for (final SessionType type : sessionType) {
18 | typesNames.add(type.getName());
19 | }
20 | return typesNames;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/innotutor/innotutor_backend/service/utility/sessionconverter/sessiontype/SessionTypeEntityConverter.java:
--------------------------------------------------------------------------------
1 | package innotutor.innotutor_backend.service.utility.sessionconverter.sessiontype;
2 |
3 | import innotutor.innotutor_backend.entity.session.SessionType;
4 | import innotutor.innotutor_backend.repository.session.SessionTypeRepository;
5 | import lombok.AllArgsConstructor;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | @AllArgsConstructor
11 | public class SessionTypeEntityConverter {
12 |
13 | private final List types;
14 | private final SessionTypeRepository sessionTypeRepository;
15 |
16 | public List toEntityList() {
17 | final List sessionTypes = new ArrayList<>();
18 | for (final String typeName : types) {
19 | final SessionType sessionType = sessionTypeRepository.findSessionTypeByName(typeName);
20 | if (sessionType != null) {
21 | sessionTypes.add(sessionType);
22 | }
23 | }
24 | return sessionTypes;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/innotutor}
2 | spring.datasource.username=${SPRING_DATASOURCE_USERNAME:postgres}
3 | spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:root}
4 | spring.datasource.driver-class-name=org.postgresql.Driver
5 | spring.jpa.hibernate.ddl-auto=none
6 | spring.jpa.show-sql=true
7 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL10Dialect
8 | spring.jpa.database=postgresql
9 | spring.jpa.properties.hibernate.format_sql=true
10 | GOOGLE_CREDENTIALS=
11 |
--------------------------------------------------------------------------------