Skip to content

Commit

Permalink
Merge pull request #171 from theMomentTeam/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jyeonjyan authored Jun 19, 2021
2 parents 1060d1e + 5886d1e commit 639b91d
Show file tree
Hide file tree
Showing 69 changed files with 601 additions and 567 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.domain;
package com.moment.the.admin;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.moment.the.controller.release;

import com.moment.the.domain.response.CommonResult;
import com.moment.the.domain.response.ResponseService;
import com.moment.the.domain.response.SingleResult;
import com.moment.the.dto.AdminDto;
import com.moment.the.dto.SignInDto;
import com.moment.the.service.AdminService;
package com.moment.the.admin.controller;


import com.moment.the.admin.dto.AdminDto;
import com.moment.the.admin.dto.SignInDto;
import com.moment.the.admin.service.AdminService;
import com.moment.the.response.ResponseService;
import com.moment.the.response.result.CommonResult;
import com.moment.the.response.result.SingleResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moment.the.dto;
package com.moment.the.admin.dto;

import com.moment.the.domain.AdminDomain;

import com.moment.the.admin.AdminDomain;
import lombok.*;

import javax.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moment.the.dto;
package com.moment.the.admin.dto;

import com.moment.the.domain.AdminDomain;
import com.moment.the.admin.AdminDomain;
import lombok.*;

import javax.validation.constraints.NotBlank;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moment.the.repository;
package com.moment.the.admin.repository;

import com.moment.the.domain.AdminDomain;
import com.moment.the.admin.AdminDomain;
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,7 +1,7 @@
package com.moment.the.service;
package com.moment.the.admin.service;

import com.moment.the.dto.AdminDto;
import com.moment.the.dto.SignInDto;
import com.moment.the.admin.dto.AdminDto;
import com.moment.the.admin.dto.SignInDto;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.moment.the.service;
package com.moment.the.admin.service;

import com.moment.the.advice.exception.UserAlreadyExistsException;
import com.moment.the.advice.exception.UserNotFoundException;
import com.moment.the.config.security.JwtUtil;
import com.moment.the.domain.AdminDomain;
import com.moment.the.dto.AdminDto;
import com.moment.the.dto.SignInDto;
import com.moment.the.repository.AdminRepository;
import com.moment.the.admin.AdminDomain;
import com.moment.the.admin.dto.AdminDto;
import com.moment.the.admin.dto.SignInDto;
import com.moment.the.admin.repository.AdminRepository;
import com.moment.the.config.security.jwt.JwtUtil;
import com.moment.the.exceptionAdvice.exception.UserAlreadyExistsException;
import com.moment.the.exceptionAdvice.exception.UserNotFoundException;
import com.moment.the.util.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void withdrawal(SignInDto signInDto) throws Exception {
}

