Skip to content

Commit

Permalink
✨ Feat : 내가 적은 오류 문의 모아보기 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
CYY1007 committed Sep 27, 2023
1 parent bcb6296 commit 49edf7a
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/main/java/zipdabang/server/converter/MemberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<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())
.build();
}
}
3 changes: 2 additions & 1 deletion src/main/java/zipdabang/server/domain/member/Inquery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@
@DynamicInsert
@DynamicUpdate
@Entity
public class Inquery {
public class Inquery extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Inquery, Long> {

Page<Inquery> findByMember(Member member, PageRequest pageRequest);
}
4 changes: 4 additions & 0 deletions src/main/java/zipdabang/server/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,4 +43,6 @@ public interface MemberService {
String tempLoginService();

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

Page<Inquery> findInquery(Member member, Integer page);
}
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 Down Expand Up @@ -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) {
Expand Down Expand Up @@ -208,6 +215,15 @@ public Inquery createInquery(Member member, MemberRequestDto.InqueryDto request)
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 {};
}
Original file line number Diff line number Diff line change
@@ -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<CheckPage, Integer> {
@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -341,13 +343,30 @@ public ResponseDto<MemberResponseDto.TempLoginDto> 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<MemberResponseDto.MemberInqueryResultDto> 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<MemberResponseDto.InqueryListDto> showInquery(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page",required = true) @CheckPage Integer page){
Page<Inquery> inqueryPage = memberService.findInquery(member, page);
return ResponseDto.of(MemberConverter.toInqueryListDto(inqueryPage));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InqueryPreviewDto> inqueryList;
Long totalElements;
Integer currentPageElements;
Integer totalPage;
Boolean isFirst;
Boolean isLast;
}
}

0 comments on commit 49edf7a

Please sign in to comment.