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 6759a6e commit f7a17c3
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD

on:
push:
branches: ["feature_25/유저-정보-조회"]
branches: ["feature_27/파이어베이스-관리"]

pull_request:
branches: ["dev"]
Expand Down
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public BaseResponseDto allUser() {
@GetMapping(value = "/specific-user")
public BaseResponseDto specificUser(@RequestParam("userId") Long userId) {

// String userId = jwtTokenProvider.getUserId(request);

return userService.specificUser(userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UserFirebaseToken extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "firebase_token_id", nullable = false)
private Integer id;
private Long id;

@Size(max = 100)
@NotNull
Expand Down
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> {
}
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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public BaseResponseDto reissueToken(String refreshToken, Long userId) {

}









public void deleteValueByKey(String key) {
redisTemplate.delete(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public String resolveToken(HttpServletRequest request) {
}
}

public String getUserRole(HttpServletRequest request) {
LOGGER.info("[resolveToken] HTTP 헤더에서 Token 값 추출");
public String getFirebaseToken(HttpServletRequest request) {
LOGGER.info("[firebaseToken] HTTP 헤더에서 Token 값 추출");

String tokenRole = request.getHeader("role");
String firebaseToken = request.getHeader("FirebaseToken");

return tokenRole;
return firebaseToken;

}

Expand Down

0 comments on commit f7a17c3

Please sign in to comment.