Skip to content

Commit

Permalink
[feat] 파이어베이스 토큰 삭제 API 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Nov 15, 2023
1 parent f7a17c3 commit 41e5a15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto;
import modernfarmer.server.farmususer.user.service.FirebaseService;
import modernfarmer.server.farmususer.user.util.JwtTokenProvider;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -21,7 +22,7 @@ public class FirebaseController {
private final FirebaseService firebaseService;


@PostMapping(value = "/insert-firebase-token")
@PostMapping(value = "/firebase-token")
public BaseResponseDto insertFirebaseToken(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);
Expand All @@ -30,4 +31,14 @@ public BaseResponseDto insertFirebaseToken(HttpServletRequest request) {
return firebaseService.insertFirebaseToken(Long.valueOf(userId),fireBaseToken);
}


@DeleteMapping(value = "/firebase-token")
public BaseResponseDto deleteFirebaseToken(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);
String fireBaseToken = jwtTokenProvider.getFirebaseToken(request);

return firebaseService.deleteFirebaseToken(Long.valueOf(userId),fireBaseToken);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package modernfarmer.server.farmususer.user.repository;


import io.lettuce.core.dynamic.annotation.Param;
import modernfarmer.server.farmususer.user.entity.User;
import modernfarmer.server.farmususer.user.entity.UserFirebaseToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface UserFirebaseTokenRepository extends JpaRepository<UserFirebaseToken, Long> {


@Modifying
@Query("delete from UserFirebaseToken as uf where uf.user = :user and uf.token = :firebaseToken ")
void deleteFirebaseToken(@Param("user") User user, @Param("firebaseToken") String firebaseToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) {
.token(firebaseToken)
.build();


userFirebaseTokenRepository.save(userFirebaseToken);

log.info("파이어 베이스 토큰 삽입 완료");
return BaseResponseDto.of(SuccessMessage.SUCCESS, null);
}

public BaseResponseDto deleteFirebaseToken(Long userId, String firebaseToken) {


userFirebaseTokenRepository.deleteFirebaseToken(
User.builder()
.id(userId)
.build(),
firebaseToken
);

log.info("파이어 베이스 토큰 삭제 완료");

return BaseResponseDto.of(SuccessMessage.SUCCESS, null);
}
}

0 comments on commit 41e5a15

Please sign in to comment.