-
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 #83 from GDSC-MYONGJI/kimjeongho
8주차 - 김정호
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.hou27.chap08; | ||
|
||
public class LoginService { | ||
|
||
private String authKey = "some_key"; | ||
private CustomerRepository customerRepository; | ||
|
||
public LoginService(CustomerRepository customerRepository) { | ||
this.customerRepository = customerRepository; | ||
} | ||
|
||
public LoginResult login(String id, String password) { | ||
int resp = 0; | ||
boolean authorized = AuthUtil.authorize(authKey); // 정적 메서드를 사용 | ||
if (authorized) { | ||
resp = AuthUtil.authenticate(id, password); // 정적 메서드를 사용 | ||
} else { | ||
resp = -1; | ||
} | ||
|
||
if (resp == -1) { | ||
return LoginResult.badAuthKey(); | ||
} else if (resp == 1) { | ||
return LoginResult.success(); | ||
} else { | ||
return LoginResult.fail(); | ||
} | ||
} | ||
|
||
} |
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,32 @@ | ||
package com.hou27.chap08; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.stream.Collectors; | ||
|
||
public class PaySync { | ||
private PayInfoDao payInfoDao; | ||
private String filePath = "tmp/paydata/payinfo.csv"; | ||
|
||
// 생성자를 통해 의존성을 주입받는다. | ||
public PaySync(PayInfoDao payInfoDao) { | ||
this.payInfoDao = payInfoDao; | ||
} | ||
|
||
// 경로를 설정 가능하게 메서드 생성 | ||
public void setFilePath(String filePath) { | ||
this.filePath = filePath; | ||
} | ||
|
||
public void sync() throws IOException { | ||
Path path = Path.of(filePath); | ||
List<PayInfo> payInfos = Files.lines(path) | ||
.map(line -> { | ||
String[] data = line.split(","); | ||
return new PayInfo(data[0], Integer.parseInt(data[1])); | ||
}).collect(Collectors.toList()); | ||
|
||
payInfos.forEach(pi -> payInfoDao.insert(pi)); | ||
} | ||
} |
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 com.hou27.chap08; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class Times { | ||
public LocalDate today() { | ||
return LocalDate.now(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
김정호/src/test/java/com/hou27/chap08/UserPointCalculator.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,62 @@ | ||
package com.hou27.chap08; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class UserPointCalculator { | ||
|
||
private SubscriptionDao subscriptionDao; | ||
private ProductDao productDao; | ||
private Times times; | ||
|
||
public UserPointCalculator( | ||
SubscriptionDao subscriptionDao, | ||
ProductDao productDao, | ||
Times times | ||
) { | ||
this.subscriptionDao = subscriptionDao; | ||
this.productDao = productDao; | ||
this.times = times; | ||
} | ||
|
||
public int calculatePoint(User u) { | ||
Subscription s = subscriptionDao.selectByUser(u); | ||
if(s == null) { | ||
throw new NoSubscriptionException(); | ||
} | ||
|
||
Product p = productDao.selectById(s.getProductId()); | ||
// LocalDate now = LocalDate.now(); // 현재 날짜를 구한다. | ||
LocalDate now = times.today(); // 현재 날짜를 구한다. | ||
PointRule rule = new PointRule(); | ||
int point = rule.calculate(s, p, now); | ||
// int point = 0; | ||
// if(s.isFinished(now)) { // 현재 시간에 따라 결과가 달라진다. | ||
// point += p.getDefaultPoint(); | ||
// } else { | ||
// point += p.getDefaultPoint() + 10; | ||
// } | ||
// | ||
// if(s.getGrade() == GOLD) { | ||
// point += 100; | ||
// } | ||
|
||
return point; | ||
} | ||
} | ||
|
||
class PointRule { | ||
public int calculate(Subscription s, Product p, LocalDate now) { | ||
int point = 0; | ||
if(s.isFinished(now)) { | ||
point += p.getDefaultPoint(); | ||
} else { | ||
point += p.getDefaultPoint() + 10; | ||
} | ||
|
||
if(s.getGrade() == GOLD) { | ||
point += 100; | ||
} | ||
|
||
return point; | ||
} | ||
} |