From a04e334d6de5d9d9e4be687424005adcd8b2086f Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Wed, 2 Feb 2022 15:27:01 +0100 Subject: [PATCH 01/10] policy of no a-pis-ment --- README.md | 2 +- commit-msg | 8 ++++---- frontend/app.json | 2 +- frontend/package.json | 2 +- server/build.gradle.kts | 2 +- .../hello/HelloApplication.kt | 2 +- .../hello/api/AuthEndpoint.kt | 8 ++++---- .../hello/api/CardEndpoint.kt | 6 +++--- .../hello/api/RootEndpoint.kt | 2 +- .../hello/api/SearchEndpoint.kt | 7 +++---- .../persistence/cloudStorage/PhotosStorage.kt | 2 +- .../hello/persistence/database/DataSource.kt | 2 +- .../hello/persistence/database/SQLDialect.kt | 2 +- .../hello/persistence/database/entities/Card.kt | 4 ++-- .../persistence/database/entities/Token.kt | 2 +- .../hello/persistence/database/entities/User.kt | 2 +- .../persistence/database/ports/CardPort.kt | 8 ++++---- .../persistence/database/ports/TokenPort.kt | 8 ++++---- .../persistence/database/ports/UserPort.kt | 6 +++--- .../database/repositories/CardRepository.kt | 4 ++-- .../database/repositories/TokenRepository.kt | 10 ++++++++++ .../database/repositories/UserRepository.kt | 4 ++-- .../database/repositories/TokenRepository.kt | 10 ---------- .../src/main/resources/application.properties | 2 +- server/src/main/resources/main.db | Bin 0 -> 45056 bytes server/src/main/resources/test.db | Bin 0 -> 32768 bytes .../{pishello => hello}/hello/TestUtilities.kt | 2 +- .../hello/api/AuthEndpointTests.kt | 4 ++-- .../hello/api/CardEndpointTests.kt | 4 ++-- .../hello/api/RootEndpointTests.kt | 2 +- .../hello/api/SearchEndpointTests.kt | 4 ++-- 31 files changed, 61 insertions(+), 62 deletions(-) rename server/src/main/kotlin/{pishello => hello}/hello/HelloApplication.kt (91%) rename server/src/main/kotlin/{pishello => hello}/hello/api/AuthEndpoint.kt (90%) rename server/src/main/kotlin/{pishello => hello}/hello/api/CardEndpoint.kt (95%) rename server/src/main/kotlin/{pishello => hello}/hello/api/RootEndpoint.kt (88%) rename server/src/main/kotlin/{pishello => hello}/hello/api/SearchEndpoint.kt (83%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/cloudStorage/PhotosStorage.kt (97%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/DataSource.kt (93%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/SQLDialect.kt (99%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/entities/Card.kt (85%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/entities/Token.kt (93%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/entities/User.kt (91%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/ports/CardPort.kt (88%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/ports/TokenPort.kt (61%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/ports/UserPort.kt (74%) rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/repositories/CardRepository.kt (89%) create mode 100644 server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt rename server/src/main/kotlin/{pishello => hello}/hello/persistence/database/repositories/UserRepository.kt (66%) delete mode 100644 server/src/main/kotlin/pishello/hello/persistence/database/repositories/TokenRepository.kt create mode 100644 server/src/main/resources/main.db create mode 100644 server/src/main/resources/test.db rename server/src/test/kotlin/{pishello => hello}/hello/TestUtilities.kt (99%) rename server/src/test/kotlin/{pishello => hello}/hello/api/AuthEndpointTests.kt (97%) rename server/src/test/kotlin/{pishello => hello}/hello/api/CardEndpointTests.kt (97%) rename server/src/test/kotlin/{pishello => hello}/hello/api/RootEndpointTests.kt (97%) rename server/src/test/kotlin/{pishello => hello}/hello/api/SearchEndpointTests.kt (96%) diff --git a/README.md b/README.md index f809999..c4489c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PiS-Hello +# Hello Business card holder app Timeline: diff --git a/commit-msg b/commit-msg index fe0e6d9..64ffb62 100644 --- a/commit-msg +++ b/commit-msg @@ -2,12 +2,12 @@ # To enable this hook, copy locally this file and move to ".git/hooks/commit-msg". export MESSAGE=$(<$1) -export JIRA_ISSUE_TAG='HPIS-([0-9]*)' +export GITHUB_ISSUE_TAG='HELL-([0-9]*)' -if [[ $MESSAGE =~ $JIRA_ISSUE_TAG ]]; then - echo -e "\e[32mYes! It contains a JIRA issue!\e[0m" +if [[ $MESSAGE =~ GITHUB_ISSUE_TAG ]]; then + echo -e "\e[32mYes! It contains a GitHub issue!\e[0m" exit 0; fi -echo -e "\e[31mOh no... You forgot to add a JIRA issue number!\e[0m"; +echo -e "\e[31mOh no... You forgot to add a GitHub issue number!\e[0m"; exit 1; \ No newline at end of file diff --git a/frontend/app.json b/frontend/app.json index 6df1bf4..758f59d 100644 --- a/frontend/app.json +++ b/frontend/app.json @@ -33,7 +33,7 @@ "foregroundImage": "./assets/business-card.png", "backgroundColor": "#FFFFFF" }, - "package": "com.pishello.hellopis" + "package": "com.hello.hello" }, "web": { "favicon": "./assets/business-card.png" diff --git a/frontend/package.json b/frontend/package.json index 305620b..f207b9e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,5 +1,5 @@ { - "name": "pis-front", + "name": "hello", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 9a6b610..a1fb83d 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -13,7 +13,7 @@ plugins { jacoco } -group = "pis-hello" +group = "hello" version = "0.0.1-SNAPSHOT" java.sourceCompatibility = JavaVersion.VERSION_11 diff --git a/server/src/main/kotlin/pishello/hello/HelloApplication.kt b/server/src/main/kotlin/hello/hello/HelloApplication.kt similarity index 91% rename from server/src/main/kotlin/pishello/hello/HelloApplication.kt rename to server/src/main/kotlin/hello/hello/HelloApplication.kt index 68d1205..bd4bfeb 100644 --- a/server/src/main/kotlin/pishello/hello/HelloApplication.kt +++ b/server/src/main/kotlin/hello/hello/HelloApplication.kt @@ -1,4 +1,4 @@ -package pishello.hello +package hello.hello import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication diff --git a/server/src/main/kotlin/pishello/hello/api/AuthEndpoint.kt b/server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt similarity index 90% rename from server/src/main/kotlin/pishello/hello/api/AuthEndpoint.kt rename to server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt index 578a103..6fe0802 100644 --- a/server/src/main/kotlin/pishello/hello/api/AuthEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt @@ -1,11 +1,11 @@ -package pishello.hello.api +package hello.hello.api import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* -import pishello.hello.persistence.database.entities.Token -import pishello.hello.persistence.database.ports.TokenPort -import pishello.hello.persistence.database.ports.UserPort +import hello.hello.persistence.database.entities.Token +import hello.hello.persistence.database.ports.TokenPort +import hello.hello.persistence.database.ports.UserPort data class LoginRequest(val name: String, val password: String) diff --git a/server/src/main/kotlin/pishello/hello/api/CardEndpoint.kt b/server/src/main/kotlin/hello/hello/api/CardEndpoint.kt similarity index 95% rename from server/src/main/kotlin/pishello/hello/api/CardEndpoint.kt rename to server/src/main/kotlin/hello/hello/api/CardEndpoint.kt index 28bae1c..787eabe 100644 --- a/server/src/main/kotlin/pishello/hello/api/CardEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/api/CardEndpoint.kt @@ -1,12 +1,12 @@ -package pishello.hello.api +package hello.hello.api import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import org.springframework.web.multipart.MultipartFile -import pishello.hello.persistence.cloudStorage.PhotosStorage -import pishello.hello.persistence.database.ports.CardPort +import hello.hello.persistence.cloudStorage.PhotosStorage +import hello.hello.persistence.database.ports.CardPort data class CardRequest(val id: Int, val mode: String?, val category: String?) data class CardData(val id: Int, val company: String?, val name: String?, val phone: String?, val email: String?, val category: String?, val mode: String?) diff --git a/server/src/main/kotlin/pishello/hello/api/RootEndpoint.kt b/server/src/main/kotlin/hello/hello/api/RootEndpoint.kt similarity index 88% rename from server/src/main/kotlin/pishello/hello/api/RootEndpoint.kt rename to server/src/main/kotlin/hello/hello/api/RootEndpoint.kt index a6e5f12..3e8f08d 100644 --- a/server/src/main/kotlin/pishello/hello/api/RootEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/api/RootEndpoint.kt @@ -1,4 +1,4 @@ -package pishello.hello.api +package hello.hello.api import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController diff --git a/server/src/main/kotlin/pishello/hello/api/SearchEndpoint.kt b/server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt similarity index 83% rename from server/src/main/kotlin/pishello/hello/api/SearchEndpoint.kt rename to server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt index 27fefdc..a8a85d8 100644 --- a/server/src/main/kotlin/pishello/hello/api/SearchEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt @@ -1,11 +1,10 @@ -package pishello.hello.api +package hello.hello.api import org.springframework.http.HttpStatus -import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* -import pishello.hello.persistence.database.entities.Card -import pishello.hello.persistence.database.ports.CardPort +import hello.hello.persistence.database.entities.Card +import hello.hello.persistence.database.ports.CardPort @RestController class SearchEndpoint(val searchPort: CardPort) { diff --git a/server/src/main/kotlin/pishello/hello/persistence/cloudStorage/PhotosStorage.kt b/server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt similarity index 97% rename from server/src/main/kotlin/pishello/hello/persistence/cloudStorage/PhotosStorage.kt rename to server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt index eef1f05..15346cc 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/cloudStorage/PhotosStorage.kt +++ b/server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.cloudStorage +package hello.hello.persistence.cloudStorage import com.google.auth.Credentials import com.google.auth.oauth2.GoogleCredentials diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/DataSource.kt b/server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt similarity index 93% rename from server/src/main/kotlin/pishello/hello/persistence/database/DataSource.kt rename to server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt index a459a02..5d5ab52 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/DataSource.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.database +package hello.hello.persistence.database import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Bean diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/SQLDialect.kt b/server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt similarity index 99% rename from server/src/main/kotlin/pishello/hello/persistence/database/SQLDialect.kt rename to server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt index 3da0e70..f10e142 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/SQLDialect.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.database +package hello.hello.persistence.database import org.hibernate.dialect.Dialect import org.hibernate.dialect.function.SQLFunctionTemplate diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/entities/Card.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt similarity index 85% rename from server/src/main/kotlin/pishello/hello/persistence/database/entities/Card.kt rename to server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt index 731ce21..49da164 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/entities/Card.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.database.entities +package hello.hello.persistence.database.entities import org.hibernate.Hibernate import javax.persistence.* @@ -6,7 +6,7 @@ import javax.persistence.* @Entity(name = "cards") data class Card( @Id - @GeneratedValue(strategy = GenerationType.TABLE) + @GeneratedValue(strategy = GenerationType.TABLE) // TODO: IDENTITY val id: Int, var mode: String, var path: String?, diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/entities/Token.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt similarity index 93% rename from server/src/main/kotlin/pishello/hello/persistence/database/entities/Token.kt rename to server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt index 5f870ec..fe0085e 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/entities/Token.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.database.entities +package hello.hello.persistence.database.entities import org.hibernate.Hibernate import java.sql.Timestamp diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/entities/User.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt similarity index 91% rename from server/src/main/kotlin/pishello/hello/persistence/database/entities/User.kt rename to server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt index e88699f..b1c5e4b 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/entities/User.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt @@ -1,4 +1,4 @@ -package pishello.hello.persistence.database.entities +package hello.hello.persistence.database.entities import org.hibernate.Hibernate import javax.persistence.Entity diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/ports/CardPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt similarity index 88% rename from server/src/main/kotlin/pishello/hello/persistence/database/ports/CardPort.kt rename to server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt index 5e78082..624c1c7 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/ports/CardPort.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt @@ -1,9 +1,9 @@ -package pishello.hello.persistence.database.ports +package hello.hello.persistence.database.ports import org.springframework.stereotype.Component -import pishello.hello.persistence.database.entities.Card -import pishello.hello.persistence.database.repositories.CardRepository -import pishello.hello.persistence.database.repositories.UserRepository +import hello.hello.persistence.database.entities.Card +import hello.hello.persistence.database.repositories.CardRepository +import hello.hello.persistence.database.repositories.UserRepository @Component class CardPort(val repository: CardRepository, val userRepository: UserRepository) { diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/ports/TokenPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt similarity index 61% rename from server/src/main/kotlin/pishello/hello/persistence/database/ports/TokenPort.kt rename to server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt index 21c8422..b04bce0 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/ports/TokenPort.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt @@ -1,9 +1,9 @@ -package pishello.hello.persistence.database.ports +package hello.hello.persistence.database.ports import org.springframework.stereotype.Component -import pishello.hello.persistence.database.entities.Token -import pishello.hello.persistence.database.entities.User -import pishello.hello.persistence.database.repositories.TokenRepository +import hello.hello.persistence.database.entities.Token +import hello.hello.persistence.database.entities.User +import hello.hello.persistence.database.repositories.TokenRepository import java.sql.Timestamp import java.time.Instant import java.util.* diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/ports/UserPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt similarity index 74% rename from server/src/main/kotlin/pishello/hello/persistence/database/ports/UserPort.kt rename to server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt index d14289d..3aba304 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/ports/UserPort.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt @@ -1,8 +1,8 @@ -package pishello.hello.persistence.database.ports +package hello.hello.persistence.database.ports import org.springframework.stereotype.Component -import pishello.hello.persistence.database.entities.User -import pishello.hello.persistence.database.repositories.UserRepository +import hello.hello.persistence.database.entities.User +import hello.hello.persistence.database.repositories.UserRepository @Component class UserPort(val repository: UserRepository) { diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/CardRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt similarity index 89% rename from server/src/main/kotlin/pishello/hello/persistence/database/repositories/CardRepository.kt rename to server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt index 23b499b..7a8d314 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/CardRepository.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt @@ -1,9 +1,9 @@ -package pishello.hello.persistence.database.repositories +package hello.hello.persistence.database.repositories import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.query.Param -import pishello.hello.persistence.database.entities.Card +import hello.hello.persistence.database.entities.Card interface CardRepository: JpaRepository { diff --git a/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt new file mode 100644 index 0000000..a5fd57c --- /dev/null +++ b/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt @@ -0,0 +1,10 @@ +package hello.hello.persistence.database.repositories + +import org.springframework.data.repository.CrudRepository +import hello.hello.persistence.database.entities.Token +import hello.hello.persistence.database.entities.User + + +interface TokenRepository: CrudRepository { + fun findByName(name: User): Token? +} \ No newline at end of file diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/UserRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt similarity index 66% rename from server/src/main/kotlin/pishello/hello/persistence/database/repositories/UserRepository.kt rename to server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt index 0546ac6..f7a8eb6 100644 --- a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/UserRepository.kt +++ b/server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt @@ -1,7 +1,7 @@ -package pishello.hello.persistence.database.repositories +package hello.hello.persistence.database.repositories import org.springframework.data.repository.CrudRepository -import pishello.hello.persistence.database.entities.User +import hello.hello.persistence.database.entities.User interface UserRepository: CrudRepository { diff --git a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/TokenRepository.kt b/server/src/main/kotlin/pishello/hello/persistence/database/repositories/TokenRepository.kt deleted file mode 100644 index be88a28..0000000 --- a/server/src/main/kotlin/pishello/hello/persistence/database/repositories/TokenRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package pishello.hello.persistence.database.repositories - -import org.springframework.data.repository.CrudRepository -import pishello.hello.persistence.database.entities.Token -import pishello.hello.persistence.database.entities.User - - -interface TokenRepository: CrudRepository { - fun findByName(name: User): Token? -} \ No newline at end of file diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 4102ed4..61111cf 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.jpa.database-platform = pishello.hello.persistence.database.SQLDialect +spring.jpa.database-platform = hello.hello.persistence.database.SQLDialect spring.jpa.hibernate.ddl-auto = none spring.datasource.url = jdbc:sqlite:src/main/resources/main.db diff --git a/server/src/main/resources/main.db b/server/src/main/resources/main.db new file mode 100644 index 0000000000000000000000000000000000000000..7d22f2498870f27ecea89057158f8ffcf3c7acca GIT binary patch literal 45056 zcmeI5U2Ggz6~|}1AO2X+P7%1Pl_^~}w29?Ta_7#sprlT)Lh3Y1lPrZIWbWL#<8Jmd zyK6ZPsFG8)PdxCz3vWdTi8tVpw+bnJKp-k1B&a}CJitpNBoGo(UpRMWKNH-n;DN|F zBkzvq&i|Y_=XcN8yYq49+AEi8eNla(VMR?5(=2@5z zCw2JC$IQ}iO)Bd3>6!sN;L;uzCTgz7AgW@Ueqr!e+v#|LwwzvujAOR$R1dsp{ zKmthM|4X3oE%nLL$&>1vqR+yH=(p>l)!T`7clyoF)WXvFt6Q7bw<^~+&t2N8Os_h% zRDmgJlfNWWU)<`azqQ)^N^7stNJO%Uw_Ck_m(^PR)MlqsAFY$?JKb87bq^|aaqxVy zqQ#m*u1F{8d8F@(Sad~;i(X}~C%V1S3aM?kDtn!X!AD`vdYnZfb;rAc^=s|cPO_?B zYl>cbuT-}x7cYNt>nj5esYxnM5`hF#@0C-@eErq=eCbR{-B0`_3GYZa zgAF7N3;)Ug1JZQ|F07-ZZNH}?{>DS+YP{8S~}r%k*)57PBJ z_1t`^R8rq^5}%xPBj^Ko%TL)SO-pG7)uKTc!wjlJ?22yEFzgt)Fi||x6ly1tOcqTg z?JDTzrfBukK5w?8Q3;Jpvoh-QRMlbq*Hd>;&QNB9dVvbsZ9_rAG|}2_c33NEoM@da z)v>nodb>5;{J2##S*1_ESl{+Ze!X0IC zUK+jmwTYcSEx763{h74!nL$4#OG8dc^6A2`pGG_3L}w*7kKUes__Uf->7Az%1j&Aq zyvUX&qfr+r6ijs5>I!%L76`Ar>(_xw!pOAj*d{g!Y#vY^ zSwT!3lUw3Tx$MfJb{!6`MbwUopne3R&~!}~8koys9#Y>Vb{ufe4g_&5&$B(t^j+I_ zmNqiRy}+?tYH>fbd_M#~ zfiSH&@chW*zU{{LRwk<-YEI}nuqBT~k?lEzMS)AXMLGAl@Em6Pu^WODMqC#9wr|1~ z8IOg{UEgG*!k zDGQ^(;oNdPNH&NstJ$?f?P|MGmnqg66&~fTNqFRkzA%YNgyn@EgA9VejvSAKw&gfn zM5g5E@`w}ex|9k?IO1Xn`ZKS;tLPu<@9MwR|Dyk0|K+fYagGF#01`j~NB{{S0VIF~ zkN^@u0!RP}JQ@TFnN@Xg5GKEnSyAONl-yFLtfq%Rvbl_|IvJ@N9Dtb9GHZ+D;|KEl zzoy+&iYvOU7xcG_-_h>rKQ8`E|GNIW;ung4F77@Wd14eu00|%gB!C2v01`j~NB{{S z0VFUxfm4~PYT2BdvF#XyMAWc-mm6U$gb{K$v<&Fa}+JO>{fNbe>)Jf@N#qNQ<)jcU zR`6LIP=f(s11?4gjDU*B;BXNG4P(oqj>t+OwL(hZl)OPgW*N3{Oc^6L98MS!uz3>F zj1*deMrIgTM(oCrj7x2U!G#uv;1GcqLyU1acQR95WC5|L3p{MbAVw>IzNRs#12<;W zp$@T#{QeI&{o{lLkN^@u0!RP}AOR$R1dsp{Kmter2^?br^8SBKyF9ON!w3K;iXRn! zqy0d8zxZA4a`9}jT-??Fc#MlQ9d=1gCFwcCWT?cMtaK>D0Mw=Aigj!#jEDC_eJ1IakY2%&faeAHCDfS zheef6d$)UAgzf!#rT`Huqp~ z&};QtIOO$Q4q{3+rL0Xw?nwLbrSH#WkI>oo=`u&?tZ5xrld#L>wF_%gIo=oc_3mD? z6Q}Q#!k`3jyFVcpTXFleXb7Hw;4gL>r~8TUG;cR2f}T4fm;~flCrK-78i>Ypk8wfNKGH;Y?EUHiTEL#?HGk2fF89tj`; zB!C2v01`j~NB{{SfybVJqh+hBxmgC&A3U5*edGHt-@D{2OS4&q)*qXlJ#&Q?velK` zECcP!Te@LWpTAkQm$KDzZk93k(dWB=siR(^qLz11uKEpNpc1Q0*~0R#|0009ILK;W+m zY<(5JZCjHknd$|4oa!Vk4x2}By9cLTd3tbo+?7R@Y(*;6@=_)Jp-N;FXEGWG!JZtc zG`)%wZ+^6R@=u{S;>nNQb>y>Uz>tw6Q=T9$nte4V+&G|y*+-|bGvnw%FM9{N3g#kt)mkN#1sBNHyt!NM zZz;Y=UuW*63S`e8_)&Hzl1gjG>DKD@`_8h67Chf=FQ{BMqwhyP0w=Gm4cm;I&*LKI zzDm5bIMga}6;-n3d(w1J4|I9l^bOG Date: Thu, 3 Feb 2022 22:56:58 +0100 Subject: [PATCH 02/10] moved from Hibernate JPA to JetBrains Exposed --- server/build.gradle.kts | 6 +- .../kotlin/hello/hello/HelloApplication.kt | 4 +- .../hello/{ => adapters}/api/AuthEndpoint.kt | 13 +- .../hello/{ => adapters}/api/CardEndpoint.kt | 9 +- .../hello/{ => adapters}/api/RootEndpoint.kt | 2 +- .../{ => adapters}/api/SearchEndpoint.kt | 14 +- .../persistence/cloudStorage/PhotosStorage.kt | 2 +- .../persistence/database/DatabaseUtilities.kt | 35 +++++ .../database/adapters/CardAdapter.kt | 75 ++++++++++ .../database/adapters/TokenAdapter.kt | 23 +++ .../database/adapters/UserAdapter.kt | 28 ++++ .../database/entities/CardEntity.kt | 37 +++++ .../database/entities/TokenEntity.kt | 31 ++++ .../database/entities/UserEntity.kt | 25 ++++ .../kotlin/hello/hello/domain/models/Card.kt | 13 ++ .../kotlin/hello/hello/domain/models/Token.kt | 10 ++ .../kotlin/hello/hello/domain/models/User.kt | 6 + .../hello/persistence/database/DataSource.kt | 21 --- .../hello/persistence/database/SQLDialect.kt | 136 ------------------ .../persistence/database/entities/Card.kt | 32 ----- .../persistence/database/entities/Token.kt | 31 ---- .../persistence/database/entities/User.kt | 22 --- .../persistence/database/ports/CardPort.kt | 63 -------- .../persistence/database/ports/TokenPort.kt | 18 --- .../persistence/database/ports/UserPort.kt | 22 --- .../database/repositories/CardRepository.kt | 22 --- .../database/repositories/TokenRepository.kt | 10 -- .../database/repositories/UserRepository.kt | 10 -- .../resources/application-test.properties | 1 - .../src/main/resources/application.properties | 3 - server/src/main/resources/main.db | Bin 45056 -> 45056 bytes server/src/main/resources/test.db | Bin 32768 -> 32768 bytes .../test/kotlin/hello/hello/TestUtilities.kt | 27 ++++ .../hello/hello/api/AuthEndpointTests.kt | 33 ++--- .../hello/hello/api/CardEndpointTests.kt | 8 -- .../hello/hello/api/RootEndpointTests.kt | 10 +- .../hello/hello/api/SearchEndpointTests.kt | 28 ++-- 37 files changed, 363 insertions(+), 467 deletions(-) rename server/src/main/kotlin/hello/hello/{ => adapters}/api/AuthEndpoint.kt (86%) rename server/src/main/kotlin/hello/hello/{ => adapters}/api/CardEndpoint.kt (92%) rename server/src/main/kotlin/hello/hello/{ => adapters}/api/RootEndpoint.kt (86%) rename server/src/main/kotlin/hello/hello/{ => adapters}/api/SearchEndpoint.kt (72%) rename server/src/main/kotlin/hello/hello/{ => adapters}/persistence/cloudStorage/PhotosStorage.kt (97%) create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/DatabaseUtilities.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/CardEntity.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/TokenEntity.kt create mode 100644 server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/UserEntity.kt create mode 100644 server/src/main/kotlin/hello/hello/domain/models/Card.kt create mode 100644 server/src/main/kotlin/hello/hello/domain/models/Token.kt create mode 100644 server/src/main/kotlin/hello/hello/domain/models/User.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt delete mode 100644 server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt diff --git a/server/build.gradle.kts b/server/build.gradle.kts index a1fb83d..93883fa 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -25,11 +25,15 @@ dependencies { val springBootVersion = "2.6.2" val jacocoVersion = "0.8.7" val sqliteJDBCVersion = "3.36.0.2" + val exposedVersion = "0.37.3" implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.jetbrains.exposed:exposed-core:$exposedVersion") + implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion") + implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion") + implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion") implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") - implementation("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion") implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") implementation("org.xerial:sqlite-jdbc:$sqliteJDBCVersion") implementation("org.jacoco:org.jacoco.core:$jacocoVersion") diff --git a/server/src/main/kotlin/hello/hello/HelloApplication.kt b/server/src/main/kotlin/hello/hello/HelloApplication.kt index bd4bfeb..0272139 100644 --- a/server/src/main/kotlin/hello/hello/HelloApplication.kt +++ b/server/src/main/kotlin/hello/hello/HelloApplication.kt @@ -1,5 +1,6 @@ package hello.hello +import hello.hello.adapters.persistence.database.init import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @@ -7,5 +8,6 @@ import org.springframework.boot.runApplication class HelloApplication fun main(args: Array) { - runApplication(*args) + val context = runApplication(*args) + init(context.environment) } diff --git a/server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt similarity index 86% rename from server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt rename to server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt index 6fe0802..635192b 100644 --- a/server/src/main/kotlin/hello/hello/api/AuthEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt @@ -1,16 +1,19 @@ -package hello.hello.api +package hello.hello.adapters.api import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* -import hello.hello.persistence.database.entities.Token -import hello.hello.persistence.database.ports.TokenPort -import hello.hello.persistence.database.ports.UserPort +import hello.hello.adapters.persistence.database.adapters.TokenAdapter +import hello.hello.adapters.persistence.database.adapters.UserAdapter +import hello.hello.domain.models.Token data class LoginRequest(val name: String, val password: String) @RestController -class AuthEndpoint(val userPort: UserPort, val tokenPort: TokenPort) { +class AuthEndpoint { + val userPort = UserAdapter() + val tokenPort = TokenAdapter() + @GetMapping("/check") fun check(@RequestParam name: String): ResponseEntity { return if (userPort.checkIfUserExists(name)) { diff --git a/server/src/main/kotlin/hello/hello/api/CardEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt similarity index 92% rename from server/src/main/kotlin/hello/hello/api/CardEndpoint.kt rename to server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt index 787eabe..1cf91b7 100644 --- a/server/src/main/kotlin/hello/hello/api/CardEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt @@ -1,19 +1,20 @@ -package hello.hello.api +package hello.hello.adapters.api import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import org.springframework.web.multipart.MultipartFile -import hello.hello.persistence.cloudStorage.PhotosStorage -import hello.hello.persistence.database.ports.CardPort +import hello.hello.adapters.persistence.cloudStorage.PhotosStorage +import hello.hello.adapters.persistence.database.adapters.CardAdapter data class CardRequest(val id: Int, val mode: String?, val category: String?) data class CardData(val id: Int, val company: String?, val name: String?, val phone: String?, val email: String?, val category: String?, val mode: String?) @RestController @RequestMapping("/card") -class CardEndpoint(val cardPort: CardPort, val photosStorage: PhotosStorage) { +class CardEndpoint(val photosStorage: PhotosStorage) { + val cardPort = CardAdapter() @PostMapping fun addCard(@RequestParam image: MultipartFile, @RequestParam ownerName: String): ResponseEntity { diff --git a/server/src/main/kotlin/hello/hello/api/RootEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/RootEndpoint.kt similarity index 86% rename from server/src/main/kotlin/hello/hello/api/RootEndpoint.kt rename to server/src/main/kotlin/hello/hello/adapters/api/RootEndpoint.kt index 3e8f08d..3ca3d5b 100644 --- a/server/src/main/kotlin/hello/hello/api/RootEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/RootEndpoint.kt @@ -1,4 +1,4 @@ -package hello.hello.api +package hello.hello.adapters.api import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController diff --git a/server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt similarity index 72% rename from server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt rename to server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt index a8a85d8..e0613da 100644 --- a/server/src/main/kotlin/hello/hello/api/SearchEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt @@ -1,15 +1,17 @@ -package hello.hello.api +package hello.hello.adapters.api import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* -import hello.hello.persistence.database.entities.Card -import hello.hello.persistence.database.ports.CardPort +import hello.hello.adapters.persistence.database.adapters.CardAdapter +import hello.hello.domain.models.Card @RestController -class SearchEndpoint(val searchPort: CardPort) { +class SearchEndpoint { + val searchPort = CardAdapter() + @GetMapping("/search") - fun search(@RequestParam id: Int?, @RequestParam profession: String?, @RequestParam ownername: String?): ResponseEntity> { + fun search(@RequestParam id: Int?, @RequestParam profession: String?, @RequestParam ownername: String?): ResponseEntity> { val result = searchPort.searchCards(id, profession, ownername) return if (result != null) { ResponseEntity(result, HttpStatus.OK) @@ -18,7 +20,7 @@ class SearchEndpoint(val searchPort: CardPort) { } @GetMapping("/{user}/cards") - fun getUserCards(@PathVariable user: String?): ResponseEntity> { + fun getUserCards(@PathVariable user: String?): ResponseEntity> { val result = searchPort.searchOwnerCards(ownerName = user) return if (result != null) { ResponseEntity(result, HttpStatus.OK) diff --git a/server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/cloudStorage/PhotosStorage.kt similarity index 97% rename from server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt rename to server/src/main/kotlin/hello/hello/adapters/persistence/cloudStorage/PhotosStorage.kt index 15346cc..8fb85fd 100644 --- a/server/src/main/kotlin/hello/hello/persistence/cloudStorage/PhotosStorage.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/cloudStorage/PhotosStorage.kt @@ -1,4 +1,4 @@ -package hello.hello.persistence.cloudStorage +package hello.hello.adapters.persistence.cloudStorage import com.google.auth.Credentials import com.google.auth.oauth2.GoogleCredentials diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/DatabaseUtilities.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/DatabaseUtilities.kt new file mode 100644 index 0000000..c297f5b --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/DatabaseUtilities.kt @@ -0,0 +1,35 @@ +package hello.hello.adapters.persistence.database + +import hello.hello.adapters.persistence.database.entities.CardTable +import hello.hello.adapters.persistence.database.entities.TokenTable +import hello.hello.adapters.persistence.database.entities.UserTable +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.transactions.TransactionManager +import org.jetbrains.exposed.sql.transactions.transaction +import org.springframework.core.env.Environment +import java.sql.Connection + +fun init(env: Environment) { + TransactionManager.defaultDatabase = Database.connect( + env.getRequiredProperty("spring.datasource.url"), + env.getRequiredProperty("spring.datasource.driver-class-name") + ) + TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE +} + +fun create() { + transaction { + SchemaUtils.create(UserTable) + SchemaUtils.create(TokenTable) + SchemaUtils.create(CardTable) + } +} + +fun drop() { + transaction { + SchemaUtils.drop(UserTable) + SchemaUtils.drop(TokenTable) + SchemaUtils.drop(CardTable) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt new file mode 100644 index 0000000..c7e0ea8 --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt @@ -0,0 +1,75 @@ +package hello.hello.adapters.persistence.database.adapters + +import hello.hello.adapters.persistence.database.adapters.UserAdapter.Companion.findByName +import hello.hello.adapters.persistence.database.entities.CardEntity +import hello.hello.adapters.persistence.database.entities.CardTable +import hello.hello.adapters.persistence.database.entities.toCard +import hello.hello.adapters.persistence.database.entities.toCardEntity +import hello.hello.domain.models.Card +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.transactions.transaction + +class CardAdapter { + private fun searchById(id: Int): List = + CardEntity.find { (CardTable.id eq id) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } + private fun searchByProfession(profession: String): List = + CardEntity.find { (CardTable.category eq profession) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } + private fun searchByOwnerName(owner: EntityID): List = + CardEntity.find { (CardTable.owner eq owner) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } + private fun findByOwner(owner: EntityID): List = + CardEntity.find { CardTable.owner eq owner }.toList().map { it.toCard() } + + fun searchCards(id: Int?, profession: String?, ownerName: String?): List? = + transaction { + when { + id != null -> searchById(id) + profession != null -> searchByProfession(profession) + ownerName != null -> findByName(ownerName)?.let { searchByOwnerName(it.id) } ?: emptyList() + else -> null + } + } + + fun searchOwnerCards(ownerName: String?): List? = + transaction { ownerName?.let { findByName(ownerName)?.let { findByOwner(it.id) } } } + + fun findById(id: Int): Card? = + transaction { CardEntity.findById(id)?.toCard() } + + fun createNewCard(userName: String, mode: String, category: String?): Card? = + transaction { + val owner = findByName(userName) ?: return@transaction null + CardEntity.new { + this.mode = mode + this.category = category + this.owner = owner + }.toCard() + } + + fun updateCard(id: Int, mode: String?, category: String?): Card? = + transaction { + val cardEntity = CardEntity.findById(id) ?: return@transaction null + mode?.let { cardEntity.mode = it } + category?.let { cardEntity.category = it } + cardEntity.toCard() + } + + fun setPath(card: Card, path: String): Card = + transaction { + val cardEntity = card.toCardEntity() + cardEntity.path = path + cardEntity.toCard() + } + + fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? = + transaction { + val cardEntity = CardEntity.findById(id) ?: return@transaction null + mode?.let { cardEntity.mode = it } + company?.let { cardEntity.company = it } + name?.let { cardEntity.name = it } + phone?.let { cardEntity.phone = it } + email?.let { cardEntity.email = it } + category?.let { cardEntity.category = it } + cardEntity.toCard() + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt new file mode 100644 index 0000000..e06581d --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt @@ -0,0 +1,23 @@ +package hello.hello.adapters.persistence.database.adapters + +import hello.hello.adapters.persistence.database.entities.TokenEntity +import hello.hello.adapters.persistence.database.entities.TokenTable +import hello.hello.adapters.persistence.database.entities.toToken +import hello.hello.adapters.persistence.database.entities.toUserEntity +import hello.hello.domain.models.Token +import hello.hello.domain.models.User +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.sql.transactions.transaction +import java.time.Instant +import java.util.* + +class TokenAdapter { + fun createNewToken(user: User): Token = + transaction { + TokenEntity.new { + this.token = EntityID(UUID.randomUUID().toString(), TokenTable) + this.name = user.toUserEntity() + this.creationDate = Instant.now() + }.toToken() + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt new file mode 100644 index 0000000..17d422b --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt @@ -0,0 +1,28 @@ +package hello.hello.adapters.persistence.database.adapters + +import hello.hello.adapters.persistence.database.entities.UserEntity +import hello.hello.adapters.persistence.database.entities.UserTable +import hello.hello.adapters.persistence.database.entities.toUser +import hello.hello.domain.models.User +import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.transactions.transaction + +class UserAdapter { + fun checkIfUserExists(username: String): Boolean = + transaction { findByName(username) != null } + + fun checkLogin(username: String, password: String): User? = + transaction { UserEntity.find { (UserTable.name eq username) and (UserTable.password eq password) }.firstOrNull()?.toUser() } + + fun createNewUser(argName: String, argPassword: String): User = + transaction { + UserEntity.new { + name = argName + password = argPassword + }.toUser() + } + + companion object { + internal fun findByName(name: String) = UserEntity.find { UserTable.name eq name }.firstOrNull() + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/CardEntity.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/CardEntity.kt new file mode 100644 index 0000000..692c93d --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/CardEntity.kt @@ -0,0 +1,37 @@ +package hello.hello.adapters.persistence.database.entities + +import hello.hello.domain.models.Card +import org.jetbrains.exposed.dao.IntEntity +import org.jetbrains.exposed.dao.IntEntityClass +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.dao.id.IntIdTable + + +object CardTable: IntIdTable(name = "cards") { + var mode = varchar("mode", 7) + var path = varchar("path", 120).nullable() + var category = varchar("category", 40).nullable() + var company = varchar("company", 40).nullable() + var name = varchar("name", 40).nullable() + var phone = varchar("phone", 12).nullable() + var email = varchar("email", 40).nullable() + var owner = reference("owner", UserTable) +} + +class CardEntity(id: EntityID): IntEntity(id) { + companion object : IntEntityClass(CardTable) + var mode by CardTable.mode + var path by CardTable.path + var category by CardTable.category + var company by CardTable.company + var name by CardTable.name + var phone by CardTable.phone + var email by CardTable.email + var owner by UserEntity referencedOn CardTable.owner +} + +fun CardEntity.toCard(): Card = + Card(id.value, mode, path, category, company, name, phone, email, owner.name) + +fun Card.toCardEntity(): CardEntity = + CardEntity.findById(id)!! diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/TokenEntity.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/TokenEntity.kt new file mode 100644 index 0000000..a6e1dc1 --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/TokenEntity.kt @@ -0,0 +1,31 @@ +package hello.hello.adapters.persistence.database.entities + +import hello.hello.domain.models.Token +import org.jetbrains.exposed.dao.Entity +import org.jetbrains.exposed.dao.EntityClass +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.dao.id.IdTable +import org.jetbrains.exposed.sql.javatime.timestamp +import java.util.* + +// TODO: this should be a UUIDTable +object TokenTable: IdTable(name = "tokens") { + val token = varchar("token", 40).entityId() + val name = reference("name", UserTable) + val creationDate = timestamp("creation_date") + + override val id = token +} + +class TokenEntity(id: EntityID): Entity(id) { + companion object : EntityClass(TokenTable) + var token by TokenTable.token + var name by UserEntity referencedOn TokenTable.name + var creationDate by TokenTable.creationDate +} + +fun TokenEntity.toToken(): Token = + Token(UUID.fromString(token.value), name.toUser(), creationDate) + +fun Token.toTokenEntity(): TokenEntity = + TokenEntity.findById(token.toString())!! diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/UserEntity.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/UserEntity.kt new file mode 100644 index 0000000..2c79174 --- /dev/null +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/entities/UserEntity.kt @@ -0,0 +1,25 @@ +package hello.hello.adapters.persistence.database.entities + +import hello.hello.domain.models.User +import org.jetbrains.exposed.dao.IntEntity +import org.jetbrains.exposed.dao.IntEntityClass +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.dao.id.IntIdTable +import org.jetbrains.exposed.sql.and + +object UserTable: IntIdTable(name = "users") { + val name = varchar("name", 40).uniqueIndex() + val password = varchar("password", 40) +} + +class UserEntity(id: EntityID): IntEntity(id) { + companion object : IntEntityClass(UserTable) + var name by UserTable.name + var password by UserTable.password +} + +fun UserEntity.toUser(): User = + User(this.name, this.password) + +fun User.toUserEntity(): UserEntity = + UserEntity.find { (UserTable.name eq name) and (UserTable.password eq password) }.first() diff --git a/server/src/main/kotlin/hello/hello/domain/models/Card.kt b/server/src/main/kotlin/hello/hello/domain/models/Card.kt new file mode 100644 index 0000000..35da49c --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/models/Card.kt @@ -0,0 +1,13 @@ +package hello.hello.domain.models + +data class Card( + var id: Int, + var mode: String, + var path: String?, + var category: String?, + var company: String?, + var name: String?, + var phone: String?, + var email: String?, + var owner: String +) diff --git a/server/src/main/kotlin/hello/hello/domain/models/Token.kt b/server/src/main/kotlin/hello/hello/domain/models/Token.kt new file mode 100644 index 0000000..21f2a34 --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/models/Token.kt @@ -0,0 +1,10 @@ +package hello.hello.domain.models + +import java.time.Instant +import java.util.UUID + +data class Token( + var token: UUID, + val name: User, + var creationDate: Instant +) \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/domain/models/User.kt b/server/src/main/kotlin/hello/hello/domain/models/User.kt new file mode 100644 index 0000000..b8a8371 --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/models/User.kt @@ -0,0 +1,6 @@ +package hello.hello.domain.models + +data class User( + var name: String, + var password: String +) diff --git a/server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt b/server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt deleted file mode 100644 index 5d5ab52..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/DataSource.kt +++ /dev/null @@ -1,21 +0,0 @@ -package hello.hello.persistence.database - -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.Bean -import org.springframework.core.env.Environment -import org.springframework.jdbc.datasource.DriverManagerDataSource -import javax.sql.DataSource - - -@Autowired -var env: Environment? = null - -@Bean -fun dataSource(): DataSource { - val dataSource = DriverManagerDataSource() - dataSource.setDriverClassName(env!!.getProperty("spring.jpa.database-platform")!!) - dataSource.url = env!!.getProperty("spring.datasource.url")!! -// dataSource.username = env!!.getProperty("user") -// dataSource.password = env!!.getProperty("password") - return dataSource -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt b/server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt deleted file mode 100644 index f10e142..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/SQLDialect.kt +++ /dev/null @@ -1,136 +0,0 @@ -package hello.hello.persistence.database - -import org.hibernate.dialect.Dialect -import org.hibernate.dialect.function.SQLFunctionTemplate -import org.hibernate.dialect.function.StandardSQLFunction -import org.hibernate.dialect.function.VarArgsSQLFunction -import org.hibernate.type.StringType -import java.sql.Types - - -class SQLDialect: Dialect() { - init { - registerColumnType(Types.BIT, "integer") - registerColumnType(Types.TINYINT, "tinyint") - registerColumnType(Types.SMALLINT, "smallint") - registerColumnType(Types.INTEGER, "integer") - registerColumnType(Types.BIGINT, "bigint") - registerColumnType(Types.FLOAT, "float") - registerColumnType(Types.REAL, "real") - registerColumnType(Types.DOUBLE, "double") - registerColumnType(Types.NUMERIC, "numeric") - registerColumnType(Types.DECIMAL, "decimal") - registerColumnType(Types.CHAR, "char") - registerColumnType(Types.VARCHAR, "varchar") - registerColumnType(Types.LONGVARCHAR, "longvarchar") - registerColumnType(Types.DATE, "date") - registerColumnType(Types.TIME, "time") - registerColumnType(Types.TIMESTAMP, "timestamp") - registerColumnType(Types.BINARY, "blob") - registerColumnType(Types.VARBINARY, "blob") - registerColumnType(Types.LONGVARBINARY, "blob") - // registerColumnType(Types.NULL, "null"); - registerColumnType(Types.BLOB, "blob") - registerColumnType(Types.CLOB, "clob") - registerColumnType(Types.BOOLEAN, "integer") - registerFunction("concat", VarArgsSQLFunction(StringType.INSTANCE, "", "||", "")) - registerFunction("mod", SQLFunctionTemplate(StringType.INSTANCE, "?1 % ?2")) - registerFunction("substr", StandardSQLFunction("substr", StringType.INSTANCE)) - registerFunction("substring", StandardSQLFunction("substr", StringType.INSTANCE)) - } - - fun supportsIdentityColumns(): Boolean { - return true - } - - fun hasDataTypeInIdentityColumn(): Boolean { - return false // As specify in NHibernate dialect - } - - // return "integer primary key autoincrement"; - val identityColumnString: String - get() =// return "integer primary key autoincrement"; - "integer" - - val identitySelectString: String - get() = "select last_insert_rowid()" - - override fun supportsLimit(): Boolean { - return true - } - - override fun getLimitString(query: String, hasOffset: Boolean): String { - return StringBuffer(query.length + 20).append(query).append(if (hasOffset) " limit ? offset ?" else " limit ?") - .toString() - } - - fun supportsTemporaryTables(): Boolean { - return true - } - - val createTemporaryTableString: String - get() = "create temporary table if not exists" - - fun dropTemporaryTableAfterUse(): Boolean { - return false - } - - override fun supportsCurrentTimestampSelection(): Boolean { - return true - } - - override fun isCurrentTimestampSelectStringCallable(): Boolean { - return false - } - - override fun getCurrentTimestampSelectString(): String { - return "select current_timestamp" - } - - override fun supportsUnionAll(): Boolean { - return true - } - - override fun hasAlterTable(): Boolean { - return false // As specify in NHibernate dialect - } - - override fun dropConstraints(): Boolean { - return false - } - - override fun getAddColumnString(): String { - return "add column" - } - - override fun getForUpdateString(): String { - return "" - } - - override fun supportsOuterJoinForUpdate(): Boolean { - return false - } - - override fun getDropForeignKeyString(): String { - throw UnsupportedOperationException("No drop foreign key syntax supported by SQLiteDialect") - } - - override fun getAddForeignKeyConstraintString( - constraintName: String, foreignKey: Array, referencedTable: String, - primaryKey: Array, referencesPrimaryKey: Boolean - ): String { - throw UnsupportedOperationException("No add foreign key syntax supported by SQLiteDialect") - } - - override fun getAddPrimaryKeyConstraintString(constraintName: String): String { - throw UnsupportedOperationException("No add primary key syntax supported by SQLiteDialect") - } - - override fun supportsIfExistsBeforeTableName(): Boolean { - return true - } - - override fun supportsCascadeDelete(): Boolean { - return false - } -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt deleted file mode 100644 index 49da164..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/entities/Card.kt +++ /dev/null @@ -1,32 +0,0 @@ -package hello.hello.persistence.database.entities - -import org.hibernate.Hibernate -import javax.persistence.* - -@Entity(name = "cards") -data class Card( - @Id - @GeneratedValue(strategy = GenerationType.TABLE) // TODO: IDENTITY - val id: Int, - var mode: String, - var path: String?, - var category: String?, - var company: String?, - var name: String?, - var phone: String?, - var email: String?, - val owner: String // "FK" -) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false - other as Card - - return id == other.id - } - - override fun hashCode(): Int = javaClass.hashCode() - - @Override - override fun toString(): String = this::class.simpleName + "(id = $id )" -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt deleted file mode 100644 index fe0085e..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/entities/Token.kt +++ /dev/null @@ -1,31 +0,0 @@ -package hello.hello.persistence.database.entities - -import org.hibernate.Hibernate -import java.sql.Timestamp -import javax.persistence.Entity -import javax.persistence.Id -import javax.persistence.JoinColumn -import javax.persistence.ManyToOne - -@Entity(name = "tokens") -data class Token( - @Id - val token: String, - @ManyToOne - @JoinColumn(name = "name") - val name: User, - val creationDate: Timestamp -) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false - other as Token - - return token == other.token - } - - override fun hashCode(): Int = javaClass.hashCode() - - @Override - override fun toString(): String = this::class.simpleName + "(token = $token )" -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt b/server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt deleted file mode 100644 index b1c5e4b..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/entities/User.kt +++ /dev/null @@ -1,22 +0,0 @@ -package hello.hello.persistence.database.entities - -import org.hibernate.Hibernate -import javax.persistence.Entity -import javax.persistence.Id - -@Entity(name = "users") -data class User( - @Id val name: String, - val password: String -) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false - other as User - return name == other.name - } - - override fun hashCode(): Int = javaClass.hashCode() - - override fun toString(): String = this::class.simpleName + "(name = $name )" -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt deleted file mode 100644 index 624c1c7..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/ports/CardPort.kt +++ /dev/null @@ -1,63 +0,0 @@ -package hello.hello.persistence.database.ports - -import org.springframework.stereotype.Component -import hello.hello.persistence.database.entities.Card -import hello.hello.persistence.database.repositories.CardRepository -import hello.hello.persistence.database.repositories.UserRepository - -@Component -class CardPort(val repository: CardRepository, val userRepository: UserRepository) { - fun searchCards(id: Int?, profession: String?, ownerName: String?): List? { - return when { - id != null -> repository.searchById(id) - profession != null -> repository.searchByProfession(profession) - ownerName != null -> repository.searchByOwnerName(ownerName) - else -> null - } - } - - fun searchOwnerCards(ownerName: String?): List? { - return ownerName?.let { repository.findByOwner(it) } - } - - fun findById(cardId: Int): Card? { - return repository.findById(cardId) - } - - fun createNewCard(userName: String, mode: String, category: String?): Card? { - userRepository.findByName(userName) ?: return null - val card = Card(0, mode, null, category, null, null, null, null, userName) - return repository.save(card) - } - - fun updateCard(id: Int, mode: String?, category: String?): Card? { - val card = repository.findById(id) ?: return null - if (mode != null) - card.mode = mode - if (category != null) - card.category = category - return repository.save(card) - } - - fun setPath(card: Card, path: String): Card? { - card.path = path - return repository.save(card) - } - - fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? { - val card = repository.findById(id) ?: return null - if (company != null) - card.company = company - if (name != null) - card.name = name - if (phone != null) - card.phone = phone - if (email != null) - card.email = email - if (category != null) - card.category = category - if (mode != null) - card.mode = mode - return repository.save(card) - } -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt deleted file mode 100644 index b04bce0..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/ports/TokenPort.kt +++ /dev/null @@ -1,18 +0,0 @@ -package hello.hello.persistence.database.ports - -import org.springframework.stereotype.Component -import hello.hello.persistence.database.entities.Token -import hello.hello.persistence.database.entities.User -import hello.hello.persistence.database.repositories.TokenRepository -import java.sql.Timestamp -import java.time.Instant -import java.util.* - -@Component -class TokenPort(val repository: TokenRepository) { - fun createNewToken(userId: User): Token { - val token = Token(UUID.randomUUID().toString(), userId, Timestamp.from(Instant.now())) - repository.save(token) - return token - } -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt b/server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt deleted file mode 100644 index 3aba304..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/ports/UserPort.kt +++ /dev/null @@ -1,22 +0,0 @@ -package hello.hello.persistence.database.ports - -import org.springframework.stereotype.Component -import hello.hello.persistence.database.entities.User -import hello.hello.persistence.database.repositories.UserRepository - -@Component -class UserPort(val repository: UserRepository) { - fun checkIfUserExists(username: String): Boolean { - return repository.findByName(username) != null - } - - fun checkLogin(username: String, password: String): User? { - return repository.findByNameAndPassword(username, password) - } - - fun createNewUser(username: String, password: String): User { - val user = User(username, password) - repository.save(user) - return user - } -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt deleted file mode 100644 index 7a8d314..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/repositories/CardRepository.kt +++ /dev/null @@ -1,22 +0,0 @@ -package hello.hello.persistence.database.repositories - -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.Query -import org.springframework.data.repository.query.Param -import hello.hello.persistence.database.entities.Card - -interface CardRepository: JpaRepository { - - @Query("SELECT * FROM CARDS C WHERE C.ID = :id AND C.MODE = :mode", nativeQuery = true) - fun searchById(@Param("id") id: Int?, @Param("mode") mode: String? = "PUBLIC"): List? - - @Query("SELECT * FROM CARDS C WHERE C.CATEGORY= :profession AND C.MODE = :mode", nativeQuery = true) - fun searchByProfession(@Param("profession") profession: String?, @Param("mode") mode: String? = "PUBLIC"): List? - - @Query("SELECT * FROM CARDS C WHERE C.OWNER= :ownerName AND C.MODE = :mode", nativeQuery = true) - fun searchByOwnerName(@Param("ownerName") ownerName: String?, @Param("mode") mode: String? = "PUBLIC"): List? - - fun findByOwner(@Param("ownerName") ownerName: String):List? - - fun findById(id: Int): Card? -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt deleted file mode 100644 index a5fd57c..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/repositories/TokenRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package hello.hello.persistence.database.repositories - -import org.springframework.data.repository.CrudRepository -import hello.hello.persistence.database.entities.Token -import hello.hello.persistence.database.entities.User - - -interface TokenRepository: CrudRepository { - fun findByName(name: User): Token? -} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt b/server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt deleted file mode 100644 index f7a8eb6..0000000 --- a/server/src/main/kotlin/hello/hello/persistence/database/repositories/UserRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package hello.hello.persistence.database.repositories - -import org.springframework.data.repository.CrudRepository -import hello.hello.persistence.database.entities.User - - -interface UserRepository: CrudRepository { - fun findByName(name: String): User? - fun findByNameAndPassword(name: String, password: String): User? -} \ No newline at end of file diff --git a/server/src/main/resources/application-test.properties b/server/src/main/resources/application-test.properties index cf20c1f..4b94c30 100644 --- a/server/src/main/resources/application-test.properties +++ b/server/src/main/resources/application-test.properties @@ -1,2 +1 @@ -spring.jpa.hibernate.ddl-auto = create-drop spring.datasource.url = jdbc:sqlite:src/main/resources/test.db \ No newline at end of file diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 61111cf..eadb8c7 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -1,6 +1,3 @@ -spring.jpa.database-platform = hello.hello.persistence.database.SQLDialect -spring.jpa.hibernate.ddl-auto = none - spring.datasource.url = jdbc:sqlite:src/main/resources/main.db spring.datasource.driver-class-name = org.sqlite.JDBC spring.servlet.multipart.max-file-size=128MB diff --git a/server/src/main/resources/main.db b/server/src/main/resources/main.db index 7d22f2498870f27ecea89057158f8ffcf3c7acca..e7eab2692b9f480d157c564aef550dc0148067e3 100644 GIT binary patch delta 1691 zcmcgsUrbw77(eIU-rM%xo_mG zVq%AJZ!STP5Ay*~-;8EUY+{U0iw`C)Joq$qK_r=p2~IP!%m-)G^W9dr5qQ*da=!DO z-}mQy=eyr`&ut0kwuEKxzBoci<;%^Nz?b%BXCx3uhenqPxs6W12+ysgG6fw~XftV79`)$8bn&dH`83gOqzmaG?N(+kCPp_oi%lBK!%`*~?FF%+8^ zGACjKV?$=EEoxQ5ipfXLnoGlOmeOZRu;=n6Gq*51+i8pEtzvO8Ur6l~chuxlnyeqz zaXFhyrO#CF1dqvudw|IPR6`B6w|vgDb<8j*wX;R_bdcOWL1eu{$BXw&lG)V#9t7^8 zsp(&AhpTL=(&PCYJ3Ekz=Mh!zk}h24jHEBcJx*QMA4rdV|9_B>T0XKV$f4;r&1|le z&ZG0(JDV!)lq&(2r{AgbuaqeW{m zT{tT!qJc*Nwj2P*Qr28-V36NO@evU`qdH!QncZi_>{=%dZ5h47Zap3XCc%vUXB-IO zci8tUL5VxS^Q>_-$Ug0V7+^nJ;s+%P2ei(9UJXhT{f3)a(GWoGY-%mYE>-1Wwh;|B z5Dv>)1kuaXqK3AvEoqTTz--Z+W3uF3B8Wx(!_E;&Y6Sib|C7#9hhzYM&40{!Oq3|_ ztt~OUTGK!lJC2oJUeVRm`Csb0_wBpYopC*a=h5Pv?~nC^X6 z&@#y56ua?pUcizQlAS#YO6m8A-#L5vn=@dr}EmS$o)VVN5IzS z*hBg#Na-k2sotyNnafc7e zoqTK0KC)w0%w?U(8b$AWC0_8s`dYW(SKo`@9OL*5$Bq6VySNhL#Vj0T->vjO)&I)s zS6>3=JS$fjgZ;D`k?9vG$4#tgkUh0Vp#J;V$+bCPjC6UG(DT| delta 1328 zcmc&zOKclO7@oCv*Y@ttj3X;-SDQ9#Wz!@iYU@`*ielp!leS5nkj5Z{Vzb1H8~loF zMN5A)!b}xiGtHL4%YtBmFzy zeDlpW|35Rkb>Fph-_=%oQUCyvhL48J>Tiujf+=wB+6xf=3A|zp;8Fae^tu!ge?i0W zNNkBoG1&?FKk|`LVU=v6k9jJ5_v#Q~P=8OMm~U3r@}Xv}WL6vbLXot@75!NcFQ1p0 z)@rq2zOvph>y3QXsF?Zne+e&%i-TCJRW*BF8@2?Uu=EY%`3rbuMPWKe@B%Zo-OqSr zS!P~4-85b-o3_~gxKfMh0zE9TSqnr(BvwzL)yQKKA-GtF6^nD@J`oE14T) z6U(wqYFf3{)T-;{vM@5@;^irsR^Ni}45ZhAOg8UWJZ(Imj1;T7D6_R&o=NzY>t z@v}UuZbNc0Gs9ov*j@_X$UMnkVOfR3+nJ~Mw422gYV%2c)@5t2&(H7~h7D5oi}@?> zulY5>+5#Q`)Qh87#5YkJ9^g;WS9lr!gyQHyN4xL?WQW~ZhWs%#=l~_2alpMDofGW2 z-d&x18GqEFx9LDgbO*oh>Ktclj6`?+^Lsk^gw7ASvp#Ysq4QP}z~2dO-NU!q>RWC0 z41^gEo~1Pppd)k}egOB;+c1L?NI^w>m)1W9rE5L`Cv%WD( z{geUf*bmf&?DX8_)QV9rG|rEodwH!mJ~_=p%tmv{Yi%(Q7_zLs&W+vZ zE;-9lD=SX`f(wh6pP|pmNi=39x>zfhjJowX%buW%{zvCNK^Hl$lU5izAw>z!1W74B zUwCLQ*9jis;~q}dkcyo%>OEFK$llSa-Fm$YJ_PvCx!nb+b69)C&vBGzyBFR=FT4-J z34p)FZ{jRIgMLMyqgPQHVfZur5LP={TZViLvRRd*uTT#p3q~b5onkiMyLvDelWbmz z>*SrCBpVgjEV;WAW}`j|0=w7QsE2|Z6vQ|Re%p=kG1gvUBy@6V53(^g<)7QDu#Yhm Oe7ARzX7m645q|^rBwsuL diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index 91293967b1d0509715dd6b5db3fbb05ebb234fbd..b632f1ba718f2cf73b7ebfd305945b7cac03fffd 100644 GIT binary patch literal 32768 zcmeI)&u-H&90%}Z9fehF<-in8Lc;X2RvUi?NF1Sb1}eIAWGP~&5E_p~Ym<_s8k4vn z#1$Tb$KU~Y86JY4?WQHDph=uIeX}KPY{&KQ^K+_ZRkrt{6J~-P#L3Xl*gfNlVVcGx z#tdWWhhZ3(XuUvd*)S^K>2Z8#oE!qUu`nvhq%=|Y4wYRo5*%MiOB%)MrFSQ)rbUAaIk2{>z zbYZPhuP|EFo_wN~mrbYjtm)M6-)XQY&R8@a3{*2&+mETo#1ErPAC-EeqiLmVFiOIq zpPaBGak8l@B7Z1kgB03A;b&nSd8)a~Urk3hjl8k^%~;u4H;pg~#QT)?Za!Sg z_udWYv%lw$vsl&UW8TtZFIAIL$+9f-^IMr7(f5-eRhx^2bf_X$4+BO#{3&#DfH9R7qm+-~tbopR!8u&&Lvd56=)b~yFdZn?6kx4SLp zdS2A1Cgul=&WlgCRT^}1^tN0`gf3%s^;nE#rmR_t;mnywv%C~z)vqy~*2P%0`F{p$ ze3f(VogQklPzY5Oop#R6n+j8qk)Ni=aT3h+YV0nQt&I(HUkxVJ=SwQyjn&Cp z++8dT@Q=22$-YTPHso9R7i)FZ{CJ`|?a>>6T#ND5WKpdcV7W|J;j}zoEL%4$bEwW) z1)tCXEfmV5^!9`lJKmY;|fB*y_ z009U<00Izz00ba#HU%!1t}kWuuSGoh2Y~$h|FaniMhyW7KmY;|fB*y_009U<00Izz zz-a_<{eK!Iw1EHwAOHafKmY;|fB*y_009V`Z2?^WpY8l%^bmjm1Rwwb2tWV=5P$## KAOL~W2>b#)@3yW0 literal 32768 zcmeI)zi!h&9Ki82Y10y^YBwwDz)37Il%gmzg0{+l=m4|~49HyKYhvm@sqOU77)B&s zfrsHCcoNt-J4vytWMhEnd$oPNv(LWY$G6-i%E_B!KhyFoPC}K*j@S{FC0dWB=siR(^qLz11uKEpNpc1Q0*~0R#|0009ILK;W+m zY<(5JZCjHknd$|4oa!Vk4x2}By9cLTd3tbo+?7R@Y(*;6@=_)Jp-N;FXEGWG!JZtc zG`)%wZ+^6R@=u{S;>nNQb>y>Uz>tw6Q=T9$nte4V+&G|y*+-|bGvnw%FM9{N3g#kt)mkN#1sBNHyt!NM zZz;Y=UuW*63S`e8_)&Hzl1gjG>DKD@`_8h67Chf=FQ{BMqwhyP0w=Gm4cm;I&*LKI zzDm5bIMga}6;-n3d(w1J4|I9l^bOG Date: Fri, 4 Feb 2022 00:05:59 +0100 Subject: [PATCH 03/10] added ports --- .../hello/hello/adapters/api/AuthEndpoint.kt | 6 ++++-- .../hello/hello/adapters/api/CardEndpoint.kt | 3 ++- .../hello/adapters/api/SearchEndpoint.kt | 7 ++++--- .../database/adapters/CardAdapter.kt | 17 ++++++++-------- .../database/adapters/TokenAdapter.kt | 5 +++-- .../database/adapters/UserAdapter.kt | 9 +++++---- .../hello/hello/domain/ports/CardPort.kt | 19 ++++++++++++++++++ .../hello/hello/domain/ports/TokenPort.kt | 8 ++++++++ .../hello/hello/domain/ports/UserPort.kt | 11 ++++++++++ server/src/main/resources/test.db | Bin 32768 -> 32768 bytes 10 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt create mode 100644 server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt create mode 100644 server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt diff --git a/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt index 635192b..afe64bf 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt @@ -6,13 +6,15 @@ import org.springframework.web.bind.annotation.* import hello.hello.adapters.persistence.database.adapters.TokenAdapter import hello.hello.adapters.persistence.database.adapters.UserAdapter import hello.hello.domain.models.Token +import hello.hello.domain.ports.TokenPort +import hello.hello.domain.ports.UserPort data class LoginRequest(val name: String, val password: String) @RestController class AuthEndpoint { - val userPort = UserAdapter() - val tokenPort = TokenAdapter() + val userPort: UserPort = UserAdapter() + val tokenPort: TokenPort = TokenAdapter() @GetMapping("/check") fun check(@RequestParam name: String): ResponseEntity { diff --git a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt index 1cf91b7..5ee150d 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.web.multipart.MultipartFile import hello.hello.adapters.persistence.cloudStorage.PhotosStorage import hello.hello.adapters.persistence.database.adapters.CardAdapter +import hello.hello.domain.ports.CardPort data class CardRequest(val id: Int, val mode: String?, val category: String?) data class CardData(val id: Int, val company: String?, val name: String?, val phone: String?, val email: String?, val category: String?, val mode: String?) @@ -14,7 +15,7 @@ data class CardData(val id: Int, val company: String?, val name: String?, val ph @RestController @RequestMapping("/card") class CardEndpoint(val photosStorage: PhotosStorage) { - val cardPort = CardAdapter() + val cardPort: CardPort = CardAdapter() @PostMapping fun addCard(@RequestParam image: MultipartFile, @RequestParam ownerName: String): ResponseEntity { diff --git a/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt index e0613da..36ff483 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt @@ -5,14 +5,15 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import hello.hello.adapters.persistence.database.adapters.CardAdapter import hello.hello.domain.models.Card +import hello.hello.domain.ports.CardPort @RestController class SearchEndpoint { - val searchPort = CardAdapter() + val cardPort: CardPort = CardAdapter() @GetMapping("/search") fun search(@RequestParam id: Int?, @RequestParam profession: String?, @RequestParam ownername: String?): ResponseEntity> { - val result = searchPort.searchCards(id, profession, ownername) + val result = cardPort.searchCards(id, profession, ownername) return if (result != null) { ResponseEntity(result, HttpStatus.OK) } else @@ -21,7 +22,7 @@ class SearchEndpoint { @GetMapping("/{user}/cards") fun getUserCards(@PathVariable user: String?): ResponseEntity> { - val result = searchPort.searchOwnerCards(ownerName = user) + val result = cardPort.searchOwnerCards(ownerName = user) return if (result != null) { ResponseEntity(result, HttpStatus.OK) } else diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt index c7e0ea8..ea74e13 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt @@ -6,11 +6,12 @@ import hello.hello.adapters.persistence.database.entities.CardTable import hello.hello.adapters.persistence.database.entities.toCard import hello.hello.adapters.persistence.database.entities.toCardEntity import hello.hello.domain.models.Card +import hello.hello.domain.ports.CardPort import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction -class CardAdapter { +class CardAdapter: CardPort() { private fun searchById(id: Int): List = CardEntity.find { (CardTable.id eq id) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } private fun searchByProfession(profession: String): List = @@ -20,7 +21,7 @@ class CardAdapter { private fun findByOwner(owner: EntityID): List = CardEntity.find { CardTable.owner eq owner }.toList().map { it.toCard() } - fun searchCards(id: Int?, profession: String?, ownerName: String?): List? = + override fun searchCards(id: Int?, profession: String?, ownerName: String?): List? = transaction { when { id != null -> searchById(id) @@ -30,13 +31,13 @@ class CardAdapter { } } - fun searchOwnerCards(ownerName: String?): List? = + override fun searchOwnerCards(ownerName: String?): List? = transaction { ownerName?.let { findByName(ownerName)?.let { findByOwner(it.id) } } } - fun findById(id: Int): Card? = + override fun findById(id: Int): Card? = transaction { CardEntity.findById(id)?.toCard() } - fun createNewCard(userName: String, mode: String, category: String?): Card? = + override fun createNewCard(userName: String, mode: String, category: String?): Card? = transaction { val owner = findByName(userName) ?: return@transaction null CardEntity.new { @@ -46,7 +47,7 @@ class CardAdapter { }.toCard() } - fun updateCard(id: Int, mode: String?, category: String?): Card? = + override fun updateCard(id: Int, mode: String?, category: String?): Card? = transaction { val cardEntity = CardEntity.findById(id) ?: return@transaction null mode?.let { cardEntity.mode = it } @@ -54,14 +55,14 @@ class CardAdapter { cardEntity.toCard() } - fun setPath(card: Card, path: String): Card = + override fun setPath(card: Card, path: String): Card = transaction { val cardEntity = card.toCardEntity() cardEntity.path = path cardEntity.toCard() } - fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? = + override fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? = transaction { val cardEntity = CardEntity.findById(id) ?: return@transaction null mode?.let { cardEntity.mode = it } diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt index e06581d..f4ff878 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt @@ -6,13 +6,14 @@ import hello.hello.adapters.persistence.database.entities.toToken import hello.hello.adapters.persistence.database.entities.toUserEntity import hello.hello.domain.models.Token import hello.hello.domain.models.User +import hello.hello.domain.ports.TokenPort import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.sql.transactions.transaction import java.time.Instant import java.util.* -class TokenAdapter { - fun createNewToken(user: User): Token = +class TokenAdapter: TokenPort() { + override fun createNewToken(user: User): Token = transaction { TokenEntity.new { this.token = EntityID(UUID.randomUUID().toString(), TokenTable) diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt index 17d422b..8f59484 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt @@ -4,17 +4,18 @@ import hello.hello.adapters.persistence.database.entities.UserEntity import hello.hello.adapters.persistence.database.entities.UserTable import hello.hello.adapters.persistence.database.entities.toUser import hello.hello.domain.models.User +import hello.hello.domain.ports.UserPort import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction -class UserAdapter { - fun checkIfUserExists(username: String): Boolean = +class UserAdapter: UserPort() { + override fun checkIfUserExists(username: String): Boolean = transaction { findByName(username) != null } - fun checkLogin(username: String, password: String): User? = + override fun checkLogin(username: String, password: String): User? = transaction { UserEntity.find { (UserTable.name eq username) and (UserTable.password eq password) }.firstOrNull()?.toUser() } - fun createNewUser(argName: String, argPassword: String): User = + override fun createNewUser(argName: String, argPassword: String): User = transaction { UserEntity.new { name = argName diff --git a/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt new file mode 100644 index 0000000..abd74ba --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt @@ -0,0 +1,19 @@ +package hello.hello.domain.ports + +import hello.hello.domain.models.Card + +abstract class CardPort { + abstract fun searchCards(id: Int?, profession: String?, ownerName: String?): List? + + abstract fun searchOwnerCards(ownerName: String?): List? + + abstract fun findById(id: Int): Card? + + abstract fun createNewCard(userName: String, mode: String, category: String?): Card? + + abstract fun updateCard(id: Int, mode: String?, category: String?): Card? + + abstract fun setPath(card: Card, path: String): Card + + abstract fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt new file mode 100644 index 0000000..8f60cda --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt @@ -0,0 +1,8 @@ +package hello.hello.domain.ports + +import hello.hello.domain.models.Token +import hello.hello.domain.models.User + +abstract class TokenPort { + abstract fun createNewToken(user: User): Token +} \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt new file mode 100644 index 0000000..a1ff1ac --- /dev/null +++ b/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt @@ -0,0 +1,11 @@ +package hello.hello.domain.ports + +import hello.hello.domain.models.User + +abstract class UserPort { + abstract fun checkIfUserExists(username: String): Boolean + + abstract fun checkLogin(username: String, password: String): User? + + abstract fun createNewUser(argName: String, argPassword: String): User +} \ No newline at end of file diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index b632f1ba718f2cf73b7ebfd305945b7cac03fffd..46809a9a407e6f5906780dd4d6e8215dab1eaac1 100644 GIT binary patch delta 37 qcmZo@U}|V!njj^_wU&W_fdhzHftZbff&1u09U~^LwHp%_)B^yG2naI( delta 37 qcmZo@U}|V!njj^_d7OcPfdhzHftZbffou0f9U~^r;~Nte)B^yItO!~F From 29a8432813ecc0ae7523050c77ae2481630dbdf8 Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Fri, 4 Feb 2022 09:48:52 +0100 Subject: [PATCH 04/10] unified CardSet methods and updated CardPort --- .../hello/hello/adapters/api/CardEndpoint.kt | 75 ++++-------------- .../hello/adapters/api/SearchEndpoint.kt | 4 +- .../database/adapters/CardAdapter.kt | 64 +++++++-------- .../hello/hello/domain/ports/CardPort.kt | 14 ++-- server/src/main/resources/test.db | Bin 32768 -> 32768 bytes .../test/kotlin/hello/hello/TestUtilities.kt | 15 +--- .../hello/hello/api/CardEndpointTests.kt | 15 +--- .../hello/hello/api/SearchEndpointTests.kt | 4 +- 8 files changed, 60 insertions(+), 131 deletions(-) diff --git a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt index 5ee150d..2e56729 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt @@ -9,8 +9,7 @@ import hello.hello.adapters.persistence.cloudStorage.PhotosStorage import hello.hello.adapters.persistence.database.adapters.CardAdapter import hello.hello.domain.ports.CardPort -data class CardRequest(val id: Int, val mode: String?, val category: String?) -data class CardData(val id: Int, val company: String?, val name: String?, val phone: String?, val email: String?, val category: String?, val mode: String?) +data class SetCardRequest(val id: Int, val company: String?, val name: String?, val phone: String?, val email: String?, val category: String?, val mode: String?) @RestController @RequestMapping("/card") @@ -18,29 +17,20 @@ class CardEndpoint(val photosStorage: PhotosStorage) { val cardPort: CardPort = CardAdapter() @PostMapping - fun addCard(@RequestParam image: MultipartFile, @RequestParam ownerName: String): ResponseEntity { - val card = cardPort.createNewCard(ownerName, "PRIVATE", null) + fun putCard(@RequestParam image: MultipartFile, @RequestParam ownerName: String): ResponseEntity { + val card = cardPort.create(ownerName, "PRIVATE", null) return if (card != null) { photosStorage.writeImage("cards/${card.id}.jpg", image.bytes) - cardPort.setPath(card, "cards/${card.id}.jpg") + cardPort.updatePath(card, "cards/${card.id}.jpg") ResponseEntity(HttpStatus.CREATED) } else { ResponseEntity(HttpStatus.NOT_FOUND) } } - @PostMapping("/set") - fun setCard(@RequestBody request: CardRequest): ResponseEntity { - return if (cardPort.updateCard(request.id, request.mode, request.category) != null) { - ResponseEntity(HttpStatus.OK) - } else { - ResponseEntity(HttpStatus.NOT_FOUND) - } - } - @GetMapping("/image", produces = [MediaType.IMAGE_JPEG_VALUE]) fun getImage(@RequestParam id: Int): ResponseEntity { - val result = cardPort.findById(id) + val result = cardPort.read(id) return if (result?.path != null) { val image = photosStorage.readImage(result.path!!) return if (image != null) { @@ -53,52 +43,17 @@ class CardEndpoint(val photosStorage: PhotosStorage) { } } + // TODO: change URI to /set @PostMapping("/changedata", consumes = ["application/json"]) - fun editCard(@RequestBody request: CardData): ResponseEntity { - var company: String? - var name: String? - var phone: String? - var email: String? - var category: String? - var mode: String? - - if (request.company ==""){ - company = null - } - else{ - company = request.company - } - if (request.name ==""){ - name = null - } - else{ - name = request.name - } - if (request.phone ==""){ - phone = null - } - else{ - phone = request.phone - } - if (request.email ==""){ - email = null - } - else{ - email = request.email - } - if (request.category ==""){ - category = null - } - else{ - category = request.category - } - if (request.mode ==""){ - mode = null - } - else{ - mode = request.mode - } - return if (cardPort.updateData(request.id, company, name, phone, email, category, mode) != null) { + fun setCard(@RequestBody request: SetCardRequest): ResponseEntity { + val company: String? = request.company?.ifBlank { null } + val name: String? = request.name?.ifBlank { null } + val phone: String? = request.phone?.ifBlank { null } + val email: String? = request.email?.ifBlank { null } + val category: String? = request.category?.ifBlank { null } + val mode: String? = request.mode?.ifBlank { null } + + return if (cardPort.update(request.id, company, name, phone, email, category, mode) != null) { ResponseEntity(HttpStatus.OK) } else { ResponseEntity(HttpStatus.NOT_FOUND) diff --git a/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt index 36ff483..4bb5a78 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/SearchEndpoint.kt @@ -13,7 +13,7 @@ class SearchEndpoint { @GetMapping("/search") fun search(@RequestParam id: Int?, @RequestParam profession: String?, @RequestParam ownername: String?): ResponseEntity> { - val result = cardPort.searchCards(id, profession, ownername) + val result = cardPort.search(id, profession, ownername) return if (result != null) { ResponseEntity(result, HttpStatus.OK) } else @@ -22,7 +22,7 @@ class SearchEndpoint { @GetMapping("/{user}/cards") fun getUserCards(@PathVariable user: String?): ResponseEntity> { - val result = cardPort.searchOwnerCards(ownerName = user) + val result = cardPort.read(ownerName = user) return if (result != null) { ResponseEntity(result, HttpStatus.OK) } else diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt index ea74e13..b03efc0 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/CardAdapter.kt @@ -12,32 +12,20 @@ import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction class CardAdapter: CardPort() { - private fun searchById(id: Int): List = - CardEntity.find { (CardTable.id eq id) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } - private fun searchByProfession(profession: String): List = - CardEntity.find { (CardTable.category eq profession) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } - private fun searchByOwnerName(owner: EntityID): List = - CardEntity.find { (CardTable.owner eq owner) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } - private fun findByOwner(owner: EntityID): List = - CardEntity.find { CardTable.owner eq owner }.toList().map { it.toCard() } - override fun searchCards(id: Int?, profession: String?, ownerName: String?): List? = - transaction { - when { - id != null -> searchById(id) - profession != null -> searchByProfession(profession) - ownerName != null -> findByName(ownerName)?.let { searchByOwnerName(it.id) } ?: emptyList() - else -> null - } - } + private fun search(cardId: Int): List = + CardEntity.find { (CardTable.id eq cardId) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } + + private fun search(profession: String): List = + CardEntity.find { (CardTable.category eq profession) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } - override fun searchOwnerCards(ownerName: String?): List? = - transaction { ownerName?.let { findByName(ownerName)?.let { findByOwner(it.id) } } } + private fun search(ownerId: EntityID): List = + CardEntity.find { (CardTable.owner eq ownerId) and (CardTable.mode eq "PUBLIC") }.toList().map { it.toCard() } - override fun findById(id: Int): Card? = - transaction { CardEntity.findById(id)?.toCard() } + private fun find(ownerId: EntityID): List = + CardEntity.find { CardTable.owner eq ownerId }.toList().map { it.toCard() } - override fun createNewCard(userName: String, mode: String, category: String?): Card? = + override fun create(userName: String, mode: String, category: String?): Card? = transaction { val owner = findByName(userName) ?: return@transaction null CardEntity.new { @@ -47,22 +35,23 @@ class CardAdapter: CardPort() { }.toCard() } - override fun updateCard(id: Int, mode: String?, category: String?): Card? = - transaction { - val cardEntity = CardEntity.findById(id) ?: return@transaction null - mode?.let { cardEntity.mode = it } - category?.let { cardEntity.category = it } - cardEntity.toCard() - } + override fun read(cardId: Int): Card? = + transaction { CardEntity.findById(cardId)?.toCard() } - override fun setPath(card: Card, path: String): Card = + override fun read(ownerName: String?): List? = + transaction { ownerName?.let { findByName(ownerName)?.let { find(it.id) } } } + + override fun search(id: Int?, profession: String?, ownerName: String?): List? = transaction { - val cardEntity = card.toCardEntity() - cardEntity.path = path - cardEntity.toCard() + when { + id != null -> search(id) + profession != null -> search(profession) + ownerName != null -> findByName(ownerName)?.let { search(it.id) } ?: emptyList() + else -> null + } } - override fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? = + override fun update(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? = transaction { val cardEntity = CardEntity.findById(id) ?: return@transaction null mode?.let { cardEntity.mode = it } @@ -73,4 +62,11 @@ class CardAdapter: CardPort() { category?.let { cardEntity.category = it } cardEntity.toCard() } + + override fun updatePath(card: Card, path: String): Card = + transaction { + val cardEntity = card.toCardEntity() + cardEntity.path = path + cardEntity.toCard() + } } \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt index abd74ba..07b9f5c 100644 --- a/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt +++ b/server/src/main/kotlin/hello/hello/domain/ports/CardPort.kt @@ -3,17 +3,15 @@ package hello.hello.domain.ports import hello.hello.domain.models.Card abstract class CardPort { - abstract fun searchCards(id: Int?, profession: String?, ownerName: String?): List? + abstract fun create(userName: String, mode: String, category: String?): Card? - abstract fun searchOwnerCards(ownerName: String?): List? + abstract fun read(cardId: Int): Card? - abstract fun findById(id: Int): Card? + abstract fun read(ownerName: String?): List? - abstract fun createNewCard(userName: String, mode: String, category: String?): Card? + abstract fun search(id: Int?, profession: String?, ownerName: String?): List? - abstract fun updateCard(id: Int, mode: String?, category: String?): Card? + abstract fun update(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? - abstract fun setPath(card: Card, path: String): Card - - abstract fun updateData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): Card? + abstract fun updatePath(card: Card, path: String): Card } \ No newline at end of file diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index 46809a9a407e6f5906780dd4d6e8215dab1eaac1..d978e75591157622278ff0e2b8d0e4b89d5bbc30 100644 GIT binary patch delta 51 zcmZo@U}|V!njj^_eTRX8fdhzHftZbff!A=Nju8|0os9`A^_jo%zu7D(@R)z|dwW3# E04GBYrT_o{ delta 51 zcmZo@U}|V!njj^_wU&W_fdhzHftZbff&1u09U~^LwHp&w>NCILf3sOo;4%N^_x6Gg E04cu>&Hw-a diff --git a/server/src/test/kotlin/hello/hello/TestUtilities.kt b/server/src/test/kotlin/hello/hello/TestUtilities.kt index b0c4fc9..f93dfad 100644 --- a/server/src/test/kotlin/hello/hello/TestUtilities.kt +++ b/server/src/test/kotlin/hello/hello/TestUtilities.kt @@ -31,10 +31,7 @@ open class TestUtilities { fun incorrectAuthRequestData(): String = """{ "name": "test_user", "password": "no, this is not a hash" }""" - fun correctSetRequestData(id: Int, mode: String?, category: String?): String = - """{ "id": $id, "mode": "$mode", "category": "$category" }""" - - fun correctEditRequestData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): String = + fun correctSetRequestData(id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?): String = """{ "id": $id, "company": "$company", "name": "$name", "phone": "$phone", "email": "$email", "category": "$category", "mode": "$mode"}""" @@ -56,16 +53,10 @@ open class TestUtilities { .param("ownerName", correctUserName())) } - fun setCard(mockMvc: MockMvc, id: Int, mode: String?, category: String?) { - mockMvc.perform(MockMvcRequestBuilders.post("/card/set") - .header("Content-Type", "application/json") - .content(correctSetRequestData(id, mode, category))) - } - - fun editCard(mockMvc: MockMvc, id: Int, company: String?, name: String?, phone: String?, email: String?, category: String?, mode: String?) { + fun setCard(mockMvc: MockMvc, id: Int, company: String? = null, name: String? = null, phone: String? = null, email: String? = null, category: String? = null, mode: String? = null) { mockMvc.perform(MockMvcRequestBuilders.post("/card/changedata") .header("Content-Type", "application/json") - .content(correctEditRequestData(id, company, name, phone, email, category, mode))) + .content(correctSetRequestData(id, company, name, phone, email, category, mode))) } @Autowired diff --git a/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt b/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt index 004454e..8ad864c 100644 --- a/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt +++ b/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt @@ -26,9 +26,9 @@ class CardEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { createUser(mockMvc) createCard(mockMvc) mockMvc - .perform(MockMvcRequestBuilders.post("/card/set") + .perform(MockMvcRequestBuilders.post("/card/changedata") .header("Content-Type", "application/json") - .content(correctSetRequestData(1, null, null))) + .content(correctSetRequestData(1, "company", "name", null, null, null, null))) .andExpect(MockMvcResultMatchers.status().isOk) } @@ -50,15 +50,4 @@ class CardEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { .param("id", "1")) .andExpect(MockMvcResultMatchers.status().isOk) } - - @Test - fun shouldEditCard() { - createUser(mockMvc) - createCard(mockMvc) - mockMvc - .perform(MockMvcRequestBuilders.post("/card/changedata") - .header("Content-Type", "application/json") - .content(correctEditRequestData(1, "company", "name",null ,null, null, null))) - .andExpect(MockMvcResultMatchers.status().isOk) - } } \ No newline at end of file diff --git a/server/src/test/kotlin/hello/hello/api/SearchEndpointTests.kt b/server/src/test/kotlin/hello/hello/api/SearchEndpointTests.kt index 3717b7e..32f2acd 100644 --- a/server/src/test/kotlin/hello/hello/api/SearchEndpointTests.kt +++ b/server/src/test/kotlin/hello/hello/api/SearchEndpointTests.kt @@ -16,7 +16,7 @@ class SearchEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { fun shouldSearchCardsByParam(paramName: String, paramValue: String) { createUser(mockMvc) createCard(mockMvc) - setCard(mockMvc, 1, "PUBLIC", "lawyer") + setCard(mockMvc, 1, mode = "PUBLIC", category = "lawyer") mockMvc .perform(MockMvcRequestBuilders.get("/search") .param(paramName, paramValue)) @@ -28,7 +28,7 @@ class SearchEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { fun shouldReturnUserCards() { createUser(mockMvc) createCard(mockMvc) - setCard(mockMvc, 1, "PUBLIC", "lawyer") + setCard(mockMvc, 1, mode = "PUBLIC", category = "lawyer") mockMvc .perform(MockMvcRequestBuilders.get("/test_user/cards")) .andExpect(MockMvcResultMatchers.status().isOk) From 404922a0c1c5aa8a54a49a4a3ccbcadb70b47a41 Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Fri, 4 Feb 2022 09:56:51 +0100 Subject: [PATCH 05/10] updated UserPort and TokenPort --- .../hello/hello/adapters/api/AuthEndpoint.kt | 10 +++++----- .../database/adapters/TokenAdapter.kt | 2 +- .../database/adapters/UserAdapter.kt | 10 +++++----- .../hello/hello/domain/ports/TokenPort.kt | 2 +- .../hello/hello/domain/ports/UserPort.kt | 6 +++--- server/src/main/resources/test.db | Bin 32768 -> 32768 bytes 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt index afe64bf..abaf0cb 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/AuthEndpoint.kt @@ -27,7 +27,7 @@ class AuthEndpoint { @PostMapping("/register", consumes = ["application/json"]) fun register(@RequestBody request: LoginRequest): ResponseEntity { return if (!userPort.checkIfUserExists(request.name)) { - userPort.createNewUser(request.name, request.password) + userPort.create(request.name, request.password) ResponseEntity(HttpStatus.CREATED) } else ResponseEntity(HttpStatus.CONFLICT) @@ -37,7 +37,7 @@ class AuthEndpoint { fun login(@RequestBody request: LoginRequest): ResponseEntity { val user = userPort.checkLogin(request.name, request.password) return if (user != null) { - val token = tokenPort.createNewToken(user) + val token = tokenPort.create(user) ResponseEntity(token, HttpStatus.OK) } else ResponseEntity(HttpStatus.FORBIDDEN) @@ -46,12 +46,12 @@ class AuthEndpoint { @PostMapping("/loginWithGoogle", consumes = ["application/json"]) fun google(@RequestBody request: LoginRequest): ResponseEntity { return if (!userPort.checkIfUserExists(request.name)) { - val user = userPort.createNewUser(request.name, request.password) - ResponseEntity(tokenPort.createNewToken(user), HttpStatus.OK) + val user = userPort.create(request.name, request.password) + ResponseEntity(tokenPort.create(user), HttpStatus.OK) } else { val user = userPort.checkLogin(request.name, request.password) if (user != null) { - ResponseEntity(tokenPort.createNewToken(user), HttpStatus.OK) + ResponseEntity(tokenPort.create(user), HttpStatus.OK) } else ResponseEntity(HttpStatus.FORBIDDEN) } diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt index f4ff878..ba47692 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/TokenAdapter.kt @@ -13,7 +13,7 @@ import java.time.Instant import java.util.* class TokenAdapter: TokenPort() { - override fun createNewToken(user: User): Token = + override fun create(user: User): Token = transaction { TokenEntity.new { this.token = EntityID(UUID.randomUUID().toString(), TokenTable) diff --git a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt index 8f59484..94269a0 100644 --- a/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt +++ b/server/src/main/kotlin/hello/hello/adapters/persistence/database/adapters/UserAdapter.kt @@ -9,13 +9,13 @@ import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction class UserAdapter: UserPort() { - override fun checkIfUserExists(username: String): Boolean = - transaction { findByName(username) != null } + override fun checkIfUserExists(name: String): Boolean = + transaction { findByName(name) != null } - override fun checkLogin(username: String, password: String): User? = - transaction { UserEntity.find { (UserTable.name eq username) and (UserTable.password eq password) }.firstOrNull()?.toUser() } + override fun checkLogin(name: String, password: String): User? = + transaction { UserEntity.find { (UserTable.name eq name) and (UserTable.password eq password) }.firstOrNull()?.toUser() } - override fun createNewUser(argName: String, argPassword: String): User = + override fun create(argName: String, argPassword: String): User = transaction { UserEntity.new { name = argName diff --git a/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt index 8f60cda..25685d3 100644 --- a/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt +++ b/server/src/main/kotlin/hello/hello/domain/ports/TokenPort.kt @@ -4,5 +4,5 @@ import hello.hello.domain.models.Token import hello.hello.domain.models.User abstract class TokenPort { - abstract fun createNewToken(user: User): Token + abstract fun create(user: User): Token } \ No newline at end of file diff --git a/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt b/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt index a1ff1ac..27dfcb4 100644 --- a/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt +++ b/server/src/main/kotlin/hello/hello/domain/ports/UserPort.kt @@ -3,9 +3,9 @@ package hello.hello.domain.ports import hello.hello.domain.models.User abstract class UserPort { - abstract fun checkIfUserExists(username: String): Boolean + abstract fun create(argName: String, argPassword: String): User - abstract fun checkLogin(username: String, password: String): User? + abstract fun checkIfUserExists(name: String): Boolean - abstract fun createNewUser(argName: String, argPassword: String): User + abstract fun checkLogin(name: String, password: String): User? } \ No newline at end of file diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index d978e75591157622278ff0e2b8d0e4b89d5bbc30..2a2cac1039014b9908970e54ae28b91488c0774e 100644 GIT binary patch delta 51 zcmZo@U}|V!njj^_ Date: Fri, 4 Feb 2022 10:09:54 +0100 Subject: [PATCH 06/10] added two more tests --- server/src/main/resources/test.db | Bin 32768 -> 32768 bytes .../hello/hello/api/CardEndpointTests.kt | 27 +++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index 2a2cac1039014b9908970e54ae28b91488c0774e..8dd82f9f996d83ef8c98c7dae1011af521de5fdc 100644 GIT binary patch delta 37 pcmZo@U}|V!njj^_E6%{czyZXpK+ML#z_)s$ju8{D_{M|<^#FOa2KE2| delta 37 pcmZo@U}|V!njj^_ Date: Fri, 4 Feb 2022 10:14:27 +0100 Subject: [PATCH 07/10] updated links --- README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4489c3..9e27864 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,5 @@ # Hello -Business card holder app - -Timeline: -17.11 - 1 stage -13.12 - 2 stage -03.01 - 3 stage -24.01 - 4 stage +Application for holding and sharing business cards ### Server @@ -110,7 +104,8 @@ npm start ``` After that, you can run the app on an android/iOS device emulator or directly on your mobile device using Expo Go app. -Links: +Useful links: * [Jira Board](https://hello-pis.atlassian.net/jira/software/projects/HPIS/boards/1) -* [CI documentation](https://circleci.com/docs/2.0/configuration-reference) -* [Documentation](https://www.overleaf.com/read/gyhnrhzrhfxw) +* [CI documentation](https://docs.github.com/en/actions) +* [ORM documentation](https://github.com/JetBrains/Exposed/wiki) +* [Project documentation](https://www.overleaf.com/read/gyhnrhzrhfxw) From 8eb7e29e83c589a6ee56b0039fa9895fed23974b Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Fri, 4 Feb 2022 12:55:37 +0100 Subject: [PATCH 08/10] changed changedata to set, removed warnings from frontend --- frontend/App.js | 15 ++------------- frontend/actions/auth.js | 18 +++++++++--------- frontend/actions/businessCards.js | 6 ++---- frontend/actions/edit.js | 8 ++++---- frontend/actions/search.js | 8 ++++---- frontend/components/LoadingScreenModal.js | 4 ---- frontend/screens/CameraScreen.js | 1 - frontend/screens/EditCardScreen.js | 18 +++++++----------- frontend/screens/GalleryScreen.js | 3 +-- frontend/screens/HomeScreen.js | 4 ++-- frontend/screens/MyBusinessCardsScreen.js | 2 +- frontend/screens/SearchBusinessCardsScreen.js | 6 ++---- frontend/screens/login/RegisterScreen.js | 5 ++--- frontend/screens/login/SignInScreen.js | 4 +--- .../hello/hello/adapters/api/CardEndpoint.kt | 3 +-- server/src/main/resources/test.db | Bin 32768 -> 32768 bytes .../test/kotlin/hello/hello/TestUtilities.kt | 4 ++-- .../hello/hello/api/CardEndpointTests.kt | 4 ++-- 18 files changed, 42 insertions(+), 71 deletions(-) diff --git a/frontend/App.js b/frontend/App.js index ecd3cc2..4152790 100644 --- a/frontend/App.js +++ b/frontend/App.js @@ -2,12 +2,9 @@ import React, { useState, useEffect } from 'react'; import { createStore, combineReducers, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import * as Font from 'expo-font'; -import AppLoading from 'expo-app-loading'; import ReduxThunk from 'redux-thunk'; - -import { StyleSheet, SafeAreaView, View } from 'react-native'; +import { View } from 'react-native'; import AppNavigation from './navigation/AppNavigation'; - import authReducer from './reducers/auth'; import searchReducer from './reducers/search'; import businessCardsReducer from './reducers/businessCards'; @@ -50,7 +47,7 @@ export default function App() { if (!fontLoaded) { return ( - + ); } @@ -77,11 +74,3 @@ export default function App() { // ) // } } - -const styles = StyleSheet.create({ - root: { - flex: 1, - backgroundColor: '#F9FBFC' - } -}); - diff --git a/frontend/actions/auth.js b/frontend/actions/auth.js index f4a2421..af56e76 100644 --- a/frontend/actions/auth.js +++ b/frontend/actions/auth.js @@ -54,11 +54,11 @@ export const signIn = (login, password) => { console.log(`response status: ${response.status}`); let token = null; - if(response.status == 200) { + if(response.status === 200) { const respData = await response.json(); token = respData.token; console.log(`Received token: ${token}`); - } else if (response.status == 403) { + } else if (response.status === 403) { console.log(`Request rejected. Wrong credentials.`); } else { console.log(`Request rejected for unknown reason.`); @@ -120,11 +120,11 @@ export const logInWithGoogle = googleToken => { console.log(`response status: ${second_response.status}`); let token = null; - if(first_response.status == 200) { + if(first_response.status === 200) { const respData = await second_response.json(); token = respData.token; console.log(`Received token: ${token}`); - } else if (first_response.status == 403) { + } else if (first_response.status === 403) { console.log(`Request rejected. Wrong credentials.`); } else { console.log(`Request rejected for unknown reason.`); @@ -138,7 +138,7 @@ export const register = (login, password, passwordRepeat) => { return async dispatch => { console.log('registering...'); - if (password != passwordRepeat) { + if (password !== passwordRepeat) { console.log('Passwords are not the same. Please try again.'); return dispatch({ type: REGISTER, outcome: null }); } @@ -172,10 +172,10 @@ export const register = (login, password, passwordRepeat) => { } console.log(`response status: ${response.status}`); - if(response.status == 201) { + if(response.status === 201) { console.log(`Registration successful!`); dispatch({ type: REGISTER, outcome: true }); - } else if (response.status == 409) { + } else if (response.status === 409) { console.log(`Request rejected. Wrong credentials. Try changing your login.`); dispatch({ type: REGISTER, outcome: false }); } else { @@ -192,10 +192,10 @@ export const checkLogin = (login) => { `http://${serverAddress.address}:8080/check?name=${login}` ); console.log(`response status: ${response.status}`); - if(response.status == 200) { + if(response.status === 200) { console.log(`Login available`); dispatch({ type: CHECK_LOGIN, outcome: true }); - } else if (response.status == 409) { + } else if (response.status === 409) { console.log(`User with this name already exists.`); dispatch({ type: CHECK_LOGIN, outcome: false }); } else { diff --git a/frontend/actions/businessCards.js b/frontend/actions/businessCards.js index 542b054..8e66bb8 100644 --- a/frontend/actions/businessCards.js +++ b/frontend/actions/businessCards.js @@ -1,6 +1,4 @@ -import { SHA256 } from 'crypto-js'; - -import serverAddress from '../constants/serverAddress'; +import { serverAddress } from '../constants/serverAddress'; export const ADD_CARD = 'ADD_CARD'; @@ -57,7 +55,7 @@ export const addBusinessCard = (photo, ownerName) => { console.log(`response status: ${response.status}`); - const outcome = response.status === 201 ? true : false; + const outcome = response.status === 201; dispatch({ type: ADD_CARD, outcome: outcome }); } diff --git a/frontend/actions/edit.js b/frontend/actions/edit.js index 06f37fd..e143021 100644 --- a/frontend/actions/edit.js +++ b/frontend/actions/edit.js @@ -22,7 +22,7 @@ async function fetchWithTimeout(resource, options = {}) { } }; -export const editCardData = (idU, company, name, phone, email, category, mode) => { +export const setCardData = (idU, company, name, phone, email, category, mode) => { return async dispatch => { const id = parseInt(idU); @@ -33,7 +33,7 @@ export const editCardData = (idU, company, name, phone, email, category, mode) = try { response = await fetchWithTimeout( - `http://${serverAddress.address}:8080/card/changedata`, + `http://${serverAddress.address}:8080/card/set`, { method: 'POST', headers: { @@ -60,10 +60,10 @@ export const editCardData = (idU, company, name, phone, email, category, mode) = } console.log(`Response status: ${response.status}`); - if(response.status == 200) { + if(response.status === 200) { console.log(`Update data successfully`); dispatch({ type: EDIT_DATA, outcome: true }); - } else if (response.status == 404) { + } else if (response.status === 404) { console.log(`Request rejected. Wrong credentials.`); dispatch({ type: EDIT_DATA, outcome: false }); } else { diff --git a/frontend/actions/search.js b/frontend/actions/search.js index e77bfcd..fef5053 100644 --- a/frontend/actions/search.js +++ b/frontend/actions/search.js @@ -37,9 +37,9 @@ export const getMyBusinessCards = (username) => { console.log(`response status: ${response.status}`); var respData = []; - if(response.status == 200) { + if(response.status === 200) { respData = await response.json(); - } else if (response.status == 404) { + } else if (response.status === 404) { console.log(`No business cards found.`); } else { console.log(`Request rejected for unknown reason.`); @@ -80,9 +80,9 @@ export const searchBusinessCards = ({id=null, profession=null, ownername=null}) console.log(`response status: ${response.status}`); var respData = []; - if(response.status == 200) { + if(response.status === 200) { respData = await response.json(); - } else if (response.status == 404) { + } else if (response.status === 404) { console.log(`No business cards found.`); } else { console.log(`Request rejected for unknown reason.`); diff --git a/frontend/components/LoadingScreenModal.js b/frontend/components/LoadingScreenModal.js index 61df0ed..900acff 100644 --- a/frontend/components/LoadingScreenModal.js +++ b/frontend/components/LoadingScreenModal.js @@ -14,7 +14,3 @@ export default function LoadingScreenModal({amIVisible}){ ); }; - -const styles = StyleSheet.create({ - -}) \ No newline at end of file diff --git a/frontend/screens/CameraScreen.js b/frontend/screens/CameraScreen.js index c6f59c3..7736ffd 100644 --- a/frontend/screens/CameraScreen.js +++ b/frontend/screens/CameraScreen.js @@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react'; import { View, StyleSheet, Text, Image, Alert, TouchableOpacity, Dimensions } from 'react-native'; import { Camera } from 'expo-camera'; import { AntDesign } from '@expo/vector-icons'; -import * as ScreenOrientation from 'expo-screen-orientation'; import * as businessCardsActions from '../actions/businessCards'; import LoadingScreenModal from '../components/LoadingScreenModal'; import OverscreenModal from '../components/OverscreenModal'; diff --git a/frontend/screens/EditCardScreen.js b/frontend/screens/EditCardScreen.js index 82cac72..b7a0a3a 100644 --- a/frontend/screens/EditCardScreen.js +++ b/frontend/screens/EditCardScreen.js @@ -1,14 +1,10 @@ -import React, {useDebugValue, useEffect, useState} from 'react'; -import { View, StyleSheet, Text, TextInput, Image, useWindowDimensions, ScrollView, ImageBackground, Pressable, TouchableOpacity, Button } from 'react-native'; -import GoogleSignInButton from '../components/GoogleSignInButton'; -import { CommonActions, useNavigation, useRoute} from '@react-navigation/core'; +import React, {useEffect, useState} from 'react'; +import { View, StyleSheet, Text, TextInput, Image, TouchableOpacity } from 'react-native'; import Card from '../components/Card'; import OverscreenModal from '../components/OverscreenModal'; import LoadingScreenModal from '../components/LoadingScreenModal'; -import backgroundImage from '../assets/purple-bg.jpg'; import purple from '../assets/gradient.png'; import { useDispatch, useSelector } from 'react-redux'; -import { logInAsync } from 'expo-google-app-auth'; import * as authActions from '../actions/edit'; export default function EditCardScreen({ route, navigation }) { @@ -36,7 +32,7 @@ export default function EditCardScreen({ route, navigation }) { return; if (editOutcome == null) return; - if (editOutcome == true) + if (editOutcome === true) { dispatch(authActions.editFinished()); navigation.navigate('HomeScreen'); @@ -46,10 +42,10 @@ export default function EditCardScreen({ route, navigation }) { }, [editResponse]); - const onChangeDataPressed = async () => { + const onSetDataPressed = async () => { setWaitingForResponse(true); - dispatch(authActions.editCardData(photoId, company, name, phone, email, category, mode)); + dispatch(authActions.setCardData(photoId, company, name, phone, email, category, mode)); } const onReturnPressed = () => { @@ -57,7 +53,7 @@ export default function EditCardScreen({ route, navigation }) { } function onChangeModePressed () { - if (mode == 'PRIVATE') { + if (mode === 'PRIVATE') { setMode('PUBLIC') } else{ @@ -139,7 +135,7 @@ export default function EditCardScreen({ route, navigation }) { - + Wprowadź zmiany diff --git a/frontend/screens/GalleryScreen.js b/frontend/screens/GalleryScreen.js index 1b8daf1..0ad319e 100644 --- a/frontend/screens/GalleryScreen.js +++ b/frontend/screens/GalleryScreen.js @@ -1,5 +1,5 @@ import React, {useEffect, useState} from 'react'; -import {Button, View, StyleSheet, Image, Dimensions, TouchableOpacity, Text, Alert} from 'react-native'; +import { View, StyleSheet, Image, TouchableOpacity, Alert } from 'react-native'; import { useNavigation } from '@react-navigation/core'; import { useDispatch, useSelector } from 'react-redux'; import * as ImagePicker from 'expo-image-picker'; @@ -7,7 +7,6 @@ import {AntDesign} from "@expo/vector-icons"; import LoadingScreenModal from "../components/LoadingScreenModal"; import OverscreenModal from "../components/OverscreenModal"; import * as businessCardsActions from "../actions/businessCards"; -import {Camera} from "expo-camera"; export default function GalleryScreen() { const navigation = useNavigation(); diff --git a/frontend/screens/HomeScreen.js b/frontend/screens/HomeScreen.js index 21b5042..3e55b39 100644 --- a/frontend/screens/HomeScreen.js +++ b/frontend/screens/HomeScreen.js @@ -1,8 +1,8 @@ import { StatusBar } from 'expo-status-bar'; -import React, { useState, useEffect } from 'react'; +import React from 'react'; import { StyleSheet, Text, View, ScrollView } from 'react-native'; import { useNavigation } from '@react-navigation/core'; -import { useSelector, useDispatch } from 'react-redux'; +import { useSelector } from 'react-redux'; import MenuItem from '../components/MenuItem'; export default function HomeScreen() { diff --git a/frontend/screens/MyBusinessCardsScreen.js b/frontend/screens/MyBusinessCardsScreen.js index d0e6532..a88fc80 100644 --- a/frontend/screens/MyBusinessCardsScreen.js +++ b/frontend/screens/MyBusinessCardsScreen.js @@ -23,7 +23,7 @@ const MyBusinessCardsScreen = props => { await dispatch(searchActions.getMyBusinessCards(username)); console.log(`Fetched my business cards`); setWaitingForResponse(false); - }; + } useEffect(() => { if (getMyCardsTimestamp === undefined) diff --git a/frontend/screens/SearchBusinessCardsScreen.js b/frontend/screens/SearchBusinessCardsScreen.js index 1b375dd..805671f 100644 --- a/frontend/screens/SearchBusinessCardsScreen.js +++ b/frontend/screens/SearchBusinessCardsScreen.js @@ -1,9 +1,8 @@ import React, { useEffect, useState } from 'react'; -import { View, StyleSheet, Text, Image, TouchableOpacity, ImageBackground, Dimensions, FlatList, TextInput } from 'react-native'; +import { View, StyleSheet, Text, Image, TouchableOpacity, FlatList, TextInput } from 'react-native'; import { AntDesign } from '@expo/vector-icons'; import { useNavigation } from '@react-navigation/core'; import { useSelector, useDispatch } from 'react-redux'; -// import * as ScreenOrientation from 'expo-screen-orientation'; import * as searchActions from '../actions/search'; import serverAddress from '../constants/serverAddress'; import LoadingScreenModal from '../components/LoadingScreenModal'; @@ -179,10 +178,9 @@ const styles = StyleSheet.create({ }, searchBar: { flexGrow: 1, - backgroundColor: 'magenta', + backgroundColor: 'white', borderRadius: 10, marginHorizontal: 5, - backgroundColor: 'white', elevation: 3, padding: 10, fontSize: 18, diff --git a/frontend/screens/login/RegisterScreen.js b/frontend/screens/login/RegisterScreen.js index dd43ea6..09ba355 100644 --- a/frontend/screens/login/RegisterScreen.js +++ b/frontend/screens/login/RegisterScreen.js @@ -1,9 +1,8 @@ import React, { useEffect, useState } from 'react'; -import { View, StyleSheet, Text, TextInput, ScrollView, Image, ImageBackground, TouchableOpacity, StatusBar } from 'react-native'; +import { View, StyleSheet, Text, TextInput, ScrollView, Image, TouchableOpacity, StatusBar } from 'react-native'; import { useSelector, useDispatch } from 'react-redux'; import { useNavigation } from '@react-navigation/core'; import gradient from '../../assets/purple-bg.jpg'; -import purple from '../../assets/gradient.png'; import Card from '../../components/Card'; import OverscreenModal from '../../components/OverscreenModal'; import LoadingScreenModal from '../../components/LoadingScreenModal'; @@ -27,7 +26,7 @@ export default function RegisterScreen() { setWaitingForResponse(false); if (registerResponse == null) return; - if (registerOutcome == true) + if (registerOutcome === true) setSuccessModalVisible(true); else setFailureModalVisible(true); diff --git a/frontend/screens/login/SignInScreen.js b/frontend/screens/login/SignInScreen.js index 3774df9..ac14dc2 100644 --- a/frontend/screens/login/SignInScreen.js +++ b/frontend/screens/login/SignInScreen.js @@ -1,4 +1,4 @@ -import React, {useDebugValue, useEffect, useState} from 'react'; +import React, {useEffect, useState} from 'react'; import { View, StyleSheet, Text, TextInput, Image, TouchableOpacity } from 'react-native'; import { StatusBar } from 'expo-status-bar'; import GoogleSignInButton from '../../components/GoogleSignInButton'; @@ -7,9 +7,7 @@ import Card from '../../components/Card'; import OverscreenModal from '../../components/OverscreenModal'; import LoadingScreenModal from '../../components/LoadingScreenModal'; import backgroundImage from '../../assets/purple-bg.jpg'; -import purple from '../../assets/gradient.png'; import { useDispatch, useSelector } from 'react-redux'; -import { logInAsync } from 'expo-google-app-auth'; import * as authActions from '../../actions/auth'; export default function SignInScreen() { diff --git a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt index 2e56729..3685bc3 100644 --- a/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt +++ b/server/src/main/kotlin/hello/hello/adapters/api/CardEndpoint.kt @@ -43,8 +43,7 @@ class CardEndpoint(val photosStorage: PhotosStorage) { } } - // TODO: change URI to /set - @PostMapping("/changedata", consumes = ["application/json"]) + @PostMapping("/set", consumes = ["application/json"]) fun setCard(@RequestBody request: SetCardRequest): ResponseEntity { val company: String? = request.company?.ifBlank { null } val name: String? = request.name?.ifBlank { null } diff --git a/server/src/main/resources/test.db b/server/src/main/resources/test.db index 8dd82f9f996d83ef8c98c7dae1011af521de5fdc..279580312602bcd1d9ac94d9bdd695670772317f 100644 GIT binary patch delta 35 ocmZo@U}|V!njkIsnSp_U1Bh9Hn2mvff9pgYW5&-L6Bg710E@W@p8x;= delta 35 ncmZo@U}|V!njkGG&cMLH0mQ68%*MdLw|b(EF{Aj#ga!2gaHa;_ diff --git a/server/src/test/kotlin/hello/hello/TestUtilities.kt b/server/src/test/kotlin/hello/hello/TestUtilities.kt index f93dfad..ce367db 100644 --- a/server/src/test/kotlin/hello/hello/TestUtilities.kt +++ b/server/src/test/kotlin/hello/hello/TestUtilities.kt @@ -18,7 +18,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") -open class TestUtilities { +class TestUtilities { fun correctUserName() = "test_user" @@ -54,7 +54,7 @@ open class TestUtilities { } fun setCard(mockMvc: MockMvc, id: Int, company: String? = null, name: String? = null, phone: String? = null, email: String? = null, category: String? = null, mode: String? = null) { - mockMvc.perform(MockMvcRequestBuilders.post("/card/changedata") + mockMvc.perform(MockMvcRequestBuilders.post("/card/set") .header("Content-Type", "application/json") .content(correctSetRequestData(id, company, name, phone, email, category, mode))) } diff --git a/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt b/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt index f9bce4e..e1e0078 100644 --- a/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt +++ b/server/src/test/kotlin/hello/hello/api/CardEndpointTests.kt @@ -35,7 +35,7 @@ class CardEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { createUser(mockMvc) createCard(mockMvc) mockMvc - .perform(MockMvcRequestBuilders.post("/card/changedata") + .perform(MockMvcRequestBuilders.post("/card/set") .header("Content-Type", "application/json") .content(correctSetRequestData(1, "company", "name", null, null, null, null))) .andExpect(MockMvcResultMatchers.status().isOk) @@ -45,7 +45,7 @@ class CardEndpointTests(@Autowired val mockMvc: MockMvc): TestUtilities() { fun shouldNotSetCardForNonExistingCard() { createUser(mockMvc) mockMvc - .perform(MockMvcRequestBuilders.post("/card/changedata") + .perform(MockMvcRequestBuilders.post("/card/set") .header("Content-Type", "application/json") .content(correctSetRequestData(1, "company", "name", null, null, null, null))) .andExpect(MockMvcResultMatchers.status().isNotFound) From 6aeedb4a650186bef75c824e6f002c821565a15a Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Fri, 4 Feb 2022 12:56:36 +0100 Subject: [PATCH 09/10] renamed frontend to application --- {frontend => application}/.expo-shared/assets.json | 0 {frontend => application}/.gitignore | 0 {frontend => application}/App.js | 0 {frontend => application}/actions/auth.js | 0 {frontend => application}/actions/businessCards.js | 0 {frontend => application}/actions/edit.js | 0 {frontend => application}/actions/search.js | 0 {frontend => application}/app.json | 0 {frontend => application}/assets/adaptive-icon.png | Bin {frontend => application}/assets/business-card.png | Bin {frontend => application}/assets/favicon.png | Bin .../assets/fonts/OpenSans-Bold.ttf | Bin .../assets/fonts/OpenSans-Regular.ttf | Bin .../assets/fonts/Roboto-Medium.ttf | Bin {frontend => application}/assets/fonts/roboto.zip | Bin {frontend => application}/assets/google-logo.png | Bin {frontend => application}/assets/gradient.png | Bin {frontend => application}/assets/icon.png | Bin {frontend => application}/assets/purple-bg.jpg | Bin {frontend => application}/assets/splash.png | Bin {frontend => application}/babel.config.js | 0 {frontend => application}/components/Card.js | 0 .../components/GoogleSignInButton.js | 0 .../components/LoadingScreenModal.js | 0 {frontend => application}/components/MenuItem.js | 0 .../components/OverscreenModal.js | 0 .../navigation/AppNavigation.js | 0 .../navigation/futureAppNavigator.js | 0 {frontend => application}/package.json | 0 {frontend => application}/reducers/auth.js | 0 {frontend => application}/reducers/businessCards.js | 0 {frontend => application}/reducers/edit.js | 0 {frontend => application}/reducers/search.js | 0 {frontend => application}/screens/CameraScreen.js | 0 {frontend => application}/screens/EditCardScreen.js | 0 {frontend => application}/screens/GalleryScreen.js | 0 {frontend => application}/screens/HomeScreen.js | 0 .../screens/MyBusinessCardsScreen.js | 0 .../screens/SearchBusinessCardsScreen.js | 0 .../screens/login/RegisterScreen.js | 0 .../screens/login/SignInScreen.js | 0 frontend/constants/Colors.js | 4 ---- 42 files changed, 4 deletions(-) rename {frontend => application}/.expo-shared/assets.json (100%) rename {frontend => application}/.gitignore (100%) rename {frontend => application}/App.js (100%) rename {frontend => application}/actions/auth.js (100%) rename {frontend => application}/actions/businessCards.js (100%) rename {frontend => application}/actions/edit.js (100%) rename {frontend => application}/actions/search.js (100%) rename {frontend => application}/app.json (100%) rename {frontend => application}/assets/adaptive-icon.png (100%) rename {frontend => application}/assets/business-card.png (100%) rename {frontend => application}/assets/favicon.png (100%) rename {frontend => application}/assets/fonts/OpenSans-Bold.ttf (100%) rename {frontend => application}/assets/fonts/OpenSans-Regular.ttf (100%) rename {frontend => application}/assets/fonts/Roboto-Medium.ttf (100%) rename {frontend => application}/assets/fonts/roboto.zip (100%) rename {frontend => application}/assets/google-logo.png (100%) rename {frontend => application}/assets/gradient.png (100%) rename {frontend => application}/assets/icon.png (100%) rename {frontend => application}/assets/purple-bg.jpg (100%) rename {frontend => application}/assets/splash.png (100%) rename {frontend => application}/babel.config.js (100%) rename {frontend => application}/components/Card.js (100%) rename {frontend => application}/components/GoogleSignInButton.js (100%) rename {frontend => application}/components/LoadingScreenModal.js (100%) rename {frontend => application}/components/MenuItem.js (100%) rename {frontend => application}/components/OverscreenModal.js (100%) rename {frontend => application}/navigation/AppNavigation.js (100%) rename {frontend => application}/navigation/futureAppNavigator.js (100%) rename {frontend => application}/package.json (100%) rename {frontend => application}/reducers/auth.js (100%) rename {frontend => application}/reducers/businessCards.js (100%) rename {frontend => application}/reducers/edit.js (100%) rename {frontend => application}/reducers/search.js (100%) rename {frontend => application}/screens/CameraScreen.js (100%) rename {frontend => application}/screens/EditCardScreen.js (100%) rename {frontend => application}/screens/GalleryScreen.js (100%) rename {frontend => application}/screens/HomeScreen.js (100%) rename {frontend => application}/screens/MyBusinessCardsScreen.js (100%) rename {frontend => application}/screens/SearchBusinessCardsScreen.js (100%) rename {frontend => application}/screens/login/RegisterScreen.js (100%) rename {frontend => application}/screens/login/SignInScreen.js (100%) delete mode 100644 frontend/constants/Colors.js diff --git a/frontend/.expo-shared/assets.json b/application/.expo-shared/assets.json similarity index 100% rename from frontend/.expo-shared/assets.json rename to application/.expo-shared/assets.json diff --git a/frontend/.gitignore b/application/.gitignore similarity index 100% rename from frontend/.gitignore rename to application/.gitignore diff --git a/frontend/App.js b/application/App.js similarity index 100% rename from frontend/App.js rename to application/App.js diff --git a/frontend/actions/auth.js b/application/actions/auth.js similarity index 100% rename from frontend/actions/auth.js rename to application/actions/auth.js diff --git a/frontend/actions/businessCards.js b/application/actions/businessCards.js similarity index 100% rename from frontend/actions/businessCards.js rename to application/actions/businessCards.js diff --git a/frontend/actions/edit.js b/application/actions/edit.js similarity index 100% rename from frontend/actions/edit.js rename to application/actions/edit.js diff --git a/frontend/actions/search.js b/application/actions/search.js similarity index 100% rename from frontend/actions/search.js rename to application/actions/search.js diff --git a/frontend/app.json b/application/app.json similarity index 100% rename from frontend/app.json rename to application/app.json diff --git a/frontend/assets/adaptive-icon.png b/application/assets/adaptive-icon.png similarity index 100% rename from frontend/assets/adaptive-icon.png rename to application/assets/adaptive-icon.png diff --git a/frontend/assets/business-card.png b/application/assets/business-card.png similarity index 100% rename from frontend/assets/business-card.png rename to application/assets/business-card.png diff --git a/frontend/assets/favicon.png b/application/assets/favicon.png similarity index 100% rename from frontend/assets/favicon.png rename to application/assets/favicon.png diff --git a/frontend/assets/fonts/OpenSans-Bold.ttf b/application/assets/fonts/OpenSans-Bold.ttf similarity index 100% rename from frontend/assets/fonts/OpenSans-Bold.ttf rename to application/assets/fonts/OpenSans-Bold.ttf diff --git a/frontend/assets/fonts/OpenSans-Regular.ttf b/application/assets/fonts/OpenSans-Regular.ttf similarity index 100% rename from frontend/assets/fonts/OpenSans-Regular.ttf rename to application/assets/fonts/OpenSans-Regular.ttf diff --git a/frontend/assets/fonts/Roboto-Medium.ttf b/application/assets/fonts/Roboto-Medium.ttf similarity index 100% rename from frontend/assets/fonts/Roboto-Medium.ttf rename to application/assets/fonts/Roboto-Medium.ttf diff --git a/frontend/assets/fonts/roboto.zip b/application/assets/fonts/roboto.zip similarity index 100% rename from frontend/assets/fonts/roboto.zip rename to application/assets/fonts/roboto.zip diff --git a/frontend/assets/google-logo.png b/application/assets/google-logo.png similarity index 100% rename from frontend/assets/google-logo.png rename to application/assets/google-logo.png diff --git a/frontend/assets/gradient.png b/application/assets/gradient.png similarity index 100% rename from frontend/assets/gradient.png rename to application/assets/gradient.png diff --git a/frontend/assets/icon.png b/application/assets/icon.png similarity index 100% rename from frontend/assets/icon.png rename to application/assets/icon.png diff --git a/frontend/assets/purple-bg.jpg b/application/assets/purple-bg.jpg similarity index 100% rename from frontend/assets/purple-bg.jpg rename to application/assets/purple-bg.jpg diff --git a/frontend/assets/splash.png b/application/assets/splash.png similarity index 100% rename from frontend/assets/splash.png rename to application/assets/splash.png diff --git a/frontend/babel.config.js b/application/babel.config.js similarity index 100% rename from frontend/babel.config.js rename to application/babel.config.js diff --git a/frontend/components/Card.js b/application/components/Card.js similarity index 100% rename from frontend/components/Card.js rename to application/components/Card.js diff --git a/frontend/components/GoogleSignInButton.js b/application/components/GoogleSignInButton.js similarity index 100% rename from frontend/components/GoogleSignInButton.js rename to application/components/GoogleSignInButton.js diff --git a/frontend/components/LoadingScreenModal.js b/application/components/LoadingScreenModal.js similarity index 100% rename from frontend/components/LoadingScreenModal.js rename to application/components/LoadingScreenModal.js diff --git a/frontend/components/MenuItem.js b/application/components/MenuItem.js similarity index 100% rename from frontend/components/MenuItem.js rename to application/components/MenuItem.js diff --git a/frontend/components/OverscreenModal.js b/application/components/OverscreenModal.js similarity index 100% rename from frontend/components/OverscreenModal.js rename to application/components/OverscreenModal.js diff --git a/frontend/navigation/AppNavigation.js b/application/navigation/AppNavigation.js similarity index 100% rename from frontend/navigation/AppNavigation.js rename to application/navigation/AppNavigation.js diff --git a/frontend/navigation/futureAppNavigator.js b/application/navigation/futureAppNavigator.js similarity index 100% rename from frontend/navigation/futureAppNavigator.js rename to application/navigation/futureAppNavigator.js diff --git a/frontend/package.json b/application/package.json similarity index 100% rename from frontend/package.json rename to application/package.json diff --git a/frontend/reducers/auth.js b/application/reducers/auth.js similarity index 100% rename from frontend/reducers/auth.js rename to application/reducers/auth.js diff --git a/frontend/reducers/businessCards.js b/application/reducers/businessCards.js similarity index 100% rename from frontend/reducers/businessCards.js rename to application/reducers/businessCards.js diff --git a/frontend/reducers/edit.js b/application/reducers/edit.js similarity index 100% rename from frontend/reducers/edit.js rename to application/reducers/edit.js diff --git a/frontend/reducers/search.js b/application/reducers/search.js similarity index 100% rename from frontend/reducers/search.js rename to application/reducers/search.js diff --git a/frontend/screens/CameraScreen.js b/application/screens/CameraScreen.js similarity index 100% rename from frontend/screens/CameraScreen.js rename to application/screens/CameraScreen.js diff --git a/frontend/screens/EditCardScreen.js b/application/screens/EditCardScreen.js similarity index 100% rename from frontend/screens/EditCardScreen.js rename to application/screens/EditCardScreen.js diff --git a/frontend/screens/GalleryScreen.js b/application/screens/GalleryScreen.js similarity index 100% rename from frontend/screens/GalleryScreen.js rename to application/screens/GalleryScreen.js diff --git a/frontend/screens/HomeScreen.js b/application/screens/HomeScreen.js similarity index 100% rename from frontend/screens/HomeScreen.js rename to application/screens/HomeScreen.js diff --git a/frontend/screens/MyBusinessCardsScreen.js b/application/screens/MyBusinessCardsScreen.js similarity index 100% rename from frontend/screens/MyBusinessCardsScreen.js rename to application/screens/MyBusinessCardsScreen.js diff --git a/frontend/screens/SearchBusinessCardsScreen.js b/application/screens/SearchBusinessCardsScreen.js similarity index 100% rename from frontend/screens/SearchBusinessCardsScreen.js rename to application/screens/SearchBusinessCardsScreen.js diff --git a/frontend/screens/login/RegisterScreen.js b/application/screens/login/RegisterScreen.js similarity index 100% rename from frontend/screens/login/RegisterScreen.js rename to application/screens/login/RegisterScreen.js diff --git a/frontend/screens/login/SignInScreen.js b/application/screens/login/SignInScreen.js similarity index 100% rename from frontend/screens/login/SignInScreen.js rename to application/screens/login/SignInScreen.js diff --git a/frontend/constants/Colors.js b/frontend/constants/Colors.js deleted file mode 100644 index 0624c4e..0000000 --- a/frontend/constants/Colors.js +++ /dev/null @@ -1,4 +0,0 @@ -export default { - primary: '#C2185B', - accent: '#FFC107' -}; \ No newline at end of file From 35c360e41d4d234db1cda58cd19cd9021e448460 Mon Sep 17 00:00:00 2001 From: Ksawery Chodyniecki Date: Fri, 4 Feb 2022 13:14:03 +0100 Subject: [PATCH 10/10] removed sql module --- server/src/main/sql/create.sql | 28 ---------------------------- server/src/main/sql/insert.sql | 4 ---- 2 files changed, 32 deletions(-) delete mode 100644 server/src/main/sql/create.sql delete mode 100644 server/src/main/sql/insert.sql diff --git a/server/src/main/sql/create.sql b/server/src/main/sql/create.sql deleted file mode 100644 index 6de5999..0000000 --- a/server/src/main/sql/create.sql +++ /dev/null @@ -1,28 +0,0 @@ -create table users -( - name text not null constraint users_pk primary key, - password text not null -); - -create table tokens -( - token text not null constraint token_pk primary key, - name text constraint name references users on update cascade, - creationDate timestamp not null -); - -create table cards -( - id integer not null constraint card_pk primary key autoincrement, - mode text not null, - path text, - category text, - company text, - name text, - phone text, - email text, - owner integer not null references users -); - -create unique index users_name_uindex on users (name); -create unique index token_token_uindex on tokens (token); \ No newline at end of file diff --git a/server/src/main/sql/insert.sql b/server/src/main/sql/insert.sql deleted file mode 100644 index 3ec0b4d..0000000 --- a/server/src/main/sql/insert.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO cards(mode, path) VALUES('PRIVATE', 'test/photo1'); -INSERT INTO cards(mode, path, category) VALUES('PUBLIC', 'test/photo2', 'lawyer'); -INSERT INTO cards(mode, path, category) VALUES('PUBLIC', 'test/photo3', 'lawyer'); -INSERT INTO cards(mode, path, category) VALUES('PUBLIC', 'test/photo4', 'cook');