-
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.
- Loading branch information
Showing
9 changed files
with
97 additions
and
8 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
33 changes: 33 additions & 0 deletions
33
src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.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,33 @@ | ||
package modernfarmer.server.farmususer.user.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/firebase") | ||
@RequiredArgsConstructor | ||
public class FirebaseController { | ||
|
||
private final JwtTokenProvider jwtTokenProvider; | ||
private final FirebaseService firebaseService; | ||
|
||
|
||
@PostMapping(value = "/insert-firebase-token") | ||
public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { | ||
|
||
String userId = jwtTokenProvider.getUserId(request); | ||
String fireBaseToken = jwtTokenProvider.getFirebaseToken(request); | ||
|
||
return firebaseService.insertFirebaseToken(Long.valueOf(userId),fireBaseToken); | ||
} | ||
|
||
} |
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
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
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
11 changes: 11 additions & 0 deletions
11
...main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.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,11 @@ | ||
package modernfarmer.server.farmususer.user.repository; | ||
|
||
|
||
import modernfarmer.server.farmususer.user.entity.UserFirebaseToken; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
|
||
@Repository | ||
public interface UserFirebaseTokenRepository extends JpaRepository<UserFirebaseToken, Long> { | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.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,38 @@ | ||
package modernfarmer.server.farmususer.user.service; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import modernfarmer.server.farmususer.global.config.s3.S3Uploader; | ||
import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; | ||
import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; | ||
import modernfarmer.server.farmususer.user.entity.User; | ||
import modernfarmer.server.farmususer.user.entity.UserFirebaseToken; | ||
import modernfarmer.server.farmususer.user.repository.UserFirebaseTokenRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Slf4j | ||
@Service | ||
public class FirebaseService { | ||
|
||
private final UserFirebaseTokenRepository userFirebaseTokenRepository; | ||
|
||
|
||
public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) { | ||
|
||
|
||
UserFirebaseToken userFirebaseToken = UserFirebaseToken.builder() | ||
.user(User.builder().id(userId).build()) | ||
.token(firebaseToken) | ||
.build(); | ||
|
||
|
||
userFirebaseTokenRepository.save(userFirebaseToken); | ||
|
||
return BaseResponseDto.of(SuccessMessage.SUCCESS, null); | ||
|
||
} | ||
} |
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
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