Skip to content

Commit

Permalink
Merge pull request #18 from jwpark1211/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jwpark1211 authored May 16, 2024
2 parents 42a7bf1 + 719b20c commit ae92ba3
Show file tree
Hide file tree
Showing 21 changed files with 544 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -33,14 +36,16 @@ public ResponseEntity<? extends BasicResponse> saveBookState(
bookStateService.saveState(request)));
}

@Operation(summary = "isbn으로 책 상태 리스트 가져오기")
@Operation(summary = "isbn으로 책 상태 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/isbn/{isbn}")
public ResponseEntity<? extends BasicResponse> getStateByISBN(
@PathVariable("isbn") String isbn
@PathVariable("isbn") String isbn,
@PageableDefault(sort = "id", size=10) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<List<InfoResponse>>(
bookStateService.findStateByISBN(isbn)));
.body(new ResponseCounter<Page<InfoResponse>>(
bookStateService.findStateByISBN(isbn, pageable)));
}

@Operation(summary = "stateId로 책 상태 가져오기")
Expand All @@ -53,14 +58,16 @@ public ResponseEntity<? extends BasicResponse> getStateById(
bookStateService.findStateByStateId(stateId)));
}

@Operation(summary = "memberId로 책 상태 리스트 가져오기")
@Operation(summary = "memberId로 책 상태 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/member/{member-id}")
public ResponseEntity<? extends BasicResponse> getStateByMemberId(
@PathVariable("member-id") Long memberId
@PathVariable("member-id") Long memberId,
@PageableDefault(sort = "id", size=10) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<List<InfoResponse>>(
bookStateService.findStateByMemberId(memberId)));
.body(new ResponseCounter<Page<InfoResponse>>(
bookStateService.findStateByMemberId(memberId,pageable)));
}

@Operation(summary = "state 정보 수정")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package capstone.bookitty.domain.controller;

import capstone.bookitty.domain.dto.ResponseType.BasicResponse;
import capstone.bookitty.domain.dto.ResponseType.ResponseCounter;
import capstone.bookitty.domain.dto.ResponseType.ResponseString;
import capstone.bookitty.domain.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static capstone.bookitty.domain.dto.CommentDTO.*;

@Tag(name="코멘트", description = "코멘트 관리 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/comment")
public class CommentController {

private final CommentService commentService;

@Operation(summary = "코멘트 생성")
@PostMapping(path = "/new")
public ResponseEntity<? extends BasicResponse> saveComment(
@RequestBody @Valid SaveRequest request
){
return ResponseEntity.ok()
.body(new ResponseCounter<IdResponse>(
commentService.saveComment(request)));
}

@Operation(summary = "commentId로 코멘트 가져오기")
@GetMapping(path="/{comment-id}")
public ResponseEntity<? extends BasicResponse> getCommentById(
@PathVariable("comment-id") Long commentId
){
return ResponseEntity.ok()
.body(new ResponseCounter<InfoResponse>(
commentService.findCommentByCommentId(commentId)));
}

@Operation(summary = "전체 코멘트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/all")
public ResponseEntity<? extends BasicResponse> getAll(
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<Page<InfoResponse>>(
commentService.findAllComment(pageable)));
}

@Operation(summary = "isbn으로 코멘트 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/isbn/{isbn}")
public ResponseEntity<? extends BasicResponse> getCommentByISBN(
@PathVariable("isbn") String isbn,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<Page<InfoResponse>>(
commentService.findCommentByIsbn(isbn, pageable)));
}

@Operation(summary = "memberId로 코멘트 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/member/{member-id}")
public ResponseEntity<? extends BasicResponse> getCommentByMemberId(
@PathVariable("member-id") Long memberId,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<Page<InfoResponse>>(
commentService.findCommentByMemberId(memberId, pageable)));
}

@Operation(summary = "코멘트 수정")
@PatchMapping(path = "/{comment-id}")
public ResponseEntity<? extends BasicResponse> updateComment(
@PathVariable("comment-id") Long commentId,
@RequestBody @Valid UpdateRequest request
){
commentService.updateComment(commentId, request);
return ResponseEntity.ok()
.body(new ResponseString("update Comment!"));
}

@Operation(summary = "코멘트 삭제")
@DeleteMapping(path = "/{comment-id}")
public ResponseEntity<? extends BasicResponse> deleteComment(
@PathVariable("comment-id") Long commentId
){
commentService.deleteComment(commentId);
return ResponseEntity.ok()
.body(new ResponseString("delete Comment!"));
}

@Operation(summary = "코멘트 좋아요 등록")
@PostMapping(path = "/{comment-id}/member/{member-id}/like/increase")
public ResponseEntity<? extends BasicResponse> increaseLike(
@PathVariable("comment-id") Long commentId,
@PathVariable("member-id") Long memberId
){
commentService.increaseLike(commentId,memberId);
return ResponseEntity.ok()
.body(new ResponseString("increase Like!"));
}

