-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java][social_login-01_base] Add base structure
- Loading branch information
1 parent
94f3d6f
commit cb77b9f
Showing
26 changed files
with
206 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
..._login-01_base/src/main/java/tv/codely/app/controller/login/EmailLoginPostController.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...ogin-01_base/src/main/java/tv/codely/app/controller/login/TwitterLoginPostController.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...gin-01_base/src/main/java/tv/codely/app/controller/sign_up/EmailSignUpPostController.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...n-01_base/src/main/java/tv/codely/app/controller/sign_up/TwitterSignUpPostController.java
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
...y/ecommerce/login/EmailLoginProvider.java → ...erce/login/domain/EmailLoginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...commerce/login/FacebookLoginProvider.java → ...e/login/domain/FacebookLoginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../ecommerce/login/GitHubLoginProvider.java → ...rce/login/domain/GitHubLoginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...codely/ecommerce/login/LoginProvider.java → ...ecommerce/login/domain/LoginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ecommerce/login/TwitterLoginProvider.java → ...ce/login/domain/TwitterLoginProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
...va-social_login-01_base/src/main/java/tv/codely/ecommerce/login_attempt/LoginAttempt.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...se/src/main/java/tv/codely/ecommerce/login_attempt/application/add/LoginAttemptAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tv.codely.ecommerce.login_attempt.application.add; | ||
|
||
import tv.codely.ecommerce.login_attempt.domain.LoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.LoginAttemptRepository; | ||
|
||
public final class LoginAttemptAdder { | ||
private final LoginAttemptRepository repository; | ||
|
||
public LoginAttemptAdder(LoginAttemptRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public void add(LoginAttempt loginAttempt) throws Exception { | ||
this.repository.save(loginAttempt); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...gin-01_base/src/main/java/tv/codely/ecommerce/login_attempt/domain/EmailLoginAttempt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tv.codely.ecommerce.login_attempt.domain; | ||
|
||
public final class EmailLoginAttempt extends LoginAttempt { | ||
private final String email; | ||
|
||
public EmailLoginAttempt(String ip, String email) { | ||
super(ip); | ||
|
||
this.email = email; | ||
} | ||
|
||
public String email() { | ||
return email; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...al_login-01_base/src/main/java/tv/codely/ecommerce/login_attempt/domain/LoginAttempt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tv.codely.ecommerce.login_attempt.domain; | ||
|
||
public abstract class LoginAttempt { | ||
private final String ip; | ||
|
||
public LoginAttempt(String ip) { | ||
this.ip = ip; | ||
} | ||
|
||
public String ip() { | ||
return ip; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...1_base/src/main/java/tv/codely/ecommerce/login_attempt/domain/LoginAttemptRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tv.codely.ecommerce.login_attempt.domain; | ||
|
||
import java.util.HashMap; | ||
|
||
public interface LoginAttemptRepository { | ||
HashMap<String, String> save(LoginAttempt loginAttempt) throws Exception; | ||
} |
15 changes: 15 additions & 0 deletions
15
...n-01_base/src/main/java/tv/codely/ecommerce/login_attempt/domain/TwitterLoginAttempt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tv.codely.ecommerce.login_attempt.domain; | ||
|
||
public final class TwitterLoginAttempt extends LoginAttempt { | ||
private final String username; | ||
|
||
public TwitterLoginAttempt(String ip, String username) { | ||
super(ip); | ||
|
||
this.username = username; | ||
} | ||
|
||
public String username() { | ||
return username; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...main/java/tv/codely/ecommerce/login_attempt/domain/format/EmailLoginAttemptFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tv.codely.ecommerce.login_attempt.domain.format; | ||
|
||
import tv.codely.ecommerce.login_attempt.domain.EmailLoginAttempt; | ||
|
||
import java.util.HashMap; | ||
|
||
public final class EmailLoginAttemptFormatter extends LoginAttemptFormatter<EmailLoginAttempt> { | ||
@Override | ||
public HashMap<String, String> format(EmailLoginAttempt loginAttempt) { | ||
return new HashMap<>() {{ | ||
put("ip", loginAttempt.ip()); | ||
put("email", loginAttempt.email()); | ||
}}; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../src/main/java/tv/codely/ecommerce/login_attempt/domain/format/LoginAttemptFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tv.codely.ecommerce.login_attempt.domain.format; | ||
|
||
import tv.codely.ecommerce.login_attempt.domain.LoginAttempt; | ||
|
||
import java.util.HashMap; | ||
|
||
public abstract class LoginAttemptFormatter<T extends LoginAttempt> { | ||
public abstract HashMap<String, String> format(T loginAttempt); | ||
} |
15 changes: 15 additions & 0 deletions
15
...in/java/tv/codely/ecommerce/login_attempt/domain/format/TwitterLoginAttemptFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tv.codely.ecommerce.login_attempt.domain.format; | ||
|
||
import tv.codely.ecommerce.login_attempt.domain.TwitterLoginAttempt; | ||
|
||
import java.util.HashMap; | ||
|
||
public final class TwitterLoginAttemptFormatter extends LoginAttemptFormatter<TwitterLoginAttempt> { | ||
@Override | ||
public HashMap<String, String> format(TwitterLoginAttempt loginAttempt) { | ||
return new HashMap<>() {{ | ||
put("ip", loginAttempt.ip()); | ||
put("username", loginAttempt.username()); | ||
}}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...java/tv/codely/ecommerce/login_attempt/infrastructure/SdkAuth0LoginAttemptRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tv.codely.ecommerce.login_attempt.infrastructure; | ||
|
||
import tv.codely.ecommerce.login_attempt.domain.EmailLoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.LoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.LoginAttemptRepository; | ||
import tv.codely.ecommerce.login_attempt.domain.TwitterLoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.format.EmailLoginAttemptFormatter; | ||
import tv.codely.ecommerce.login_attempt.domain.format.LoginAttemptFormatter; | ||
import tv.codely.ecommerce.login_attempt.domain.format.TwitterLoginAttemptFormatter; | ||
|
||
import java.util.HashMap; | ||
|
||
public final class SdkAuth0LoginAttemptRepository implements LoginAttemptRepository { | ||
@Override | ||
public HashMap<String, String> save(LoginAttempt loginAttempt) throws Exception { | ||
LoginAttemptFormatter formatter; | ||
|
||
if (loginAttempt instanceof TwitterLoginAttempt) { | ||
formatter = new TwitterLoginAttemptFormatter(); | ||
} else if (loginAttempt instanceof EmailLoginAttempt) { | ||
formatter = new EmailLoginAttemptFormatter(); | ||
} else { | ||
throw new Exception("There are no formatters for that attempt"); | ||
} | ||
|
||
return formatter.format(loginAttempt); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...commerce/sign_up/EmailSignUpProvider.java → ...e/sign_up/domain/EmailSignUpProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...merce/sign_up/FacebookSignUpProvider.java → ...ign_up/domain/FacebookSignUpProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ommerce/sign_up/GitHubSignUpProvider.java → .../sign_up/domain/GitHubSignUpProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ely/ecommerce/sign_up/SignUpProvider.java → ...mmerce/sign_up/domain/SignUpProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...mmerce/sign_up/TwitterSignUpProvider.java → ...sign_up/domain/TwitterSignUpProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...v/codely/ecommerce/login_attempt/infrastructure/SdkAuth0LoginAttemptRepositoryShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package tv.codely.ecommerce.login_attempt.infrastructure; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import tv.codely.ecommerce.login_attempt.domain.EmailLoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.LoginAttempt; | ||
import tv.codely.ecommerce.login_attempt.domain.TwitterLoginAttempt; | ||
|
||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
final class SdkAuth0LoginAttemptRepositoryShould { | ||
private SdkAuth0LoginAttemptRepository repository; | ||
|
||
@BeforeEach | ||
protected void setUp() { | ||
repository = new SdkAuth0LoginAttemptRepository(); | ||
} | ||
|
||
@Test | ||
void add_an_email_login_attempt() throws Exception { | ||
EmailLoginAttempt loginAttempt = new EmailLoginAttempt("192.168.1.1", "[email protected]"); | ||
HashMap<String, String> expected = new HashMap<>() {{ | ||
put("ip", "192.168.1.1"); | ||
put("email", "[email protected]"); | ||
}}; | ||
|
||
assertEquals(expected, repository.save(loginAttempt)); | ||
} | ||
|
||
@Test | ||
void add_a_twitter_login_attempt() throws Exception { | ||
TwitterLoginAttempt loginAttempt = new TwitterLoginAttempt("192.168.1.2", "codelytv"); | ||
HashMap<String, String> expected = new HashMap<>() {{ | ||
put("ip", "192.168.1.2"); | ||
put("username", "codelytv"); | ||
}}; | ||
|
||
assertEquals(expected, repository.save(loginAttempt)); | ||
} | ||
|
||
@Test | ||
void throw_an_exception_with_an_unknown_login_attempt() { | ||
LoginAttempt loginAttempt = new LoginAttempt("192.168.1.3") { | ||
public String name() { | ||
return "unknown"; | ||
} | ||
}; | ||
|
||
assertThrows(Exception.class, () -> repository.save(loginAttempt)); | ||
} | ||
} |