Skip to content

Commit

Permalink
🙈 Chore: .gradle, .idea 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
JungYoonShin committed Jul 24, 2023
2 parents 77e2763 + 2127d46 commit 86a97be
Show file tree
Hide file tree
Showing 21 changed files with 576 additions and 41 deletions.
1 change: 1 addition & 0 deletions out/production/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spring:
properties:
hibernate:
format_sql: true
show_sql: true
---
# Settings for local
spring:
Expand Down
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);
}

}
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;

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

import com.fasterxml.jackson.databind.ser.Serializers.Base;
import com.umc.DongnaeFriend.domain.BaseTimeEntity;
import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto;
import com.umc.DongnaeFriend.domain.dongnae.dto.DongnaeBoardDto;
import com.umc.DongnaeFriend.domain.type.SharingCategory;
import com.umc.DongnaeFriend.domain.user.entity.User;
import javax.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

@Getter
@Builder
Expand All @@ -38,4 +41,14 @@ public class SharingBoard extends BaseTimeEntity {

@Column(columnDefinition = "MEDIUMTEXT", nullable = false)
private String content;

@Column(name = "view")
@ColumnDefault("0")
private Integer view;

public void updateBoard(SharingDto.Request req) {
this.category = SharingCategory.valueOf(req.getCategory());
this.title = req.getTitle();
this.content = req.getContent();
}
}
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);




}
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);
}
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);
}
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);
}
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);
}
Loading

0 comments on commit 86a97be

Please sign in to comment.