-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cb34670
Showing
24 changed files
with
6,879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/kotlin,maven,intellij | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=kotlin,maven,intellij | ||
|
||
### Intellij ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# AWS User-specific | ||
.idea/**/aws.xml | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/artifacts | ||
# .idea/compiler.xml | ||
# .idea/jarRepositories.xml | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# SonarLint plugin | ||
.idea/sonarlint/ | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
### Intellij Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
# https://plugins.jetbrains.com/plugin/7973-sonarlint | ||
.idea/**/sonarlint/ | ||
|
||
# SonarQube Plugin | ||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin | ||
.idea/**/sonarIssues.xml | ||
|
||
# Markdown Navigator plugin | ||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced | ||
.idea/**/markdown-navigator.xml | ||
.idea/**/markdown-navigator-enh.xml | ||
.idea/**/markdown-navigator/ | ||
|
||
# Cache file creation bug | ||
# See https://youtrack.jetbrains.com/issue/JBR-2257 | ||
.idea/$CACHE_FILE$ | ||
|
||
# CodeStream plugin | ||
# https://plugins.jetbrains.com/plugin/12206-codestream | ||
.idea/codestream.xml | ||
|
||
# Azure Toolkit for IntelliJ plugin | ||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij | ||
.idea/**/azureSettings.xml | ||
|
||
### Kotlin ### | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
replay_pid* | ||
|
||
### Maven ### | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Eclipse m2e generated files | ||
# Eclipse Core | ||
.project | ||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/kotlin,maven,intellij |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>edu.unq</groupId> | ||
<artifactId>steam-model</artifactId> | ||
<version>1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>org.unq steam-model</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<kotlin.version>1.9.0</kotlin.version> | ||
<kotlin.code.style>official</kotlin.code.style> | ||
<junit.version>4.13.1</junit.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit</artifactId> | ||
<version>${kotlin.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package org.unq | ||
|
||
import org.unq.model.* | ||
|
||
fun <E> getPage(list: List<E>, page: Int): PageInfo<E> { | ||
if (page < 1) throw Exception("Page most be 1 or more") | ||
val chunkedList = list.chunked(10) | ||
return PageInfo( | ||
currentPage = page, | ||
list = chunkedList.getOrElse(page - 1) { listOf() }, | ||
amountOfElements = list.size, | ||
amountOfPages = chunkedList.size, | ||
) | ||
} | ||
|
||
class SteamSystem( | ||
val games: List<Game>, | ||
val developers: List<Developer>, | ||
val tags: List<Tag>, | ||
val users: MutableList<User>, | ||
) { | ||
|
||
private val idGenerator = IdGenerator() | ||
|
||
fun addNewUser(user: DraftUser): User { | ||
users.forEach { | ||
if (it.email == user.email) throw UserException("Email is token") | ||
} | ||
val newUser = User( | ||
idGenerator.nextUserId(), | ||
user.email, | ||
user.password, | ||
user.name, | ||
user.image, | ||
user.backgroundImage, | ||
mutableListOf(), | ||
mutableListOf(), | ||
) | ||
users.add(newUser) | ||
return newUser | ||
} | ||
|
||
fun getTag(id: String): Tag { | ||
return tags.find { it.id == id } ?: throw NotFoundTag() | ||
} | ||
|
||
fun getUser(id: String): User { | ||
return users.find { it.id == id } ?: throw NotFoundUser() | ||
} | ||
|
||
fun getGame(id: String): Game { | ||
return games.find { it.id == id } ?: throw NotFoundGame() | ||
} | ||
|
||
fun getDeveloper(id: String): Developer { | ||
return developers.find { it.id == id } ?: throw NotFoundDeveloper() | ||
} | ||
|
||
fun getUserReviews(userId: String): List<Review> { | ||
val user = getUser(userId) | ||
return games | ||
.flatMap { game -> game.reviews } | ||
.filter { it.user === user } | ||
} | ||
|
||
fun getRecommendedGames(): List<Game> { | ||
return games | ||
.sortedByDescending { game -> game.reviews.count { review -> review.isRecommended } } | ||
.take(10) | ||
} | ||
|
||
fun getGames(page: Int = 1): PageInfo<Game> { | ||
return getPage(games, page) | ||
} | ||
|
||
fun getGamesByTag(tagId: String, page: Int = 1): PageInfo<Game> { | ||
val tag = getTag(tagId) | ||
val filterGames = games.filter { it.tags.contains(tag) } | ||
return getPage(filterGames, page) | ||
} | ||
|
||
fun getGamesByDeveloper(developerId: String, page: Int = 1): PageInfo<Game> { | ||
val developer = getDeveloper(developerId) | ||
val filterGames = games.filter { it.developer == developer } | ||
return getPage(filterGames, page) | ||
} | ||
|
||
fun searchGame(name: String, page: Int = 1): PageInfo<Game> { | ||
val filterGames = games.filter { it.name.contains(name, true) } | ||
return getPage(filterGames, page) | ||
} | ||
|
||
fun searchUser(name: String, page: Int = 1): PageInfo<User> { | ||
val filterUsers = users.filter { it.name.contains(name, true) } | ||
return getPage(filterUsers, page) | ||
} | ||
|
||
fun addReview(userId: String, draftReview: DraftReview): Game { | ||
val user = getUser(userId) | ||
val game = getGame(draftReview.gameId) | ||
if (!user.games.contains(game)) throw ReviewException("You need to own the game to leave a review") | ||
game.reviews.find { it.user == user }?.let { throw ReviewException("You've already submitted a review for this game") } | ||
game.reviews.add(Review(idGenerator.nextReviewId(), user, draftReview.isRecommended, draftReview.text)) | ||
return game | ||
} | ||
|
||
fun purchaseGame(userId: String, draftPurchase: DraftPurchase): User { | ||
val user = getUser(userId) | ||
val game = getGame(draftPurchase.gameId) | ||
if(user.games.contains(game)) throw PurchaseException("You already have the game") | ||
user.games.add(game) | ||
return user | ||
} | ||
|
||
fun addOrRemoveFriend(userId: String, friendId: String): User { | ||
if (userId == friendId) throw UserException("You cannot self-add.") | ||
val user = getUser(userId) | ||
val friend = getUser(friendId) | ||
if (user.friends.remove(friend)) { | ||
friend.friends.remove(user) | ||
} else { | ||
user.friends.add(friend) | ||
friend.friends.add(user) | ||
} | ||
return user | ||
} | ||
|
||
} |
Oops, something went wrong.