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

issue/135 ✨ [FEAT] 오류 문의 및 신고하기 API 구현 #141

Merged
merged 3 commits into from
Sep 27, 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
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public String generateStepKeyName(Uuid uuid) {
return amazonConfig.getRecipeStep() + '/' + uuid.getUuid();
}

public String generateInqueryKeyName(Uuid uuid) {return amazonConfig.getInquery() + '/' + uuid.getUuid();}

// 중복된 UUID가 있다면 중복이 없을때까지 재귀적으로 동작
public Uuid createUUID() {
Uuid savedUuid = null;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/zipdabang/server/config/AmazonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class AmazonConfig {
@Value("${cloud.aws.s3.folder.zipdabang-proifile}")
private String userProfile;

@Value("${cloud.aws.s3.folder.zipdabang-inquery}")
private String inquery;


private AWSCredentials awsCredentials;

Expand Down
72 changes: 72 additions & 0 deletions src/main/java/zipdabang/server/converter/MemberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import zipdabang.server.aws.s3.AmazonS3Manager;
import zipdabang.server.base.Code;
import zipdabang.server.base.exception.handler.MemberException;
import zipdabang.server.domain.Category;
import zipdabang.server.domain.enums.GenderType;
import zipdabang.server.domain.enums.SocialType;
import zipdabang.server.domain.etc.Uuid;
import zipdabang.server.domain.member.*;
import zipdabang.server.domain.member.Deregister;
import zipdabang.server.domain.member.Terms;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.member.MemberPreferCategory;
import zipdabang.server.repository.memberRepositories.MemberRepository;
import zipdabang.server.utils.converter.TimeConverter;
import zipdabang.server.utils.dto.OAuthJoin;
import zipdabang.server.web.dto.requestDto.MemberRequestDto;
import zipdabang.server.web.dto.responseDto.MemberResponseDto;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Component
Expand All @@ -34,8 +42,12 @@ public class MemberConverter {

private static MemberRepository staticMemberRepository;

private final AmazonS3Manager amazonS3Manager;

private static String defaultProfileImage;

private static AmazonS3Manager staticAmazonS3Manager;

@Value("${cloud.aws.s3.user-default-image}")
public void setDefaultImage(String value) {
defaultProfileImage=value;
Expand Down Expand Up @@ -105,6 +117,7 @@ public static MemberResponseDto.SocialJoinDto toSocialJoinDto(OAuthJoin.OAuthJoi
@PostConstruct
public void init() {
this.staticMemberRepository = this.memberRepository;
this.staticAmazonS3Manager = amazonS3Manager;
}


Expand Down Expand Up @@ -234,6 +247,65 @@ public static MemberResponseDto.TempLoginDto toTempLoginDto(String token){
.build();
}

public static MemberResponseDto.MemberInqueryResultDto toMemberInqueryResultDto(Inquery inquery){
return MemberResponseDto.MemberInqueryResultDto.builder()
.id(inquery.getId())
.created_at(inquery.getMember().getCreatedAt())
.build();
}


public static List<InqueryImage> toInqueryImage(List<MultipartFile> imageList)
{
List<InqueryImage> inqueryImageList = imageList.stream()
.map(
image ->
{
try {
Uuid uuid = staticAmazonS3Manager.createUUID();
String keyName = staticAmazonS3Manager.generateInqueryKeyName(uuid);
String inqueryImageUrl = staticAmazonS3Manager.uploadFile(keyName, image);
return InqueryImage.builder()
.imageUrl(inqueryImageUrl)
.build();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
).collect(Collectors.toList());
return inqueryImageList;
}

public static Inquery toInquery(MemberRequestDto.InqueryDto request){
return Inquery.builder()
.title(request.getTitle())
.body(request.getBody())
.receiveEmail(request.getEmail())
.inqueryImageList(new ArrayList<>())
.build();
}

public static MemberResponseDto.InqueryPreviewDto toInqueryPreviewDto(Inquery inquery){
return MemberResponseDto.InqueryPreviewDto.builder()
.id(inquery.getId())
.title(inquery.getTitle())
.createdAt(TimeConverter.ConvertTime(inquery.getCreatedAt()))
.build();
}

public static MemberResponseDto.InqueryListDto toInqueryListDto(Page<Inquery> inqueryPage){

List<MemberResponseDto.InqueryPreviewDto> inqueryPreviewDtoList = inqueryPage.getContent().stream()
.map(MemberConverter::toInqueryPreviewDto).collect(Collectors.toList());

return MemberResponseDto.InqueryListDto.builder()
.inqueryList(inqueryPreviewDtoList)
.isFirst(inqueryPage.isFirst())
.isLast(inqueryPage.isLast())
.currentPageElements(inqueryPage.getNumberOfElements())
.totalElements(inqueryPage.getTotalElements())
.totalPage(inqueryPage.getTotalPages())

public static Deregister toDeregister(String phoneNum, MemberRequestDto.DeregisterDto request) {
return Deregister.builder()
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/zipdabang/server/domain/member/Inquery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package zipdabang.server.domain.member;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import zipdabang.server.domain.common.BaseEntity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@DynamicInsert
@DynamicUpdate
@Entity
public class Inquery extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String receiveEmail;

@Column(nullable = false,length = 20)
private String title;

@Column(nullable = false,length = 500)
private String body;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@OneToMany(mappedBy = "inquery", cascade = CascadeType.ALL)
private List<InqueryImage> inqueryImageList = new ArrayList<>();

public void setMember(Member member){
if(this.member != null)
member.getInqueryList().remove(this);
this.member = member;
member.getInqueryList().add(this);
}
}
34 changes: 34 additions & 0 deletions src/main/java/zipdabang/server/domain/member/InqueryImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package zipdabang.server.domain.member;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@DynamicInsert
@DynamicUpdate
@Entity
public class InqueryImage {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String imageUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inquery_id")
private Inquery inquery;

public void setInquery(Inquery inquery){
if (this.inquery != null)
inquery.getInqueryImageList().remove(this);
this.inquery = inquery;
inquery.getInqueryImageList().add(this);
}
}
3 changes: 3 additions & 0 deletions src/main/java/zipdabang/server/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<FcmToken> fcmTokenList;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Inquery> inqueryList;


public void setProfileUrl(String profileUrl) {
this.profileUrl = profileUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package zipdabang.server.repository.memberRepositories;

import org.springframework.data.jpa.repository.JpaRepository;
import zipdabang.server.domain.member.InqueryImage;

public interface InqueryImageRepository extends JpaRepository<InqueryImage, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package zipdabang.server.repository.memberRepositories;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import zipdabang.server.domain.member.Inquery;
import zipdabang.server.domain.member.Member;

public interface InqueryRepository extends JpaRepository<Inquery, Long> {

Page<Inquery> findByMember(Member member, PageRequest pageRequest);
}
9 changes: 8 additions & 1 deletion src/main/java/zipdabang/server/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package zipdabang.server.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import zipdabang.server.domain.Category;
import zipdabang.server.domain.member.Inquery;
import zipdabang.server.domain.enums.DeregisterType;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.member.Terms;
Expand Down Expand Up @@ -40,9 +43,13 @@ public interface MemberService {

String tempLoginService();


Inquery createInquery(Member member, MemberRequestDto.InqueryDto request);

Page<Inquery> findInquery(Member member, Integer page);
public void memberDeregister(Member member, MemberRequestDto.DeregisterDto request);
public Long saveDeregisterInfo(String phoneNum, MemberRequestDto.DeregisterDto request);
public void inactivateMember(Member member);

public void saveDeregisterReasons(Long deregisterId, List<DeregisterType> deregisterTypeList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -25,6 +29,10 @@
import zipdabang.server.repository.TermsRepository;
import zipdabang.server.redis.service.RedisService;
import zipdabang.server.repository.CategoryRepository;
import zipdabang.server.repository.memberRepositories.FcmTokenRepository;
import zipdabang.server.repository.memberRepositories.InqueryRepository;
import zipdabang.server.repository.memberRepositories.MemberRepository;
import zipdabang.server.repository.memberRepositories.PreferCategoryRepository;
import zipdabang.server.repository.memberRepositories.*;
import zipdabang.server.service.MemberService;
import zipdabang.server.utils.dto.OAuthJoin;
Expand Down Expand Up @@ -60,10 +68,15 @@ public class MemberServiceImpl implements MemberService {
private final RedisService redisService;

private final FcmTokenRepository fcmTokenRepository;

private final InqueryRepository inqueryRepository;
private final AmazonS3Manager s3Manager;
private final DeregisterRepository deregisterRepository;
private final DeregisterReasonRepository deregisterReasonRepository;

@Value("${paging.size}")
private Integer pageSize;

@Override
@Transactional
public OAuthResult.OAuthResultDto SocialLogin(MemberRequestDto.OAuthRequestDto request,String type) {
Expand Down Expand Up @@ -192,6 +205,29 @@ public String tempLoginService() {
return tokenProvider.createTempAccessToken(Arrays.asList(new SimpleGrantedAuthority("GUEST")));
}

@Override
@Transactional
public Inquery createInquery(Member member, MemberRequestDto.InqueryDto request) {
Inquery inquery = MemberConverter.toInquery(request);
List<InqueryImage> inqueryImageList = null;
if(request.getImageList() != null)
if(request.getImageList().size() > 0) {
inqueryImageList = MemberConverter.toInqueryImage(request.getImageList());
inqueryImageList.forEach(inqueryImage -> inqueryImage.setInquery(inquery));
}
inquery.setMember(member);
return inqueryRepository.save(inquery);
}

@Override
public Page<Inquery> findInquery(Member member, Integer page) {
page -= 1;
Page<Inquery> inqueries = inqueryRepository.findByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")));
if(inqueries.getTotalPages() <= page)
throw new MemberException(Code.OVER_PAGE_INDEX_ERROR);
return inqueries;
}

@Override
@Transactional(readOnly = false)
public OAuthJoin.OAuthJoinDto joinInfoComplete(MemberRequestDto.MemberInfoDto request, String type){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@RequiredArgsConstructor
public class TimeConverter {

public String ConvertTime(LocalDateTime time) {
public static String ConvertTime(LocalDateTime time) {
LocalDateTime currentTime = LocalDateTime.now();

String result = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package zipdabang.server.validation.annotation;

import zipdabang.server.validation.validator.CheckPageValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = CheckPageValidator.class)
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface CheckPage {
String message() default "해당하는 페이지가 존재하지 않습니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Loading
Loading