From bcb62961c4c19652e8107b3a3d7f7260fb12d3d4 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Wed, 27 Sep 2023 13:54:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20Feat=20:=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EB=AC=B8=EC=9D=98=20=EB=B0=8F=20=EC=8B=A0=EA=B3=A0=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/aws/s3/AmazonS3Manager.java | 2 + .../zipdabang/server/config/AmazonConfig.java | 3 ++ .../server/converter/MemberConverter.java | 54 +++++++++++++++++-- .../server/domain/member/Inquery.java | 46 ++++++++++++++++ .../server/domain/member/InqueryImage.java | 34 ++++++++++++ .../server/domain/member/Member.java | 3 ++ .../InqueryImageRepository.java | 7 +++ .../memberRepositories/InqueryRepository.java | 7 +++ .../server/service/MemberService.java | 3 ++ .../serviceImpl/MemberServiceImpl.java | 17 ++++++ .../web/controller/MemberRestController.java | 14 +++++ .../web/dto/requestDto/MemberRequestDto.java | 17 ++++++ .../dto/responseDto/MemberResponseDto.java | 8 +++ src/main/resources/application.yml | 9 ++-- 14 files changed, 217 insertions(+), 7 deletions(-) create mode 100644 src/main/java/zipdabang/server/domain/member/Inquery.java create mode 100644 src/main/java/zipdabang/server/domain/member/InqueryImage.java create mode 100644 src/main/java/zipdabang/server/repository/memberRepositories/InqueryImageRepository.java create mode 100644 src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java diff --git a/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java b/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java index a335062..3527078 100644 --- a/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java +++ b/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java @@ -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; diff --git a/src/main/java/zipdabang/server/config/AmazonConfig.java b/src/main/java/zipdabang/server/config/AmazonConfig.java index 259c6f3..55d7990 100644 --- a/src/main/java/zipdabang/server/config/AmazonConfig.java +++ b/src/main/java/zipdabang/server/config/AmazonConfig.java @@ -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; diff --git a/src/main/java/zipdabang/server/converter/MemberConverter.java b/src/main/java/zipdabang/server/converter/MemberConverter.java index 31a947a..8cdd336 100644 --- a/src/main/java/zipdabang/server/converter/MemberConverter.java +++ b/src/main/java/zipdabang/server/converter/MemberConverter.java @@ -3,26 +3,29 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; 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.member.Terms; -import zipdabang.server.domain.member.Member; -import zipdabang.server.domain.member.MemberPreferCategory; +import zipdabang.server.domain.etc.Uuid; +import zipdabang.server.domain.member.*; import zipdabang.server.repository.memberRepositories.MemberRepository; 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 @@ -33,8 +36,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; @@ -104,6 +111,7 @@ public static MemberResponseDto.SocialJoinDto toSocialJoinDto(OAuthJoin.OAuthJoi @PostConstruct public void init() { this.staticMemberRepository = this.memberRepository; + this.staticAmazonS3Manager = amazonS3Manager; } @@ -232,4 +240,44 @@ public static MemberResponseDto.TempLoginDto toTempLoginDto(String token){ .accessToken(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 toInqueryImage(List imageList) + { + List 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(); + } + } diff --git a/src/main/java/zipdabang/server/domain/member/Inquery.java b/src/main/java/zipdabang/server/domain/member/Inquery.java new file mode 100644 index 0000000..70af190 --- /dev/null +++ b/src/main/java/zipdabang/server/domain/member/Inquery.java @@ -0,0 +1,46 @@ +package zipdabang.server.domain.member; + +import lombok.*; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +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 { + + @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 inqueryImageList = new ArrayList<>(); + + public void setMember(Member member){ + if(this.member != null) + member.getInqueryList().remove(this); + this.member = member; + member.getInqueryList().add(this); + } +} diff --git a/src/main/java/zipdabang/server/domain/member/InqueryImage.java b/src/main/java/zipdabang/server/domain/member/InqueryImage.java new file mode 100644 index 0000000..746b527 --- /dev/null +++ b/src/main/java/zipdabang/server/domain/member/InqueryImage.java @@ -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); + } +} diff --git a/src/main/java/zipdabang/server/domain/member/Member.java b/src/main/java/zipdabang/server/domain/member/Member.java index 6394617..025e17e 100644 --- a/src/main/java/zipdabang/server/domain/member/Member.java +++ b/src/main/java/zipdabang/server/domain/member/Member.java @@ -104,6 +104,9 @@ public class Member extends BaseEntity { @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) private List fcmTokenList; + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + private List inqueryList; + public void setProfileUrl(String profileUrl) { this.profileUrl = profileUrl; diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/InqueryImageRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryImageRepository.java new file mode 100644 index 0000000..11c455f --- /dev/null +++ b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryImageRepository.java @@ -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 { +} diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java new file mode 100644 index 0000000..200bf99 --- /dev/null +++ b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java @@ -0,0 +1,7 @@ +package zipdabang.server.repository.memberRepositories; + +import org.springframework.data.jpa.repository.JpaRepository; +import zipdabang.server.domain.member.Inquery; + +public interface InqueryRepository extends JpaRepository { +} diff --git a/src/main/java/zipdabang/server/service/MemberService.java b/src/main/java/zipdabang/server/service/MemberService.java index 408a3f5..33239b8 100644 --- a/src/main/java/zipdabang/server/service/MemberService.java +++ b/src/main/java/zipdabang/server/service/MemberService.java @@ -1,6 +1,7 @@ package zipdabang.server.service; import zipdabang.server.domain.Category; +import zipdabang.server.domain.member.Inquery; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.member.Terms; import zipdabang.server.redis.domain.RefreshToken; @@ -38,4 +39,6 @@ public interface MemberService { List getAllTerms(); String tempLoginService(); + + Inquery createInquery(Member member, MemberRequestDto.InqueryDto request); } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java index 13d3162..51ca57e 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java @@ -25,6 +25,7 @@ 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.service.MemberService; @@ -61,6 +62,8 @@ public class MemberServiceImpl implements MemberService { private final RedisService redisService; private final FcmTokenRepository fcmTokenRepository; + + private final InqueryRepository inqueryRepository; private final AmazonS3Manager s3Manager; @Override @@ -191,6 +194,20 @@ 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 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 @Transactional(readOnly = false) public OAuthJoin.OAuthJoinDto joinInfoComplete(MemberRequestDto.MemberInfoDto request, String type){ diff --git a/src/main/java/zipdabang/server/web/controller/MemberRestController.java b/src/main/java/zipdabang/server/web/controller/MemberRestController.java index da5c61f..1405095 100644 --- a/src/main/java/zipdabang/server/web/controller/MemberRestController.java +++ b/src/main/java/zipdabang/server/web/controller/MemberRestController.java @@ -1,6 +1,7 @@ package zipdabang.server.web.controller; import com.fasterxml.jackson.core.JsonProcessingException; +import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -25,12 +26,14 @@ import zipdabang.server.converter.MemberConverter; import zipdabang.server.converter.RootConverter; import zipdabang.server.domain.Category; +import zipdabang.server.domain.member.Inquery; import zipdabang.server.domain.member.Member; import zipdabang.server.redis.domain.RefreshToken; import zipdabang.server.redis.service.RedisService; import zipdabang.server.service.MemberService; import zipdabang.server.sms.service.SmsService; import zipdabang.server.utils.dto.OAuthJoin; +import zipdabang.server.validation.annotation.CheckTempMember; import zipdabang.server.web.dto.requestDto.MemberRequestDto; import zipdabang.server.web.dto.responseDto.MemberResponseDto; @@ -39,6 +42,7 @@ import zipdabang.server.utils.dto.OAuthResult; import zipdabang.server.web.dto.responseDto.RootResponseDto; +import javax.validation.Valid; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; @@ -336,4 +340,14 @@ public ResponseDto showTerms() { public ResponseDto tempLogin(){ return ResponseDto.of(MemberConverter.toTempLoginDto(memberService.tempLoginService())); } + + @Operation(summary = "🎪figma[더보기 - 오류 신고 및 신고하기] 오류 신고하기 API", description = "오류 신고하기 API 입니다.") + @Parameters({ + @Parameter(name = "member", hidden = true), + }) + @PostMapping(value = "/members/inquery",consumes ={ MediaType.MULTIPART_FORM_DATA_VALUE } ) + public ResponseDto createInquery(@CheckTempMember @AuthMember Member member, @ModelAttribute @Valid MemberRequestDto.InqueryDto request){ + Inquery inquery = memberService.createInquery(member, request); + return ResponseDto.of(MemberConverter.toMemberInqueryResultDto(inquery)); + } } diff --git a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java index f7ed4b7..8b15759 100644 --- a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java +++ b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java @@ -3,8 +3,10 @@ import lombok.Setter; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.web.multipart.MultipartFile; import zipdabang.server.web.dto.responseDto.MemberResponseDto; @@ -148,5 +150,20 @@ public static class IssueTokenDto{ String refreshToken; } + @Getter @Setter + public static class InqueryDto{ + + @NotBlank + String email; + + @NotBlank @Size(max = 20) + String title; + + @NotBlank @Size(max = 500) + String body; + + @Nullable + List imageList; + } } diff --git a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java index 622da69..21ec875 100644 --- a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java +++ b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java @@ -154,4 +154,12 @@ public static class MemberPreferCategoryDto{ } + @Builder + @Getter + @AllArgsConstructor(access = AccessLevel.PROTECTED) + @NoArgsConstructor(access = AccessLevel.PROTECTED) + public static class MemberInqueryResultDto{ + private Long id; + private LocalDateTime created_at; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 00bb558..9c063a3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,11 +12,11 @@ spring: enabled: always ## # local redis -# redis: -# host: localhost - redis: - host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com + host: localhost + +# redis: +# host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com batch: jdbc: initialize-schema: always @@ -62,6 +62,7 @@ cloud: zipdabang-recipe-thumbNail: recipe/thumbnail zipdabang-recipe-steps : recipe/steps zipdabang-proifile : user + zipdabang-inquery : inquery # zipdabang-facilities : facilities user-default-image: ${USER_DEFAULT_IMAGE} region: From 49edf7ad8d357edf6cc2178038575de9c2bccb98 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Wed, 27 Sep 2023 15:09:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:sparkles:=20Feat=20:=20=EB=82=B4=EA=B0=80?= =?UTF-8?q?=20=EC=A0=81=EC=9D=80=20=EC=98=A4=EB=A5=98=20=EB=AC=B8=EC=9D=98?= =?UTF-8?q?=20=EB=AA=A8=EC=95=84=EB=B3=B4=EA=B8=B0=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/converter/MemberConverter.java | 24 +++++++++++++++ .../server/domain/member/Inquery.java | 3 +- .../memberRepositories/InqueryRepository.java | 5 ++++ .../server/service/MemberService.java | 4 +++ .../serviceImpl/MemberServiceImpl.java | 16 ++++++++++ .../server/utils/converter/TimeConverter.java | 2 +- .../validation/annotation/CheckPage.java | 17 +++++++++++ .../validator/CheckPageValidator.java | 29 +++++++++++++++++++ .../web/controller/MemberRestController.java | 23 +++++++++++++-- .../dto/responseDto/MemberResponseDto.java | 23 +++++++++++++++ 10 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/main/java/zipdabang/server/validation/annotation/CheckPage.java create mode 100644 src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java diff --git a/src/main/java/zipdabang/server/converter/MemberConverter.java b/src/main/java/zipdabang/server/converter/MemberConverter.java index 8cdd336..b04776e 100644 --- a/src/main/java/zipdabang/server/converter/MemberConverter.java +++ b/src/main/java/zipdabang/server/converter/MemberConverter.java @@ -2,6 +2,7 @@ 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; @@ -13,6 +14,7 @@ import zipdabang.server.domain.etc.Uuid; import zipdabang.server.domain.member.*; 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; @@ -280,4 +282,26 @@ public static Inquery toInquery(MemberRequestDto.InqueryDto request){ .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 inqueryPage){ + + List 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()) + .build(); + } } diff --git a/src/main/java/zipdabang/server/domain/member/Inquery.java b/src/main/java/zipdabang/server/domain/member/Inquery.java index 70af190..4fe4390 100644 --- a/src/main/java/zipdabang/server/domain/member/Inquery.java +++ b/src/main/java/zipdabang/server/domain/member/Inquery.java @@ -3,6 +3,7 @@ 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; @@ -15,7 +16,7 @@ @DynamicInsert @DynamicUpdate @Entity -public class Inquery { +public class Inquery extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java index 200bf99..4f88795 100644 --- a/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java +++ b/src/main/java/zipdabang/server/repository/memberRepositories/InqueryRepository.java @@ -1,7 +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 { + + Page findByMember(Member member, PageRequest pageRequest); } diff --git a/src/main/java/zipdabang/server/service/MemberService.java b/src/main/java/zipdabang/server/service/MemberService.java index 33239b8..65a02a0 100644 --- a/src/main/java/zipdabang/server/service/MemberService.java +++ b/src/main/java/zipdabang/server/service/MemberService.java @@ -1,5 +1,7 @@ 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.member.Member; @@ -41,4 +43,6 @@ public interface MemberService { String tempLoginService(); Inquery createInquery(Member member, MemberRequestDto.InqueryDto request); + + Page findInquery(Member member, Integer page); } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java index 51ca57e..614b739 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java @@ -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; @@ -66,6 +70,9 @@ public class MemberServiceImpl implements MemberService { private final InqueryRepository inqueryRepository; private final AmazonS3Manager s3Manager; + @Value("${paging.size}") + private Integer pageSize; + @Override @Transactional public OAuthResult.OAuthResultDto SocialLogin(MemberRequestDto.OAuthRequestDto request,String type) { @@ -208,6 +215,15 @@ public Inquery createInquery(Member member, MemberRequestDto.InqueryDto request) return inqueryRepository.save(inquery); } + @Override + public Page findInquery(Member member, Integer page) { + page -= 1; + Page 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){ diff --git a/src/main/java/zipdabang/server/utils/converter/TimeConverter.java b/src/main/java/zipdabang/server/utils/converter/TimeConverter.java index fa6571d..71bbc10 100644 --- a/src/main/java/zipdabang/server/utils/converter/TimeConverter.java +++ b/src/main/java/zipdabang/server/utils/converter/TimeConverter.java @@ -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; diff --git a/src/main/java/zipdabang/server/validation/annotation/CheckPage.java b/src/main/java/zipdabang/server/validation/annotation/CheckPage.java new file mode 100644 index 0000000..05b1b60 --- /dev/null +++ b/src/main/java/zipdabang/server/validation/annotation/CheckPage.java @@ -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[] payload() default {}; +} diff --git a/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java b/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java new file mode 100644 index 0000000..0fe8b86 --- /dev/null +++ b/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java @@ -0,0 +1,29 @@ +package zipdabang.server.validation.validator; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import zipdabang.server.base.Code; +import zipdabang.server.domain.member.Member; +import zipdabang.server.validation.annotation.CheckPage; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +@Component +@RequiredArgsConstructor +public class CheckPageValidator implements ConstraintValidator { + @Override + public void initialize(CheckPage constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + if(value < 1 || value == null) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(Code.UNDER_PAGE_INDEX_ERROR.toString()).addConstraintViolation(); + return false; + } + return true; + } +} diff --git a/src/main/java/zipdabang/server/web/controller/MemberRestController.java b/src/main/java/zipdabang/server/web/controller/MemberRestController.java index 1405095..020a826 100644 --- a/src/main/java/zipdabang/server/web/controller/MemberRestController.java +++ b/src/main/java/zipdabang/server/web/controller/MemberRestController.java @@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PatchMapping; @@ -33,6 +34,7 @@ import zipdabang.server.service.MemberService; import zipdabang.server.sms.service.SmsService; import zipdabang.server.utils.dto.OAuthJoin; +import zipdabang.server.validation.annotation.CheckPage; import zipdabang.server.validation.annotation.CheckTempMember; import zipdabang.server.web.dto.requestDto.MemberRequestDto; import zipdabang.server.web.dto.responseDto.MemberResponseDto; @@ -341,13 +343,30 @@ public ResponseDto tempLogin(){ return ResponseDto.of(MemberConverter.toTempLoginDto(memberService.tempLoginService())); } - @Operation(summary = "🎪figma[더보기 - 오류 신고 및 신고하기] 오류 신고하기 API", description = "오류 신고하기 API 입니다.") + @Operation(summary = "🎪figma[더보기 - 오류 신고 및 신고하기] 오류 신고하기 API ✔️🔑", description = "오류 신고하기 API 입니다.") @Parameters({ @Parameter(name = "member", hidden = true), }) - @PostMapping(value = "/members/inquery",consumes ={ MediaType.MULTIPART_FORM_DATA_VALUE } ) + @PostMapping(value = "/members/inquiries",consumes ={ MediaType.MULTIPART_FORM_DATA_VALUE } ) public ResponseDto createInquery(@CheckTempMember @AuthMember Member member, @ModelAttribute @Valid MemberRequestDto.InqueryDto request){ Inquery inquery = memberService.createInquery(member, request); return ResponseDto.of(MemberConverter.toMemberInqueryResultDto(inquery)); } + + @Operation(summary = "🎪[더보기 - 오류 신고및 신고하기5] 내가 문의 한 오류 모아보기 (페이징 포함) ✔️🔑", description = "내가 신고한 오류 모아보기 입니다.") + @GetMapping("/members/inquiries") + @Parameters({ + @Parameter(name = "member", hidden = true), + @Parameter(name = "page", description = "페이지 번호, 1부터 시작") + }) + @ApiResponses({ + @ApiResponse(responseCode = "2000", description = "OK 성공, access Token과 refresh 토큰을 반환함"), + @ApiResponse(responseCode = "4054", description = "BAD_REQEUST , 페이지 번호가 없거나 0 이하", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "4055", description = "BAD_REQEUST , 페이지 번호가 초과함", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + + }) + public ResponseDto showInquery(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page",required = true) @CheckPage Integer page){ + Page inqueryPage = memberService.findInquery(member, page); + return ResponseDto.of(MemberConverter.toInqueryListDto(inqueryPage)); + } } diff --git a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java index 21ec875..5090f60 100644 --- a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java +++ b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java @@ -162,4 +162,27 @@ public static class MemberInqueryResultDto{ private Long id; private LocalDateTime created_at; } + + @Builder + @Getter + @AllArgsConstructor(access = AccessLevel.PROTECTED) + @NoArgsConstructor(access = AccessLevel.PROTECTED) + public static class InqueryPreviewDto{ + Long id; + String title; + String createdAt; + } + + @Builder + @Getter + @AllArgsConstructor(access = AccessLevel.PROTECTED) + @NoArgsConstructor(access = AccessLevel.PROTECTED) + public static class InqueryListDto{ + List inqueryList; + Long totalElements; + Integer currentPageElements; + Integer totalPage; + Boolean isFirst; + Boolean isLast; + } }