Skip to content

Commit

Permalink
refactor: AuthMember 적용 및 테스트 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Nov 21, 2023
1 parent 6a08ed0 commit 39eb57b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class CouponQueueService {
private final CouponService couponService;
private final CouponQueueRepository couponQueueRepository;

public void register(AuthMember member, String couponName) {
public void register(AuthMember authMember, String couponName) {
double registerTime = System.currentTimeMillis();

if (canRegister(couponName)) {
log.info("{} 쿠폰이 모두 발급되었습니다.", couponName);
return;
}

couponQueueRepository.addIfAbsent(couponName, member.nickname(), registerTime);
couponQueueRepository.addIfAbsent(couponName, authMember.nickname(), registerTime);
}

private boolean canRegister(String couponName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.moabam.global.auth.model.AuthorizationMember;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.error.exception.NotFoundException;
import com.moabam.global.error.model.ErrorMessage;

Expand All @@ -19,12 +19,12 @@ public class FcmService {
private final FcmRepository fcmRepository;

// TODO : 세연님 로그인 시, 해당 메서드 사용해서 해당 유저의 FCM TOKEN 저장하면 됩니다. Front와 상의 후 삭제예정
public void createToken(AuthorizationMember member, String fcmToken) {
public void createToken(AuthMember authMember, String fcmToken) {
if (fcmToken == null || fcmToken.isBlank()) {
return;
}

fcmRepository.saveToken(member.id(), fcmToken);
fcmRepository.saveToken(authMember.id(), fcmToken);
}

// TODO : 세연님 로그아웃 시, 해당 메서드 사용해서 해당 유저의 FCM TOKEN 삭제하시면 됩니다. (이 코드는 원하시면 변경하셔도 됩니다.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class CouponController {

@PostMapping("/admins/coupons")
@ResponseStatus(HttpStatus.CREATED)
public void createCoupon(@Auth AuthMember admin,
@Valid @RequestBody CreateCouponRequest request) {
public void createCoupon(@Auth AuthMember admin, @Valid @RequestBody CreateCouponRequest request) {
couponService.create(admin, request);
}

Expand All @@ -56,8 +55,7 @@ public List<CouponResponse> getAllByStatus(@Valid @RequestBody CouponStatusReque
}

@PostMapping("/coupons")
public void registerCouponQueue(@Auth AuthMember member,
@RequestParam("couponName") String couponName) {
couponQueueService.register(member, couponName);
public void registerCouponQueue(@Auth AuthMember authMember, @RequestParam("couponName") String couponName) {
couponQueueService.register(authMember, couponName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void sendKnockNotification(@Auth AuthMember member, @PathVariable("roomId

@PostMapping
@ResponseStatus(HttpStatus.OK)
public void createFcmToken(@CurrentMember AuthorizationMember member, @RequestParam("fcmToken") String fcmToken) {
fcmService.createToken(member, fcmToken);
public void createFcmToken(@Auth AuthMember authMember, @RequestParam("fcmToken") String fcmToken) {
fcmService.createToken(authMember, fcmToken);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/static/docs/coupon.html
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ <h4 id="_요청" class="discrete">요청</h4>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /admins/coupons HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 194
Content-Length: 186
Host: localhost:8080

{
Expand Down Expand Up @@ -751,7 +751,7 @@ <h3 id="_쿠폰_사용_진행_중">쿠폰 사용 (진행 중)</h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-21 15:46:20 +0900
Last updated 2023-11-20 17:19:12 +0900
</div>
</div>
</body>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/static/docs/notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ <h4 id="_응답" class="discrete">응답</h4>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Content-Length: 66
Content-Length: 64

{
"message" : "해당 유저는 접속 중이 아닙니다."
Expand Down Expand Up @@ -515,7 +515,7 @@ <h4 id="_응답_2" class="discrete">응답</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-21 16:18:31 +0900
Last updated 2023-11-21 16:49:01 +0900
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
import com.moabam.global.auth.model.AuthorizationMember;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.auth.model.AuthorizationThreadLocal;
import com.moabam.global.config.FcmConfig;
import com.moabam.support.annotation.WithMember;
Expand All @@ -33,10 +33,10 @@ class FcmServiceTest extends WithoutFilterSupporter {
@Test
void saveToken() {
// Given
AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember();
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();

// When
fcmService.createToken(member, "value1");
fcmService.createToken(authMember, "value1");

// Then
verify(fcmRepository).saveToken(any(Long.class), any(String.class));
Expand All @@ -47,10 +47,10 @@ void saveToken() {
@Test
void saveToken_Blank() {
// Given
AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember();
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();

// When
fcmService.createToken(member, "");
fcmService.createToken(authMember, "");

// Then
verify(fcmRepository, times(0)).saveToken(any(Long.class), any(String.class));
Expand All @@ -61,10 +61,10 @@ void saveToken_Blank() {
@Test
void saveToken_Null() {
// Given
AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember();
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();

// When
fcmService.createToken(member, null);
fcmService.createToken(authMember, null);

// Then
verify(fcmRepository, times(0)).saveToken(any(Long.class), any(String.class));
Expand Down

0 comments on commit 39eb57b

Please sign in to comment.