Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#25 Feature/edit user group #28

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ dependencies {

implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

// Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'

}
ext {
snippetsDir = file('build/generated-snippets')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.utils.JwtService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Tag(name = "알람")
@RestController
@RequestMapping("/app/alarm")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wakeUpTogetUp.togetUp.api.alarm.model;

import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.mission.model.Mission;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
import com.wakeUpTogetUp.togetUp.api.auth.dto.response.LoginRes;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;


@Tag(name = "Auth(로그인)",description = "로그인 및 유저의 권한 인증")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/auth")
public class AuthController {
private final AuthService authService;

/**
*
*/

@ResponseBody
@PostMapping("/login")
public BaseResponse<LoginRes> join(@RequestBody SocialLoginReq loginReq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;



@Slf4j
@Component
@RequiredArgsConstructor
Expand All @@ -29,10 +31,13 @@ public boolean supportsParameter(MethodParameter parameter) {
}

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String jwt = webRequest.getHeader("Authorization");
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
if(webRequest.getHeader("Authorization")==null)
throw new BaseException(Status.UNAUTHORIZED);
String jwt = webRequest.getHeader("Authorization").replace("Bearer", "").trim();
if(jwt.isEmpty())
new BaseException(Status.UNAUTHORIZED);
throw new BaseException(Status.UNAUTHORIZED);

return jwtService.getUserId(jwt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public LoginRes socialLogin(SocialLoginReq socialLoginReq) {
SocialLoginService loginService = this.getLoginService(socialLoginReq.getLoginType());

//소셜로그인 유저 정보 가져오기
// SocialUserRes socialUserRes = loginService.getUserInfo(socialLoginReq.getOauthAccessToken());
//log.info("socialUserResponse {} ", socialUserRes.toString());
SocialUserRes socialUserRes = loginService.getUserInfo(socialLoginReq.getOauthAccessToken());
log.info("socialUserResponse {} ", socialUserRes.toString());

//저장된 유저 or 저장한유저의 id 가져오기
Integer userId= 9;//this.getSignedUserId(socialUserRes,socialLoginReq.getLoginType());
Integer userId = this.getSignedUserId(socialUserRes,socialLoginReq.getLoginType());

//accessToken 만들기
String accessToken = jwtService.generateAccessToken(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.wakeUpTogetUp.togetUp.api.fcmNotification.dto.request.PushNotificationReq;
import com.wakeUpTogetUp.togetUp.api.fcmNotification.dto.response.PushNotificationRes;
import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.api.group.GroupRepository;
import com.wakeUpTogetUp.togetUp.api.room.GroupRepository;
import com.wakeUpTogetUp.togetUp.api.users.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wakeUpTogetUp.togetUp.api.fcmNotification.entity;

import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.users.fcmToken.FcmToken;
import com.wakeUpTogetUp.togetUp.utils.TimestampFormatter;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.mappingRoomUser;

import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.group.model.RoomUser;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.RoomUser;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wakeUpTogetUp.togetUp.api.mappingRoomUser.dto.request;


import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.group.model.RoomUser;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.RoomUser;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import com.wakeUpTogetUp.togetUp.api.mission.dto.response.MissionLogRes;
import com.wakeUpTogetUp.togetUp.api.mission.dto.response.PostObjectRecognitionRes;
import com.wakeUpTogetUp.togetUp.utils.JwtService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "미션")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/mission")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.mission;

import com.wakeUpTogetUp.togetUp.api.group.GroupRepository;
import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.GroupRepository;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.mission.model.Mission;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wakeUpTogetUp.togetUp.api.mission.model;

import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import com.wakeUpTogetUp.togetUp.utils.TimestampFormatter;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.wakeUpTogetUp.togetUp.api.group;
package com.wakeUpTogetUp.togetUp.api.room;

import com.wakeUpTogetUp.togetUp.api.group.dto.request.GroupReq;
import com.wakeUpTogetUp.togetUp.api.group.dto.response.GroupRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.GroupReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.GroupRes;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import com.wakeUpTogetUp.togetUp.common.Status;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Tag(name = "그룹")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/group")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.group;
package com.wakeUpTogetUp.togetUp.api.room;


import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wakeUpTogetUp.togetUp.api.group;
package com.wakeUpTogetUp.togetUp.api.room;

import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.api.group.dto.request.GroupReq;
import com.wakeUpTogetUp.togetUp.api.group.dto.response.GroupRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.GroupReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.GroupRes;
import com.wakeUpTogetUp.togetUp.utils.mapper.GroupMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.group.dto.request;
package com.wakeUpTogetUp.togetUp.api.room.dto.request;


import com.wakeUpTogetUp.togetUp.api.group.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import lombok.*;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.api.group.dto.response;
package com.wakeUpTogetUp.togetUp.api.room.dto.response;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.api.group.model;
package com.wakeUpTogetUp.togetUp.api.room.model;


import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.group.model;
package com.wakeUpTogetUp.togetUp.api.room.model;

import com.wakeUpTogetUp.togetUp.api.users.model.User;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;
import java.sql.Timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.wakeUpTogetUp.togetUp.api.auth.AuthUser;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;


@Tag(name = "유저")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/users")
Expand All @@ -16,6 +20,19 @@ public class UserController {
private final UserRepository userRepository;


@Operation(summary = "fcmToken 업데이트")
@PatchMapping("/fcm-token")
public BaseResponse<Integer> updateFcmToken(@Parameter(hidden = true) @AuthUser Integer userId, @Parameter(description = "디바이스토큰 id")@RequestParam( required = false) Integer fcmTokenId, @Parameter(description = "토큰값",required = true) @RequestParam String fcmToken){
Integer updatedFcmTokenId =userService.updateFcmToken(userId,fcmTokenId,fcmToken);
return new BaseResponse<>(Status.SUCCESS,updatedFcmTokenId);
}

@Operation(summary="알림설정 동의 변경")
@PatchMapping("/push")
public BaseResponse<Status> updateAgreePush(@Parameter(hidden = true) @AuthUser Integer userId,@RequestParam() boolean agreePush){
userService.updateAgreePush(userId,agreePush);
return new BaseResponse<>(Status.SUCCESS);
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {


Optional<User> findById(Integer integer);

Optional<User> findBySocialId(String userId);

}
61 changes: 38 additions & 23 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/users/UserService.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
package com.wakeUpTogetUp.togetUp.api.users;

import com.wakeUpTogetUp.togetUp.api.users.dto.request.LoginReq;
import com.wakeUpTogetUp.togetUp.api.users.dto.request.PatchUserReq;
import com.wakeUpTogetUp.togetUp.api.users.dto.request.SocialLoginReq;
import com.wakeUpTogetUp.togetUp.api.users.dto.request.UserReq;
import com.wakeUpTogetUp.togetUp.api.auth.AuthUser;
import com.wakeUpTogetUp.togetUp.api.users.fcmToken.FcmToken;
import com.wakeUpTogetUp.togetUp.api.users.fcmToken.FcmTokenRepository;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.api.users.dto.response.UserInfoRes;
import com.wakeUpTogetUp.togetUp.api.users.dto.response.UserRes;
import com.wakeUpTogetUp.togetUp.api.users.dto.response.UserTokenRes;
import com.wakeUpTogetUp.togetUp.utils.JwtService;
import com.wakeUpTogetUp.togetUp.utils.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Objects;


@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class UserService {

private final UserRepository userRepository;
private final JwtService jwtService;





private final FcmTokenRepository fcmTokenRepository;


public Integer updateFcmToken(Integer userId, Integer fcmTokenId, String fcmToken) {

User user = userRepository.findById(userId).orElse(null);
FcmToken fcmTokenObject;
if (Objects.isNull(user))
new BaseException(Status.INVALID_USER_ID);
if(fcmTokenId==null)
{
fcmTokenObject = FcmToken.builder()
.value(fcmToken)
.user(user)
.build();
}else {
fcmTokenObject = fcmTokenRepository.findById(fcmTokenId).orElse(
FcmToken.builder()
.value(fcmToken)
.user(user)
.build());
fcmTokenObject.updateFcmToken(fcmToken);
}

return fcmTokenRepository.save(fcmTokenObject).getId();

}

public void updateAgreePush(Integer userId, boolean agreePush){
User user = userRepository.findById(userId).orElseThrow(() -> new BaseException(Status.USER_NOT_FOUND));
user.setAgreePush(agreePush);
userRepository.save(user);
}

}
Loading