@Operation(summary = "코멘트 좋아요 삭제")
@PostMapping(path = "/{comment-id}/member/{member-id}/like/decrease")
public ResponseEntity<? extends BasicResponse> decreaseLike(
@PathVariable("comment-id") Long commentId,
@PathVariable("member-id") Long memberId
){
commentService.decreaseLike(commentId,memberId);
return ResponseEntity.ok()
.body(new ResponseString("decrease Like!"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static capstone.bookitty.domain.dto.MemberDTO.*;

@Tag(name = "회원", description = "회원 관련 api 입니다.")
Expand Down Expand Up @@ -68,12 +69,15 @@ public ResponseEntity<? extends BasicResponse> findOneMember(
memberService.getMemberInfoWithId(memberId)));
}

@Operation(summary = "전체 회원 조회")
@Operation(summary = "전체 회원 조회 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/all")
public ResponseEntity<? extends BasicResponse> findAllMembers(){
public ResponseEntity<? extends BasicResponse> findAllMembers(
@PageableDefault(sort="id",size = 10) Pageable pageable
){
return ResponseEntity.ok(
new ResponseCounter<List<InfoResponse>>(
memberService.getAllMemberInfo()));
new ResponseCounter<Page<InfoResponse>>(
memberService.getAllMemberInfo(pageable)));
}

/* TODO : S3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public Mono<AladinBestSellerResponseDTO> getBestSeller(){
}


@Operation(summary = "카테고리별 베스트셀러 Top 10\n CategoryId: " +
"(170 : 경제경영 / 987 : 과학 / 1 : 문학 / 656 : 인문 / 336 : 자기계발")
@Operation(summary = "카테고리별 베스트셀러 Top 10\n / CategoryId: " +
"(170 : 경제경영 / 987 : 과학 / 1 : 문학 / 656 : 인문 / 336 : 자기계발)")
@GetMapping(path = "/bestseller/category/{category-id}")
public Mono<AladinBestSellerResponseDTO> getBestSellerByGenre(
@PathVariable("category-id") int cid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static capstone.bookitty.domain.dto.StarDTO.*;

@Tag(name="평점", description = "평점 관리 api 입니다.")
Expand Down Expand Up @@ -43,26 +45,40 @@ public ResponseEntity<? extends BasicResponse> getStarById(
starService.findStarByStarId(starId)));
}

//TODO: PAGING
@Operation(summary = "isbn으로 평점 리스트 가져오기")

@Operation(summary = "전체 평점 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/all")
public ResponseEntity<? extends BasicResponse> getAllStar(
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<Page<InfoResponse>>(
starService.findAllStar(pageable)));
}

@Operation(summary = "isbn으로 평점 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/isbn/{isbn}")
public ResponseEntity<? extends BasicResponse> getStarByISBN(
@PathVariable("isbn") String isbn
@PathVariable("isbn") String isbn,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<List<InfoResponse>>(
starService.findStarByISBN(isbn)));
.body(new ResponseCounter<Page<InfoResponse>>(
starService.findStarByISBN(isbn,pageable)));
}

//TODO: PAGING
@Operation(summary = "member id로 평점 리스트 가져오기")
@Operation(summary = "member id로 평점 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)")
@GetMapping(path = "/member/{member-id}")
public ResponseEntity<? extends BasicResponse> getStarByMemberId(
@PathVariable("member-id") Long memberId
@PathVariable("member-id") Long memberId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
){
return ResponseEntity.ok()
.body(new ResponseCounter<List<InfoResponse>>(
starService.findStarByMemberId(memberId)));
.body(new ResponseCounter<Page<InfoResponse>>(
starService.findStarByMemberId(memberId,pageable)));
}

@Operation(summary = "평점 수정")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import capstone.bookitty.domain.entity.BookState;
import capstone.bookitty.domain.entity.State;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/capstone/bookitty/domain/dto/CommentDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package capstone.bookitty.domain.dto;

import capstone.bookitty.domain.entity.Comment;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

public class CommentDTO {

@Data
public static class SaveRequest{
@NotBlank(message = "Isbn is a required entry value.")
private String isbn;
@NotNull(message = "memberId is a required entry value.")
private Long memberId;
@NotEmpty(message = "content is a required entry value.")
@Size(min = 1, max = 100, message = "Name must be between 1 and 100 characters")
private String content;
}

@Data
public static class UpdateRequest{
@NotEmpty(message = "content is a required entry value.")
@Size(min = 1, max = 100, message = "Name must be between 1 and 100 characters")
private String content;
}

@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class IdResponse{
private Long id;
public static IdResponse of(Comment comment){
return new IdResponse(comment.getId());
}
}

@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class InfoResponse{
private Long id;
private Long memberId;
private String isbn;
private String content;
private int like_count;
@DateTimeFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
@DateTimeFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss")
private LocalDateTime modifiedAt;

public static InfoResponse of(Comment comment, int like_count){
return new InfoResponse(comment.getId(), comment.getMember().getId(),comment.getIsbn(),
comment.getContent(), like_count ,comment.getCreatedAt(),
comment.getModifiedAt());
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package capstone.bookitty.domain.dto.ResponseType;

import org.springframework.data.domain.Page;

import lombok.Getter;
import lombok.Setter;

Expand All @@ -13,7 +15,10 @@ public class ResponseCounter<T> extends BasicResponse {

public ResponseCounter(T data) {
this.data = data;
if (data instanceof List) {
if (data instanceof Page) {
this.count = (int) ((Page<?>) data).getTotalElements();
}
else if (data instanceof List) {
this.count = ((List<?>) data).size();
} else {
this.count = 1;
Expand Down
Loading

0 comments on commit ae92ba3

Please sign in to comment.