Skip to content

Commit

Permalink
Merge pull request #28 from LikelionUniv/feature/mypage
Browse files Browse the repository at this point in the history
Feature/mypage
  • Loading branch information
seulgi99 authored Nov 13, 2023
2 parents 49c8dab + a3c3de7 commit 7d17c86
Show file tree
Hide file tree
Showing 92 changed files with 1,551 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableCaching
@EnableJpaAuditing
@EnableScheduling
@EnableAsync
@SpringBootApplication
public class LikelionClientApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package likelion.univ.alarm.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import likelion.univ.alarm.dto.request.AlarmRegisterRequestDto;
import likelion.univ.alarm.usecase.RegisterAlarmUseCase;
import likelion.univ.response.SuccessResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/v1/alarm")
@Tag(name = "알람", description = "알람 API")
public class AlarmController {
private final RegisterAlarmUseCase registerAlarmUseCase;

@Operation(summary = "알람 등록", description = "이메일과 알람 타입을 입력받아 해당 기수의 알람을 등록합니다.")
@PostMapping("/{ordinal}/register")
public SuccessResponse registerAlarm(@PathVariable Long ordinal,
@RequestBody AlarmRegisterRequestDto alarmRegisterRequestDto){
registerAlarmUseCase.execute(ordinal, alarmRegisterRequestDto);
return SuccessResponse.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package likelion.univ.alarm.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import likelion.univ.domain.alarm.entity.Alarm;
import likelion.univ.domain.alarm.entity.AlarmType;
import likelion.univ.domain.alarm.entity.SendStatus;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

import static likelion.univ.domain.alarm.entity.SendStatus.NOT_SENT;

@Getter
@NoArgsConstructor
public class AlarmRegisterRequestDto {
@NotNull
@Schema(description = "이메일", example = "tmfrk0426@gmail.com", required = true)
private String email;

@NotNull
@Schema(description = "알람 타입", example = "NEW_UNIVERSITY_RECRUITING", required = true, enumAsRef = true)
private AlarmType alarmType;

public static Alarm toEntity(Long ordinal, AlarmRegisterRequestDto alarmRegisterRequestDto){
return Alarm.builder()
.ordinal(ordinal)
.email(alarmRegisterRequestDto.getEmail())
.alarmType(alarmRegisterRequestDto.getAlarmType())
.sendStatus(NOT_SENT)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package likelion.univ.alarm.usecase;

import likelion.univ.alarm.dto.request.AlarmRegisterRequestDto;
import likelion.univ.annotation.UseCase;
import likelion.univ.domain.alarm.adaptor.AlarmAdaptor;
import likelion.univ.domain.alarm.entity.Alarm;
import likelion.univ.domain.alarm.service.AlarmDomainService;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class RegisterAlarmUseCase {
private final AlarmAdaptor alarmAdaptor;
private final AlarmDomainService alarmDomainService;

public void execute(Long ordinal, AlarmRegisterRequestDto alarmRegisterRequestDto){
alarmAdaptor.existsByOrdinalAndEmailAndAlarmType(ordinal,
alarmRegisterRequestDto.getEmail(), alarmRegisterRequestDto.getAlarmType());
Alarm newAlarm = AlarmRegisterRequestDto.toEntity(ordinal, alarmRegisterRequestDto);
alarmDomainService.createAlarm(newAlarm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import likelion.univ.auth.dto.response.AccountTokenDto;
import likelion.univ.auth.dto.response.AccountUserInfoDto;
import likelion.univ.auth.dto.response.IdTokenDto;
import likelion.univ.auth.usecase.LoginUseCase;
import likelion.univ.auth.usecase.RefreshTokenUseCase;
import likelion.univ.auth.usecase.RequestIdTokenUseCase;
import likelion.univ.auth.usecase.SignUpUseCase;
import likelion.univ.auth.usecase.*;
import likelion.univ.auth.dto.request.SignUpRequestDto;
import likelion.univ.response.SuccessResponse;
import likelion.univ.utils.AuthentiatedUserUtils;
Expand All @@ -24,7 +22,7 @@ public class AuthController {
private final RequestIdTokenUseCase requestIdTokenUseCase;
private final SignUpUseCase signUpUseCase;
private final RefreshTokenUseCase refreshTokenUseCase;
private final AuthentiatedUserUtils userUtils;
private final GetUserInfoUseCase getUserInfoUsecase;

@Operation(summary = "id token 발급", description = "인가 코드로 id token을 발급받습니다.")
@GetMapping("/{logintype}/idtoken")
Expand Down Expand Up @@ -55,17 +53,18 @@ public SuccessResponse<Object> signUp(
return SuccessResponse.of(accountTokenDto);
}

@Operation(summary = "유저 정보 조회", description = "간단한 유저정보를 조회합니다.")
@GetMapping("/userinfo")
public SuccessResponse<Object> getUserInfo(){
AccountUserInfoDto accountUserInfoDto = getUserInfoUsecase.execute();
return SuccessResponse.of(accountUserInfoDto);
}

@Operation(summary = "토큰 재발급", description = "refresh token으로 access token을 재발급합니다.")
@PostMapping("/refresh")
public SuccessResponse<Object> refreshToken(
@RequestParam("token") String refreshToken){
AccountTokenDto accountTokenDto = refreshTokenUseCase.execute(refreshToken);
return SuccessResponse.of(accountTokenDto);
}

@Operation(summary = "로그인 유저 Id 반환", description = "(for client only) 로그인 중인 유저의 Id를 얻습니다.")
@GetMapping("/loginuserid")
public SuccessResponse<?> getLoginUserId() {
return SuccessResponse.of(userUtils.getCurrentUserId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package likelion.univ.auth.dto.response;

import likelion.univ.domain.user.entity.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class AccountUserInfoDto {
private Long userId;
private String profileImage;
private String name;

public static AccountUserInfoDto of(User user){
return AccountUserInfoDto.builder()
.userId(user.getId())
.profileImage(user.getProfile().getProfileImage())
.name(user.getProfile().getName())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package likelion.univ.auth.usecase;

import likelion.univ.annotation.UseCase;
import likelion.univ.auth.dto.response.AccountUserInfoDto;
import likelion.univ.domain.user.entity.User;
import likelion.univ.utils.AuthentiatedUserUtils;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class GetUserInfoUseCase {

private final AuthentiatedUserUtils authentiatedUserUtils;

public AccountUserInfoDto execute(){
User user = authentiatedUserUtils.getCurrentUser();
return AccountUserInfoDto.of(user);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package likelion.univ.follow.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import likelion.univ.follow.usecase.CancelFollowUseCase;
import likelion.univ.follow.usecase.FollowUserUseCase;
import likelion.univ.response.SuccessResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/v1/follow")
@Tag(name = "팔로우", description = "팔로우 관련 API입니다.")
public class FollowController {
private final FollowUserUseCase followUserUseCase;
private final CancelFollowUseCase cancelFollowUseCase;

@Operation(summary = "팔로우 ", description = "해당 유저를 팔로우 합니다.")
@PostMapping("/{userId}")
public SuccessResponse<Object> follow(@PathVariable("userId") Long userId){
followUserUseCase.execute(userId);
return SuccessResponse.empty();
}

@Operation(summary = "팔로우 취소", description = "해당 유저를 팔로우 취소 합니다.")
@DeleteMapping("/{userId}")
public SuccessResponse<Object> deleteFollow(@PathVariable("userId") Long userId) {
cancelFollowUseCase.execute(userId);
return SuccessResponse.empty();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package likelion.univ.follow.usecase;

import likelion.univ.annotation.UseCase;
import likelion.univ.domain.follow.adaptor.FollowAdaptor;
import likelion.univ.follow.dao.FollowNumRedisDao;
import likelion.univ.follow.entity.FollowNum;
import likelion.univ.follow.service.FollowNumRedisService;
import likelion.univ.utils.AuthentiatedUserUtils;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@UseCase
@RequiredArgsConstructor
public class CancelFollowUseCase {
private final AuthentiatedUserUtils authentiatedUserUtils;
private final FollowAdaptor followAdaptor;
private final FollowNumRedisDao followNumRedisDao;
private final FollowNumRedisService followNumRedisService;

public void execute(Long userId){
Long currentUserId = authentiatedUserUtils.getCurrentUserId();
followAdaptor.delete(currentUserId, userId);
updateFollowNumRedis(currentUserId, userId);
}

private void updateFollowNumRedis(Long currentUserId, Long userId){
Optional<FollowNum> myFollowNum = followNumRedisDao.findById(currentUserId);
if(myFollowNum.isPresent()) followNumRedisService.followingDown(currentUserId, myFollowNum.get());
Optional<FollowNum> targetFollowNum = followNumRedisDao.findById(userId);
if(targetFollowNum.isPresent()) followNumRedisService.followerDown(userId, targetFollowNum.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package likelion.univ.follow.usecase;

import likelion.univ.annotation.UseCase;
import likelion.univ.domain.follow.adaptor.FollowAdaptor;
import likelion.univ.follow.dao.FollowNumRedisDao;
import likelion.univ.follow.entity.FollowNum;
import likelion.univ.follow.service.FollowNumRedisService;
import likelion.univ.utils.AuthentiatedUserUtils;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@UseCase
@RequiredArgsConstructor
public class FollowUserUseCase {
private final AuthentiatedUserUtils authentiatedUserUtils;
private final FollowAdaptor followAdaptor;
private final FollowNumRedisDao followNumRedisDao;
private final FollowNumRedisService followNumRedisService;

public void execute(Long userId){
Long currentUserId = authentiatedUserUtils.getCurrentUserId();
followAdaptor.save(currentUserId, userId);
updateFollowNumRedis(currentUserId, userId);
}

private void updateFollowNumRedis(Long currentUserId, Long userId){
Optional<FollowNum> myFollowNum = followNumRedisDao.findById(currentUserId);
if(myFollowNum.isPresent()) followNumRedisService.followingUp(currentUserId, myFollowNum.get());
Optional<FollowNum> targetFollowNum = followNumRedisDao.findById(userId);
if(targetFollowNum.isPresent()) followNumRedisService.followerUp(userId, targetFollowNum.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package likelion.univ.post.repository;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import likelion.univ.domain.post.dto.response.PostDetailResponseDto;
import likelion.univ.domain.post.dto.response.QPostDetailResponseDto;
import likelion.univ.domain.post.entity.enums.MainCategory;
Expand All @@ -9,7 +9,6 @@
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.Pageable;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand Down
Loading

0 comments on commit 7d17c86

Please sign in to comment.