-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ADPRO-C11/staging
Staging
- Loading branch information
Showing
10 changed files
with
188 additions
and
103 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
25 changes: 25 additions & 0 deletions
25
src/main/java/snackscription/subscriptionadmin/enums/SubscriptionStatus.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,25 @@ | ||
package snackscription.subscriptionadmin.enums; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum SubscriptionStatus { | ||
PENDING("PENDING"), | ||
REJECTED("REJECTED"), | ||
SUBSCRIBED("SUBSCRIBED"); | ||
|
||
private final String value; | ||
|
||
private SubscriptionStatus(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static boolean contains(String param) { | ||
for (SubscriptionStatus subscriptionStatus : SubscriptionStatus.values()) { | ||
if (subscriptionStatus.name().equals(param)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/snackscription/subscriptionadmin/factory/AdminRepositoryFactory.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,14 @@ | ||
package snackscription.subscriptionadmin.factory; | ||
|
||
import snackscription.subscriptionadmin.repository.AdminRepository; | ||
|
||
public class AdminRepositoryFactory implements Factory<AdminRepository> { | ||
@Override | ||
public AdminRepository create() { | ||
return new AdminRepository(); | ||
} | ||
|
||
public AdminRepository create(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/snackscription/subscriptionadmin/factory/AdminSubscriptionFactory.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,14 @@ | ||
package snackscription.subscriptionadmin.factory; | ||
|
||
import snackscription.subscriptionadmin.model.AdminSubscription; | ||
|
||
public class AdminSubscriptionFactory implements Factory<AdminSubscription> { | ||
@Override | ||
public AdminSubscription create() { | ||
return new AdminSubscription(); | ||
} | ||
|
||
public AdminSubscription create(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) { | ||
return new AdminSubscription(subscriberName, subscriberId, uniqueCode, subscriptionBoxId, subscriptionStatus); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/snackscription/subscriptionadmin/factory/Factory.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,5 @@ | ||
package snackscription.subscriptionadmin.factory; | ||
|
||
public interface Factory <F> { | ||
F create(); | ||
} |
44 changes: 39 additions & 5 deletions
44
src/main/java/snackscription/subscriptionadmin/model/AdminSubscription.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 |
---|---|---|
@@ -1,13 +1,47 @@ | ||
package snackscription.subscriptionadmin.model; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import snackscription.subscriptionadmin.enums.SubscriptionStatus; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter @Setter | ||
public class AdminSubscription { | ||
private String subscriberName; | ||
private int subscriberId; | ||
private String subscriptionUniqueCode; | ||
private String subscriptionType; | ||
private String subscribtionStatus; | ||
String subscriberName; | ||
String subscriberId; | ||
String uniqueCode; | ||
String subscriptionId; | ||
String subscriptionBoxId; | ||
String subscriptionStatus; | ||
|
||
public AdminSubscription() { | ||
this.subscriptionId = UUID.randomUUID().toString(); | ||
} | ||
|
||
public AdminSubscription(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) { | ||
this.subscriptionId = UUID.randomUUID().toString(); | ||
|
||
this.subscriberName = subscriberName; | ||
this.subscriberId = subscriberId; | ||
|
||
if (!uniqueCode.startsWith("MTH-") && !uniqueCode.startsWith("QTR-") && !uniqueCode.startsWith("SAA-")) { | ||
throw new IllegalArgumentException("Invalid unique code"); | ||
} | ||
|
||
this.uniqueCode = uniqueCode; | ||
this.subscriptionBoxId = subscriptionBoxId; | ||
this.getSubscriptionStatus(); | ||
this.setSubscriptionStatus(subscriptionStatus); | ||
} | ||
|
||
public void setSubscriptionStatus(String subscriptionStatus) { | ||
if (SubscriptionStatus.contains(subscriptionStatus)) { | ||
this.subscriptionStatus = subscriptionStatus; | ||
} else { | ||
throw new IllegalArgumentException("Invalid subscription status"); | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/test/java/snackscription/subscriptionadmin/factory/AdminRepositoryFactoryTest.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,17 @@ | ||
package snackscription.subscriptionadmin.factory; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import snackscription.subscriptionadmin.repository.AdminRepository; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class AdminRepositoryFactoryTest { | ||
@Test | ||
void testCreateAdminRepository() { | ||
AdminRepositoryFactory adminRepositoryFactory = new AdminRepositoryFactory(); | ||
AdminRepository adminRepository = adminRepositoryFactory.create(); | ||
|
||
assertNotNull(adminRepository); | ||
assertInstanceOf(AdminRepository.class, adminRepository); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/snackscription/subscriptionadmin/factory/AdminSubscriptionFactoryTest.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,37 @@ | ||
package snackscription.subscriptionadmin.factory; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import snackscription.subscriptionadmin.enums.SubscriptionStatus; | ||
import snackscription.subscriptionadmin.model.AdminSubscription; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class AdminSubscriptionFactoryTest { | ||
@Test | ||
void testCreateAdminSubscription() { | ||
AdminSubscriptionFactory adminSubscriptionFactory = new AdminSubscriptionFactory(); | ||
AdminSubscription adminSubscription = adminSubscriptionFactory.create(); | ||
|
||
assertNotNull(adminSubscription); | ||
} | ||
|
||
@Test | ||
void testCreateAdminSubscriptionComplete() { | ||
AdminSubscriptionFactory adminSubscriptionFactory = new AdminSubscriptionFactory(); | ||
|
||
AdminSubscription adminSubscription = adminSubscriptionFactory.create( | ||
"Hwang Hyunjin", | ||
"12345678910", | ||
"MTH-12345678910", | ||
"12345678910", | ||
SubscriptionStatus.PENDING.getValue() | ||
); | ||
|
||
assertNotNull(adminSubscription.getSubscriptionId()); | ||
assertEquals("Hwang Hyunjin", adminSubscription.getSubscriberName()); | ||
assertEquals("12345678910", adminSubscription.getSubscriberId()); | ||
assertEquals("MTH-12345678910", adminSubscription.getUniqueCode()); | ||
assertEquals("12345678910", adminSubscription.getSubscriptionBoxId()); | ||
assertEquals(SubscriptionStatus.PENDING.getValue(), adminSubscription.getSubscriptionStatus()); | ||
} | ||
} |
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
85 changes: 0 additions & 85 deletions
85
src/test/java/snackscription/subscriptionadmin/repository/AdminRepositoryTest.java
This file was deleted.
Oops, something went wrong.