-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
576 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ spring: | |
properties: | ||
hibernate: | ||
format_sql: true | ||
show_sql: true | ||
--- | ||
# Settings for local | ||
spring: | ||
|
90 changes: 90 additions & 0 deletions
90
...com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.controller; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto; | ||
import com.umc.DongnaeFriend.domain.account.sharing.service.AccountBookSharingService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/account-books/sharing") | ||
public class accountBookSharingController { | ||
|
||
@Autowired | ||
AccountBookSharingService accountBookSharingService; | ||
|
||
/* | ||
* [가계부 공유] 게시글 검색 | ||
* @param keyword | ||
* @param pageable | ||
* | ||
* @param pageable | ||
* size : 페이지 사이즈 | ||
* page : 페이지 | ||
* sortBy : 정렬순 | ||
* - like | ||
* - createdAt | ||
*/ | ||
|
||
@GetMapping("/search") | ||
|
||
public ResponseEntity<?> searchAll(@RequestParam("keyword") String keyword, @RequestParam("category") int category, Pageable pageable) { | ||
log.info("searching : " + keyword + category); | ||
List<SharingDto.ListResponse> res = accountBookSharingService.searchByKeyword(keyword, category, pageable); | ||
log.info("res "); | ||
return ResponseEntity.ok(res); | ||
} | ||
|
||
/* | ||
* [가계부 공유] 게시글 등록 | ||
* | ||
* @param RequestDto | ||
*/ | ||
|
||
@PostMapping("") | ||
public ResponseEntity<?> createPost(@RequestBody SharingDto.Request req) { | ||
accountBookSharingService.createPost(req); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
/* | ||
* [가계부 공유] 게시글 상세 조회 | ||
* | ||
* @PathVariable accountBookId | ||
*/ | ||
@GetMapping("/{accountBookId}") | ||
public ResponseEntity<?> updatePost(@PathVariable("accountBookId") long board_id) { | ||
return ResponseEntity.ok(accountBookSharingService.getBoard(board_id)); | ||
} | ||
|
||
/* | ||
* [가계부 공유] 게시글 수정 | ||
* | ||
* @PathVariable accountBookId | ||
* @RequestBody SharingDto.Request | ||
*/ | ||
@PutMapping("/{accountBookId}") | ||
public ResponseEntity<?> updateBoard(@PathVariable("accountBookId") int board_id, @RequestBody SharingDto.Request req) { | ||
accountBookSharingService.updateBoard(board_id, req); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
/* | ||
* [가계부 공유] 게시글 삭제 | ||
* | ||
* @PathVariable accountBookId | ||
*/ | ||
@DeleteMapping("/{accountBookId}") | ||
public ResponseEntity<?> deleteBoard(@PathVariable("accountBookId") int board_id) { | ||
accountBookSharingService.deleteBoard(board_id); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.dto; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.Dongnae; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard; | ||
import com.umc.DongnaeFriend.domain.type.DongnaeBoardCategory; | ||
import com.umc.DongnaeFriend.domain.type.SharingCategory; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class SharingDto { | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Request { | ||
private int category; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
private List<String> images; | ||
|
||
public SharingBoard toEntity(User user) { | ||
return SharingBoard.builder() | ||
.user(user) | ||
.category(SharingCategory.valueOf(category)) | ||
.title(title) | ||
.content(content) | ||
.view(0) | ||
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Response{ | ||
String profileImage; | ||
String nickname; | ||
int category; | ||
String title; | ||
String content; | ||
List<String> images; | ||
String createdAt; | ||
boolean isWriter; | ||
boolean likeOrNot; | ||
boolean scrapOrNot; | ||
int view; | ||
} | ||
|
||
|
||
|
||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class ListResponse { | ||
private Long id; | ||
|
||
private int category; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
private String imageUrl; | ||
|
||
private String createdAt; | ||
|
||
private int view; | ||
|
||
private int commentCount; | ||
|
||
private int likes; | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface SharingBoardRepository extends JpaRepository<SharingBoard,Long> { | ||
|
||
|
||
// private final EntityManager em; | ||
// | ||
// public SharingBoardRepository(EntityManager em) { | ||
// this.em = em; | ||
// } | ||
|
||
// public List<SharingDto.ListResponse> findByKeywordAAndCategory(@Param("keyword") String keyword, @Param("category") String category, Pageable pageable) { | ||
// return em.createQuery("SELECT new com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto.ListResponse(s.id, s.category, s.title, s.content, s.createdAt, s.view, likes), count(SharingSympathy.sharingBoard.id) as likes " + | ||
// "FROM SharingBoard s left join SharingSympathy on s.id=SharingSympathy.sharingBoard.id " + | ||
// "WHERE (s.title LIKE %:keyword% or s.content LIKE % :keyword%) and s.category = :category " + | ||
// "group by s.id", SharingDto.ListResponse.class) | ||
// .setParameter("keyword", keyword) | ||
// .setParameter("category", category) | ||
// .getResultList(); | ||
// } | ||
|
||
|
||
@Query(value = "SELECT sharing_board.*, COUNT(sharing_sympathy.sharing_board_id) AS cnt FROM sharing_board\n" + | ||
"LEFT JOIN sharing_sympathy ON sharing_board.sharing_board_id = sharing_sympathy.sharing_board_id\n" + | ||
"WHERE (sharing_board.title LIKE %:keyword% OR sharing_board.content LIKE %:keyword%)\n" + | ||
"AND sharing_board.category = :category GROUP BY sharing_board.sharing_board_id ", nativeQuery = true) | ||
List<SharingBoard> findByKeywordOrderByLikes(@Param("keyword") String keyword, @Param("category") String category, Pageable pageable); | ||
|
||
|
||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...ava/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface SharingCommentRepository extends JpaRepository<SharingComment, Long> { | ||
|
||
public int countAllBySharingBoardId(Long sharing_board_id); | ||
} |
21 changes: 21 additions & 0 deletions
21
...in/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingImgRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingImg; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeImg; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface SharingImgRepository extends JpaRepository<SharingImg, Long> { | ||
|
||
@Query(value = "SELECT * FROM sharing_img WHERE sharing_board_id = ?1 ORDER BY created_at ASC LIMIT 1", nativeQuery = true) | ||
Optional<SharingImg> findFirst(long sharing_board_id); | ||
|
||
List<SharingImg> findAllBySharingBoard_Id(long id); | ||
|
||
void deleteAllById(long id); | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeSympathy; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface SharingSympathyRepository extends JpaRepository<SharingSympathy, Long> { | ||
|
||
int countAllBySharingBoardId(Long sharing_board_id); | ||
|
||
List<SharingSympathy> findByUser_Id(long user_id); | ||
} |
29 changes: 29 additions & 0 deletions
29
.../java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.service; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface AccountBookSharingService { | ||
|
||
List<SharingDto.ListResponse> searchByKeyword(String keyword, int category, Pageable pageable); | ||
|
||
void createPost(SharingDto.Request req); | ||
|
||
/* | ||
* [가계부 공유] 게시글 상세 조회 | ||
*/ | ||
SharingDto.Response getBoard(long board_id); | ||
|
||
/* | ||
* [가계부 공유] 게시글 수정 | ||
*/ | ||
void updateBoard(long board_id, SharingDto.Request req); | ||
|
||
|
||
/* | ||
* [가계부 공유] 게시글 삭제 | ||
*/ | ||
void deleteBoard(long board_id); | ||
} |
Oops, something went wrong.