//현재 로그인 된 사용자의 ID를 Return
public String getUserEmail() {
static public String getUserEmail() {
String userEmail;
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(principal instanceof UserDetails) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.moment.the.domain;
package com.moment.the.answer;

import com.moment.the.dto.AnswerDto;


import com.moment.the.admin.AdminDomain;
import com.moment.the.answer.dto.AnswerDto;
import com.moment.the.table.TableDomain;
import com.sun.istack.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.moment.the.controller.release;

import com.moment.the.domain.response.CommonResult;
import com.moment.the.domain.response.ResponseService;
import com.moment.the.domain.response.SingleResult;
import com.moment.the.dto.AnswerDto;
import com.moment.the.dto.AnswerResDto;
import com.moment.the.service.AnswerService;
package com.moment.the.answer.controller;


import com.moment.the.answer.dto.AnswerDto;
import com.moment.the.answer.dto.AnswerResDto;
import com.moment.the.answer.service.AnswerService;
import com.moment.the.response.ResponseService;
import com.moment.the.response.result.CommonResult;
import com.moment.the.response.result.SingleResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.moment.the.dto;
package com.moment.the.answer.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.moment.the.domain.AdminDomain;
import com.moment.the.domain.AnswerDomain;
import com.moment.the.domain.TableDomain;

import com.moment.the.admin.AdminDomain;
import com.moment.the.answer.AnswerDomain;
import lombok.*;

@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.dto;
package com.moment.the.answer.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.moment.the.repository;
package com.moment.the.answer.repository;

import com.moment.the.domain.AdminDomain;
import com.moment.the.domain.AnswerDomain;

import com.moment.the.admin.AdminDomain;
import com.moment.the.answer.AnswerDomain;
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,17 +1,16 @@
package com.moment.the.service;

import com.moment.the.advice.exception.*;
import com.moment.the.domain.AdminDomain;
import com.moment.the.domain.AnswerDomain;
import com.moment.the.domain.TableDomain;
import com.moment.the.dto.AnswerDto;
import com.moment.the.dto.AnswerResDto;
import com.moment.the.repository.AdminRepository;
import com.moment.the.repository.AnswerRepository;
import com.moment.the.repository.TableRepository;
package com.moment.the.answer.service;

import com.moment.the.admin.AdminDomain;
import com.moment.the.admin.repository.AdminRepository;
import com.moment.the.admin.service.AdminServiceImpl;
import com.moment.the.answer.AnswerDomain;
import com.moment.the.answer.dto.AnswerDto;
import com.moment.the.answer.dto.AnswerResDto;
import com.moment.the.answer.repository.AnswerRepository;
import com.moment.the.exceptionAdvice.exception.*;
import com.moment.the.table.TableDomain;
import com.moment.the.table.repository.TableRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,33 +22,37 @@ public class AnswerService {
final private TableRepository tableRepo;

// 답변 작성하기
public void save(AnswerDto answerDto, Long boardIdx) {
public AnswerDomain save(AnswerDto answerDto, Long boardIdx) {
//예외 처리
TableDomain tableDomain = tableFindBy(boardIdx); // table 번호로 찾고 없으면 Exception
boolean existAnswer = tableDomain.getAnswerDomain() != null ? true : false;
if(existAnswer) throw new AnswerAlreadyExistsException(); //이미 답변이 있으면 Exception

AdminDomain adminDomain = adminRepo.findByAdminId(getLoginAdminEmail());
AdminDomain adminDomain = adminRepo.findByAdminId(AdminServiceImpl.getUserEmail());

// AnswerDomain 생성 및 Table 과의 연관관계 맻음
answerDto.setAdminDomain(adminDomain);
AnswerDomain saveAnswerDomain = answerDto.toEntity();
saveAnswerDomain.updateTableDomain(tableDomain);

answerRepo.save(saveAnswerDomain);
AnswerDomain savedAnswerDomain = answerRepo.save(saveAnswerDomain);

return savedAnswerDomain;
}

// 답변 수정하기
@Transactional
public void update(AnswerDto answerDto, Long answerIdx) {
public AnswerDomain update(AnswerDto answerDto, Long answerIdx) {
AnswerDomain answerDomain = answerFindBy(answerIdx); // 해당하는 answer 찾기
AdminDomain answerAdmin = answerDomain.getAdminDomain();
AdminDomain loginAdmin = adminRepo.findByAdminId(getLoginAdminEmail());
AdminDomain loginAdmin = adminRepo.findByAdminId(AdminServiceImpl.getUserEmail());

answerOwnerCheck(answerAdmin, loginAdmin); // 자신이 작성한 답변인지 확인

// 답변 업데이트하기
answerDomain.update(answerDto);

return answerDomain;
}

public AnswerResDto view(Long boardIdx) {
Expand All @@ -73,7 +76,7 @@ public void delete(Long answerIdx) {
AnswerDomain answerDomain = answerFindBy(answerIdx);
AdminDomain answerAdmin = answerDomain.getAdminDomain();

AdminDomain loginAdmin = adminRepo.findByAdminId(getLoginAdminEmail());
AdminDomain loginAdmin = adminRepo.findByAdminId(AdminServiceImpl.getUserEmail());
answerOwnerCheck(answerAdmin, loginAdmin); // 자신이 작성한 답변인지 확인

// answer 삭제하기
Expand All @@ -95,18 +98,6 @@ public TableDomain tableFindBy(Long tableId){
return tableRepo.findById(tableId).orElseThrow(NoPostException::new);
}

// Current userEmail 을 가져오기.
public String getLoginAdminEmail() {
String userEmail;
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(principal instanceof UserDetails) {
userEmail = ((UserDetails)principal).getUsername();
} else {
userEmail = principal.toString();
}
return userEmail;
}

public void deleteAnswer(AnswerDomain answerDomain){
Long answerIdx = answerDomain.getAnswerIdx();
answerDomain.getTableDomain().updateAnswerDomain(null); // 외래키 제약조건으로 인한 오류 해결
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.config.security;
package com.moment.the.config.exception;

import net.rakugakibox.util.YamlResourceBundle;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.moment.the.config.security;

import com.moment.the.advice.ExceptionAdvice;
import com.moment.the.advice.exception.AccessTokenExpiredException;
import com.moment.the.advice.exception.InvalidTokenException;
import com.moment.the.advice.exception.UserNotFoundException;
import com.moment.the.domain.response.CommonResult;
import com.moment.the.domain.response.ResponseService;
package com.moment.the.config.mvc;

import com.moment.the.exceptionAdvice.ExceptionAdvice;
import com.moment.the.exceptionAdvice.exception.AccessTokenExpiredException;
import com.moment.the.exceptionAdvice.exception.InvalidTokenException;
import com.moment.the.exceptionAdvice.exception.UserNotFoundException;
import com.moment.the.response.ResponseService;
import com.moment.the.response.result.CommonResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.moment.the.config.security;

import com.moment.the.config.mvc.ExceptionHandlerFilter;
import com.moment.the.config.security.jwt.JwtRequestFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.moment.the.config.security;
package com.moment.the.config.security.auth;

import com.moment.the.domain.AdminDomain;
import com.moment.the.repository.AdminRepository;
import com.moment.the.admin.AdminDomain;
import com.moment.the.admin.repository.AdminRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.moment.the.config.security;
package com.moment.the.config.security.jwt;

import com.moment.the.advice.exception.AccessTokenExpiredException;
import com.moment.the.advice.exception.InvalidTokenException;
import com.moment.the.advice.exception.UserNotFoundException;
import com.moment.the.config.security.auth.MyUserDetailsService;
import com.moment.the.exceptionAdvice.exception.AccessTokenExpiredException;
import com.moment.the.exceptionAdvice.exception.InvalidTokenException;
import com.moment.the.exceptionAdvice.exception.UserNotFoundException;
import com.moment.the.util.RedisUtil;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.config.security;
package com.moment.the.config.security.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.moment.the.advice;
package com.moment.the.exceptionAdvice;

import com.moment.the.advice.exception.*;
import com.moment.the.domain.response.CommonResult;
import com.moment.the.domain.response.ResponseService;
import com.moment.the.exceptionAdvice.exception.*;
import com.moment.the.response.result.CommonResult;
import com.moment.the.response.ResponseService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.moment.the.controller.exception;
package com.moment.the.exceptionAdvice.controller;

import com.moment.the.advice.exception.*;
import com.moment.the.domain.response.CommonResult;
import com.moment.the.exceptionAdvice.exception.*;
import com.moment.the.response.result.CommonResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class AccessNotFoundException extends RuntimeException{
public AccessNotFoundException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class AccessTokenExpiredException extends RuntimeException{
public AccessTokenExpiredException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class AnswerAlreadyExistsException extends RuntimeException{
public AnswerAlreadyExistsException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class CustomMethodArgumentNotValidException extends RuntimeException{
public CustomMethodArgumentNotValidException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class GoodsNotCancelException extends RuntimeException{
public GoodsNotCancelException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class InvalidTokenException extends RuntimeException{
public InvalidTokenException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class NoCommentException extends RuntimeException{
public NoCommentException(String msg, Throwable t){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moment.the.advice.exception;
package com.moment.the.exceptionAdvice.exception;

public class NoGoodException extends RuntimeException{
public NoGoodException(String msg, Throwable t){
Expand Down
Loading

0 comments on commit 639b91d

Please sign in to comment.