Skip to content

Commit

Permalink
feature : Post 객체 구현 및 관련 기능 구현 완료 #188
Browse files Browse the repository at this point in the history
feature : Post 객체 구현 및 관련 기능 구현 완료
  • Loading branch information
dltjdgh0428 authored May 6, 2024
2 parents 19b6e89 + 9f0072b commit b130588
Show file tree
Hide file tree
Showing 28 changed files with 485 additions and 70 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/book_everywhere/common/dto/CountDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.book_everywhere.common.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
public class CountDto<T> {
private List<T> data;
private int count;

public CountDto(List<T> data) {
this.data = data;
this.count = data.size();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.book_everywhere.domain.book.service;

import com.book_everywhere.domain.book.entity.Book;
import com.book_everywhere.domain.book.repository.BookRepository;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import com.book_everywhere.domain.book.dto.BookDto;
import com.book_everywhere.domain.book.dto.BookRespDto;
import com.book_everywhere.domain.book.entity.Book;
import com.book_everywhere.domain.book.repository.BookRepository;
import com.book_everywhere.domain.review.dto.ReviewRespDto;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class DataService {
Visit visit = visitRepository.mFindByUserAndPin(review.getUser().getId(), review.getPin().getId());
PinRespDto pinRespDto = new PinRespDto(
pin.getTitle(),
pin.getPhone(),
pin.getPlaceId(),
pin.getLatitude(),
pin.getLongitude(),
Expand Down Expand Up @@ -100,6 +101,7 @@ public class DataService {
Visit visit = visitRepository.mFindByUserAndPin(review.getUser().getId(), review.getPin().getId());
PinRespDto pinRespDto = new PinRespDto(
pin.getTitle(),
pin.getPhone(),
pin.getPlaceId(),
pin.getLatitude(),
pin.getLongitude(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.book_everywhere.common.dto.CMRespDto;
import com.book_everywhere.domain.mark.dto.BookmarkDto;
import com.book_everywhere.domain.mark.service.BookmarkService;
import com.book_everywhere.common.dto.CountDto;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -15,18 +16,22 @@
public class BookmarkController {
private final BookmarkService bookmarkService;

@Operation(summary = "유저의 모든 북마크 조회", description = "유저의 북마크 계시글을 개수와 함께 조회 return = CountDto<List<BookmarkDto>>")
@GetMapping("/api/bookmark/{socialId}")
public CMRespDto<?> findBookmarkWithUser(@PathVariable Long socialId) {
List<BookmarkDto> result = bookmarkService.유저_북마크_조회(socialId);
public CMRespDto<?> findBookmarkAndCountWithUser(@PathVariable Long socialId) {
List<BookmarkDto> bookmarkDtos = bookmarkService.유저_북마크_조회(socialId);
CountDto<?> result = new CountDto<>(bookmarkDtos); // 북마크 개수 조회
return new CMRespDto<>(HttpStatus.OK, result, "유저 북마크 조회 성공");
}

@Operation(summary = "북마크 등록", description = "새로운 북마크를 등록합니다.")
@PostMapping("/api/bookmark")
public CMRespDto<?> saveBookmark(@RequestParam Long socialId, @RequestParam String address) {
bookmarkService.북마크_등록(socialId, address);
return new CMRespDto<>(HttpStatus.OK, null, "유저 북마크 등록 성공");
}

@Operation(summary = "북마크 삭제", description = "북마크를 삭제합니다.")
@DeleteMapping("/api/bookmark/{bookmarkId}")
public CMRespDto<?> deleteBookmark(@PathVariable Long bookmarkId) {
bookmarkService.북마크_삭제(bookmarkId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.book_everywhere.domain.mark.dto;

import com.book_everywhere.domain.pin.dto.PinRespDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@AllArgsConstructor
public class BookmarkDto {
Long id;
Long pinId;
PinRespDto pinRespDto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.book_everywhere.domain.mark.dto.BookmarkDto;
import com.book_everywhere.domain.mark.entity.Bookmark;
import com.book_everywhere.domain.mark.repository.BookmarkRepository;
import com.book_everywhere.domain.pin.dto.PinRespDto;
import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.pin.repository.PinRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -47,10 +48,6 @@ public class BookmarkServiceImpl implements BookmarkService{
@Override
public List<BookmarkDto> 유저_북마크_조회(Long socialId) {
List<Bookmark> init = bookmarkRepository.findAllBySocialId(socialId);
return init.stream().map(bookmark ->
new BookmarkDto(
bookmark.getId(),
bookmark.getPin().getId())
).toList();
return init.stream().map(bookmark -> new BookmarkDto(bookmark.getPin().toRespDto())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
@AllArgsConstructor
public class PinRespDto {
private String name;
private String phone;
private double placeId;
private double y;
private double x;
private String address;
private boolean isPrivate;
//3월 2일 추가 공유지도
private boolean isPrivate;
private String url;

public Pin toEntity() {
return Pin.builder()
.placeId(placeId)
.title(name)
.phone(phone)
.address(address)
.longitude(x)
.latitude(y)
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/book_everywhere/domain/pin/entity/Pin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.book_everywhere.domain.pin.entity;

import com.book_everywhere.common.entity.BaseTimeEntity;
import com.book_everywhere.domain.pin.dto.PinRespDto;
import com.book_everywhere.domain.review.entity.Review;
import com.book_everywhere.domain.tag.entity.Tagged;
import jakarta.persistence.*;
Expand Down Expand Up @@ -50,4 +51,10 @@ public class Pin extends BaseTimeEntity {
@Column(nullable = false,unique = true)
private String address;

@Column
private String phone;

public PinRespDto toRespDto() {
return new PinRespDto(this.title, this.phone, this.getPlaceId(), this.getLongitude(), this.getLatitude(), this.getAddress(), false, this.getUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.book_everywhere.domain.pin.dto.PinDto;
import com.book_everywhere.domain.pin.dto.PinWithTagCountRespDto;
import com.book_everywhere.domain.post.dto.PostReqDto;
import com.book_everywhere.domain.review.dto.ReviewRespDto;

import java.util.List;

public interface PinService {
List<PinDto> 전체지도조회();

void 핀생성(ReviewRespDto reviewRespDto);
void 핀생성포스트(PostReqDto postReqDto);

void 핀생성리뷰(ReviewRespDto reviewRespDto);

List<PinWithTagCountRespDto> 핀의상위4개태그개수와함께조회();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.book_everywhere.domain.pin.service;

import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.pin.repository.PinRepository;
import com.book_everywhere.domain.tag.repository.TaggedRepository;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import com.book_everywhere.domain.pin.dto.PinDto;
import com.book_everywhere.domain.pin.dto.PinRespDto;
import com.book_everywhere.domain.pin.dto.PinWithTagCountRespDto;
import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.pin.repository.PinRepository;
import com.book_everywhere.domain.post.dto.PostReqDto;
import com.book_everywhere.domain.review.dto.ReviewRespDto;
import com.book_everywhere.domain.tag.dto.TagCountRespDto;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import com.book_everywhere.domain.tag.repository.TaggedRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -32,7 +33,17 @@ public class PinServiceImpl implements PinService {
.toList();
}
@Transactional
public void 핀생성(ReviewRespDto reviewRespDto) {
public void 핀생성포스트(PostReqDto postReqDto) {
PinRespDto pinRespDto = postReqDto.getPinRespDto();
Pin pined = pinRepository.mFindPinByAddress(postReqDto.getPinRespDto().getAddress());
if (pined == null) {
Pin pin = pinRespDto.toEntity();
pinRepository.save(pin);
}
}

@Override
public void 핀생성리뷰(ReviewRespDto reviewRespDto) {
PinRespDto pinRespDto = reviewRespDto.getPinRespDto();
Pin pined = pinRepository.mFindPinByAddress(reviewRespDto.getPinRespDto().getAddress());
if (pined == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.book_everywhere.domain.pin.service;

import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.pin.repository.PinRepository;
import com.book_everywhere.domain.pin.repository.VisitRepository;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import com.book_everywhere.domain.auth.entity.User;
import com.book_everywhere.domain.auth.repository.UserRepository;
import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.pin.entity.Visit;
import com.book_everywhere.domain.pin.repository.PinRepository;
import com.book_everywhere.domain.pin.repository.VisitRepository;
import com.book_everywhere.domain.review.dto.ReviewRespDto;
import com.book_everywhere.common.exception.customs.CustomErrorCode;
import com.book_everywhere.common.exception.customs.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.book_everywhere.domain.post.controller;

import com.book_everywhere.common.dto.CMRespDto;
import com.book_everywhere.common.dto.CountDto;
import com.book_everywhere.domain.post.facade.PostFacade;
import com.book_everywhere.domain.post.dto.PostReqDto;
import com.book_everywhere.domain.post.dto.PostRespDto;
import com.book_everywhere.domain.post.service.PostService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class PostController {

private final PostService postService;
private final PostFacade postFacade;

//전체 장소 리뷰 조회
@Operation(summary = "모든 큐레이팅 조회", description = "모든 큐레이팅 조회 return = List<PostRespDto>")
@GetMapping("/api/posts")
public CMRespDto<?> findAllPosts() {
List<PostRespDto> result = postService.모든_장소_리뷰_조회();
return new CMRespDto<>(HttpStatus.OK, result, "모든 장소 리뷰 조회 성공!");
}

//단일 장소 리뷰 조회
@Operation(summary = "단일 큐레이팅 조회", description = "단일 큐레이팅 조회 return = PostRespDto")
@GetMapping("/api/post/{postId}")
public CMRespDto<?> findPost(@PathVariable Long postId) {
PostRespDto result = postService.장소_리뷰_조회(postId);
return new CMRespDto<>(HttpStatus.OK,result,"단일 장소 리뷰 조회 성공!");
}

//유저 장소 리뷰 조회
@Operation(summary = "유저의 모든 큐레이팅 조회", description = "유저의 모든 큐레이팅을 개수와 함께 조회합니다. return = CountDto<List<PostRespDto>>")
@GetMapping("/api/user/post/{socialId}")
public CMRespDto<?> findUserPosts(@PathVariable Long socialId) {
List<PostRespDto> postRespDtos = postService.유저의_모든_장소_리뷰_조회(socialId);
CountDto<?> result = new CountDto<>(postRespDtos);
return new CMRespDto<>(HttpStatus.OK, result, "유저의 장소 리뷰 조회 성공!");
}

//유저 큐레이팅 생성 (임시)
@Operation(summary = "큐레이팅 생성", description = "새 큐레이팅을 저장합니다.")
@PostMapping("/api/post")
public CMRespDto<?> savePost(@Valid @RequestBody PostReqDto postReqDto) {
postFacade.장소_리뷰_등록(postReqDto); //#@! 이미지 관련 부분 및 태그 부분 구현이 필요합니다.
return new CMRespDto<>(HttpStatus.OK, null, "큐레이팅 저장 성공!");
}

//해당 장소의 모든 리뷰 조회
@Operation(summary = "장소의 모든 큐레이팅 조회", description = "장소의 모든 큐레이팅을 조회합니다. return = List<PostRespDto>")
@GetMapping("/api/pin/post")
public CMRespDto<?> findAllPostInPin(@RequestParam("address") String address) {
List<PostRespDto> result = postService.장소의_모든_리뷰_조회(address);
return new CMRespDto<>(HttpStatus.OK, result, "해당 장소의 모든 리뷰 조회 성공!");
}

//#@!유저의 좋아요 장소 리뷰 조회

//#@!유저 장소 리뷰 수정

//#@!유저 장소 리뷰 삭제
}
46 changes: 46 additions & 0 deletions src/main/java/com/book_everywhere/domain/post/dto/PostReqDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.book_everywhere.domain.post.dto;

import com.book_everywhere.domain.auth.entity.User;
import com.book_everywhere.domain.pin.dto.PinRespDto;
import com.book_everywhere.domain.pin.entity.Pin;
import com.book_everywhere.domain.post.entity.Post;
import com.book_everywhere.domain.post.entity.PostImage;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
//장소 리뷰 등록 요청용 Dto
public class PostReqDto {
private Long socialId;
//@Valid 어노테이션 사용하기
@NotBlank
@Size(max = 20, message = "제목은 20자 이하로 입력해주세요.")
private String title;
@NotNull
@Size(max = 1500, message = "내용은 1500자 이하로 입력해주세요")
private String content;
private List<String> imageUrls;
private PinRespDto pinRespDto;

// 리뷰 임시저장 or 발행 여부
@NotNull(message = "발행 여부를 정확히해주세요.")
private boolean isPublishing;

//태그 생성을 위한 dto필요

public Post toEntity(User user, Pin pin) {
return Post.builder()
.title(title)
.content(content)
.user(user)
.pin(pin)
//#@!이미지 관련 코드가 필요합니다.
.build();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/book_everywhere/domain/post/dto/PostRespDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.book_everywhere.domain.post.dto;

import com.book_everywhere.domain.pin.dto.PinRespDto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
public class PostRespDto {
private Long postId;
private String title;
private String content;
private List<String> post_imageUrl;
private PinRespDto pinRespDto;
private boolean isPublishing;
}
Loading

0 comments on commit b130588

Please sign in to comment.