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

Develop #284

Merged
merged 8 commits into from
Oct 1, 2024
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 .github/workflows/admin-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- 'sluv-common/**'
- 'sluv-infra/**'

concurrency:
group: ${{ github.ref_name }}

jobs:
admin-ci-cd:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/api-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- 'sluv-common/**'
- 'sluv-infra/**'

concurrency:
group: ${{ github.ref_name }}

jobs:
api-ci-cd:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/batch-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- 'sluv-common/**'
- 'sluv-infra/**'

concurrency:
group: ${{ github.ref_name }}

jobs:
batch-ci-cd:
runs-on: ubuntu-latest
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

6 changes: 3 additions & 3 deletions sluv-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ dependencies {

}

//tasks.named('test') {
// dependsOn ':sluv-domain:test', ':sluv-common:test', ':sluv-infra:test'
//}
tasks.named('test') {
dependsOn ':sluv-domain:test', ':sluv-common:test', ':sluv-infra:test'
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public PaginationResponse<AlarmResponse> getAlarmsByUserId(Long userId, Pageable
return PaginationResponse.create(alarmPage, content);
}

@Transactional(readOnly = true)
private AlarmImages getAlarmImages(Alarm alarm) {
List<QuestionImgSimpleDto> images = new ArrayList<>();
String useImageUrl = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.sluv.common.constant.ConstantData.ALARM_TITLE;

@Service
@Transactional
@RequiredArgsConstructor
public class UserAlarmService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;

@RestController
Expand Down Expand Up @@ -51,6 +52,7 @@ public ResponseEntity<SuccessDataResponse<AuthResponse>> socialLogin(@RequestBod
return ResponseEntity.ok().body(SuccessDataResponse.create(response));
}

@Deprecated
@Operation(summary = "*자동 로그인", description = "토큰 만료 시 error code : 4002")
@GetMapping("/auto-login")
public ResponseEntity<SuccessDataResponse<AutoLoginResponse>> autoLogin(@CurrentUserId Long userId) {
Expand All @@ -61,6 +63,20 @@ public ResponseEntity<SuccessDataResponse<AutoLoginResponse>> autoLogin(@Current
return ResponseEntity.ok().body(SuccessDataResponse.create(response));
}

@Operation(summary = "*자동 로그인", description = "토큰 만료 시 error code : 4002")
@PostMapping("/auto-login")
public ResponseEntity<SuccessDataResponse<AutoLoginResponse>> autoLoginWithFcm(@CurrentUserId Long userId,
@Nullable @RequestBody AutoLoginRequest request) {
cacheService.visitMember(userId);
if (request != null) {
authService.changeFcm(userId, request.getFcm());
}
User user = authService.findLogInUser(userId);
// authService.checkFcm(user);
AutoLoginResponse response = AutoLoginResponse.of(user);
return ResponseEntity.ok().body(SuccessDataResponse.create(response));
}

@Operation(summary = "*FCM 토큰 갱신", description = "FCM 토큰을 갱신")
@PostMapping("/fcm")
public ResponseEntity<SuccessResponse> changeFcm(@CurrentUserId Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ public class AutoLoginResponse {
@Schema(description = "유저 Status")
private UserStatus userStatus;

@Schema(description = "유저 FCM")
private String fcm;

public static AutoLoginResponse of(User user) {
return AutoLoginResponse.builder()
.userStatus(user.getUserStatus())
.fcm(user.getFcmToken())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AuthResponse getAuthResDto(User user) {

@Transactional
public User getOrCreateUser(SocialUserInfoDto userInfoDto, SnsType snsType, String fcm) {
User user = userDomainService.findByEmailOrNull(userInfoDto.getEmail());
User user = userDomainService.findBySnsWithEmailOrNull(userInfoDto.getEmail(), snsType);

if (user == null) {
user = userDomainService.createUser(User.toEntity(userInfoDto, snsType, fcm));
Expand All @@ -52,7 +52,6 @@ public void checkFcm(User user) {
public void changeFcm(Long userId, String fcmToken) {
User user = userDomainService.findById(userId);
user.changeFcmToken(fcmToken);
userDomainService.saveUser(user);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.sluv.api.config.security;

import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;

@Configuration
public class CorsConfig {

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(
Arrays.asList("https://www.sluv.co.kr", "http://localhost:3000", "https://sluv-server.co.kr"));
Arrays.asList("https://www.sluv.co.kr", "http://localhost:3000", "https://sluv-server.co.kr", "https://dev.sluv.co.kr"));
configuration.addAllowedHeader("Authorization");
configuration.addAllowedHeader("Content-Type");
configuration.addAllowedMethod("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,12 @@ public ResponseEntity<SuccessResponse> withdrawUser(@CurrentUserId Long userId,
userService.withdrawUser(userId, dto);
return ResponseEntity.ok().body(SuccessResponse.create());
}

@Operation(summary = "사용자 알람 수신 여부 수정", description = "기본값 false, 호출 시 현재 상태의 반대로 수정")
@PatchMapping("/alarm-status")
public ResponseEntity<SuccessDataResponse<UserAlarmStatusResponse>> changeUserAlarmStatus(@CurrentUserId Long userId) {
UserAlarmStatusResponse response = userService.changeAlarmStatus(userId);
return ResponseEntity.ok().body(SuccessDataResponse.create(response));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sluv.api.user.dto;

import com.sluv.domain.user.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserAlarmStatusResponse {
@Schema(description = "알람 수신동의 상태")
private Boolean alarmStatus;

public static UserAlarmStatusResponse from(User user) {
return UserAlarmStatusResponse.builder()
.alarmStatus(user.getAlarmStatus())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void withdrawUser(Long userId, UserWithdrawReqDto dto) {
userWithdrawDataService.withdrawUserByUserId(user.getId());

userWithdrawDomainService.saveUserWithdraw(user, dto.getReason(), dto.getContent());
webHookService.sendWithdrawMessage(user);
webHookService.sendWithdrawMessage(user, dto.getReason(), dto.getContent());

}

Expand All @@ -262,4 +262,12 @@ public UserTermsResDto findUserTermsStatus(Long userId) {
return UserTermsResDto.of(user);
}

@Transactional
public UserAlarmStatusResponse changeAlarmStatus(Long userId) {
User user = userDomainService.findById(userId);
Boolean alarmStatus = user.getAlarmStatus();
user.changeAlarmStatus(!alarmStatus);
return UserAlarmStatusResponse.from(user);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sluv.domain.alarm.dto;

import lombok.*;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class AlarmCheckResponse {

private Boolean isAllRead;

public static AlarmCheckResponse of(Boolean isAllRead) {
return AlarmCheckResponse.builder()
.isAllRead(isAllRead)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public List<Celeb> findTop10Celeb() {
}

public Celeb findByIdOrNull(Long celebId) {
if (celebId == null) {
return null;
}
return celebRepository.findById(celebId).orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public NewCeleb saveNewCelebByName(NewCeleb newCeleb) {
}

public NewCeleb findByNewCelebIdOrNull(Long newCelebId) {
if (newCelebId == null) {
return null;
}
return newCelebRepository.findById(newCelebId).orElseThrow(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.sluv.domain.user.repository.impl;

import com.sluv.domain.auth.enums.SnsType;
import com.sluv.domain.user.entity.User;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;

public interface UserRepositoryCustom {
Page<User> getSearchUser(List<Long> userIdList, Pageable pageable);

Expand All @@ -19,4 +22,6 @@ public interface UserRepositoryCustom {
long getNotDeleteUserCount();

List<User> getDeletedUsersAfter7Days();

Optional<User> findBySnsWithEmailOrNull(String email, SnsType snsType);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.sluv.domain.user.repository.impl;

import static com.sluv.domain.celeb.entity.QInterestedCeleb.interestedCeleb;
import static com.sluv.domain.item.entity.QItem.item;
import static com.sluv.domain.item.entity.QItemLike.itemLike;
import static com.sluv.domain.user.entity.QFollow.follow;
import static com.sluv.domain.user.entity.QUser.user;
import static com.sluv.domain.user.enums.UserStatus.ACTIVE;
import static com.sluv.domain.user.enums.UserStatus.DELETED;

import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.sluv.domain.auth.enums.SnsType;
import com.sluv.domain.item.enums.ItemStatus;
import com.sluv.domain.user.entity.Follow;
import com.sluv.domain.user.entity.QUser;
import com.sluv.domain.user.entity.User;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import static com.sluv.domain.celeb.entity.QInterestedCeleb.interestedCeleb;
import static com.sluv.domain.item.entity.QItem.item;
import static com.sluv.domain.item.entity.QItemLike.itemLike;
import static com.sluv.domain.user.entity.QFollow.follow;
import static com.sluv.domain.user.entity.QUser.user;
import static com.sluv.domain.user.enums.UserStatus.ACTIVE;
import static com.sluv.domain.user.enums.UserStatus.DELETED;

@RequiredArgsConstructor
public class UserRepositoryImpl implements UserRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;
Expand Down Expand Up @@ -164,4 +168,12 @@ public List<User> getDeletedUsersAfter7Days() {
.and(user.updatedAt.before(LocalDateTime.now().minusDays(7)))
).fetch();
}

@Override
public Optional<User> findBySnsWithEmailOrNull(String email, SnsType snsType) {
User user = jpaQueryFactory.selectFrom(QUser.user)
.where(QUser.user.snsType.eq(snsType).and(QUser.user.email.eq(email)))
.fetchOne();
return Optional.ofNullable(user);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sluv.domain.user.service;

import com.sluv.domain.auth.enums.SnsType;
import com.sluv.domain.user.entity.User;
import com.sluv.domain.user.exception.UserNotFoundException;
import com.sluv.domain.user.repository.UserRepository;
Expand Down Expand Up @@ -55,7 +56,7 @@ public Page<User> getSearchUser(List<Long> searchUserIds, Pageable pageable) {
return userRepository.getSearchUser(searchUserIds, pageable);
}

public User findByEmailOrNull(String email) {
return userRepository.findByEmail(email).orElse(null);
public User findBySnsWithEmailOrNull(String email, SnsType snsType) {
return userRepository.findBySnsWithEmailOrNull(email, snsType).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import com.sluv.domain.celeb.entity.NewCeleb;
import com.sluv.domain.user.entity.User;
import com.sluv.domain.user.enums.UserStatus;
import com.sluv.domain.user.enums.UserWithdrawReason;
import com.sluv.domain.user.repository.UserRepository;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

@Service
@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -61,7 +63,7 @@ public void sendSingupMessage(User user) {
@Override
@Async("asyncThreadPoolExecutor")
@Transactional
public void sendWithdrawMessage(User user) {
public void sendWithdrawMessage(User user, UserWithdrawReason reason, String content) {
long userCount = userRepository.getNotDeleteUserCount() - 1;
long activeUser = userRepository.countByUserStatus(UserStatus.ACTIVE);
LocalDateTime now = LocalDateTime.now();
Expand All @@ -74,6 +76,7 @@ public void sendWithdrawMessage(User user) {
.append("- 연령대: ").append(user.getAgeRange()).append("\n")
.append("- 성별: ").append(user.getGender()).append("\n")
.append("- 탈퇴 시간: ").append(date).append(" ").append(localTime).append("\n")
.append("- 탈퇴 사유: ").append(reason).append(" -> ").append(content).append("\n")
.append("### 현재 __**").append(activeUser).append("명**__의 **활성화** 유저").append("\n")
.append("### 현재 __**").append(userCount).append("명**__의 유저")
.toString();
Expand Down
Loading
Loading