Skip to content

Commit

Permalink
Merge pull request #22 from Hooking-CEOS/jiwon
Browse files Browse the repository at this point in the history
✨[feat] 파일 api 생성
  • Loading branch information
JiwonKim08 authored Feb 18, 2024
2 parents bf9caf6 + 4189dc4 commit c42d793
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 16 deletions.
52 changes: 50 additions & 2 deletions src/main/java/shop/hooking/hooking/controller/CopyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import shop.hooking.hooking.dto.CardSearchCondition;
import shop.hooking.hooking.dto.request.CopyReqDto;
import shop.hooking.hooking.dto.request.CrawlingReqDto;
import shop.hooking.hooking.dto.request.FolderReqDto;
import shop.hooking.hooking.dto.request.ScrapReqDto;
import shop.hooking.hooking.dto.request.RandomSeedDto;
import shop.hooking.hooking.dto.response.CopyResDto;
import shop.hooking.hooking.dto.response.CopySearchResDto;
import shop.hooking.hooking.entity.Card;
import shop.hooking.hooking.entity.Contain;
import shop.hooking.hooking.entity.Scrap;
import shop.hooking.hooking.exception.OutOfIndexException;
import shop.hooking.hooking.repository.ContainRepository;
import shop.hooking.hooking.service.CopyService;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
Expand All @@ -24,6 +30,7 @@
public class CopyController {

private final CopyService copyService;
private final ContainRepository containRepository;


@Operation(summary = "전체 카피라이팅 조회하기")
Expand All @@ -38,6 +45,7 @@ public ResponseEntity<List<CopyResDto>> getCopyList(HttpServletRequest httpReque
}



@Operation(summary = "브랜드 카피라이팅 검색하기")
@PostMapping("/search/brand/{index}")
public ResponseEntity<CopySearchResDto> searchBrandList(HttpServletRequest httpRequest,
Expand Down Expand Up @@ -81,11 +89,51 @@ public ResponseEntity<List<CopyResDto>> getCopyFilter(HttpServletRequest httpReq

}

@Operation(summary= "사용자의 폴더 리스트 보여주기")
@GetMapping("/folder")
public ResponseEntity<List<String>> getFolderList(HttpServletRequest httpRequest){
return ResponseEntity.ok(copyService.getFolderList(httpRequest));

}

@Operation(summary = "폴더 스크랩 세부 조회하기")
@GetMapping("/folder/{folderId}")
public ResponseEntity<List<CopyResDto>> getFolderScrap(HttpServletRequest httpRequest, @PathVariable Long folderId) {
// Contain 엔티티에서 폴더에 속한 스크랩 조회
List<Contain> contains = containRepository.findByFolderId(folderId);
List<CopyResDto> copyResDtos = new ArrayList<>();

// 조회된 스크랩이 없는 경우
if (contains.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ArrayList<>()); // 빈 목록 반환
}

for (Contain contain : contains) {
Scrap scrap = contain.getScrap();
Card card = scrap.getCard(); // 스크랩에서 카드 정보 가져오기

// CopyResDto 객체 생성
CopyResDto copyResDto = CopyResDto.builder()
.id(card.getId())
.brand(scrap.getCard().getBrand())
.text(card.getText())
.createdAt(scrap.getCreatedAt())
.cardLink(scrap.getCard().getUrl())
.build();

copyResDtos.add(copyResDto);
}

// 스크랩된 CopyResDto 목록을 반환
return ResponseEntity.ok(copyResDtos);
}


@Operation(summary = "스크랩 하기")
@PostMapping("/scrap")
public ResponseEntity<?> createScrap(HttpServletRequest httpRequest, @RequestBody CopyReqDto copyReqDto) {
return ResponseEntity.ok(copyService.createScrap(httpRequest,copyReqDto));
public ResponseEntity<?> createScrap(HttpServletRequest httpRequest, @RequestBody ScrapReqDto scrapReqDto) {
copyService.createScrap(httpRequest, scrapReqDto);
return ResponseEntity.ok().build();
}


Expand Down
19 changes: 19 additions & 0 deletions src/main/java/shop/hooking/hooking/dto/request/FolderReqDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package shop.hooking.hooking.dto.request;

import lombok.Builder;
import lombok.Data;
import shop.hooking.hooking.entity.Folder;

import java.util.List;

@Data
@Builder
public class FolderReqDto {
private Long folderId;

@Builder
public FolderReqDto(Long folderId){
this.folderId=folderId;

}
}
23 changes: 23 additions & 0 deletions src/main/java/shop/hooking/hooking/dto/request/ScrapReqDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package shop.hooking.hooking.dto.request;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import shop.hooking.hooking.entity.Card;
import shop.hooking.hooking.entity.Folder;


@Getter
@NoArgsConstructor
public class ScrapReqDto {
private Long cardId;
private Long folderId;
private String folderName;

@Builder
public ScrapReqDto(Card card, Folder folder){
this.cardId=card.getId();
this.folderId = folder.getId();
this.folderName = folder.getName();
}
}
23 changes: 23 additions & 0 deletions src/main/java/shop/hooking/hooking/dto/response/FolderResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package shop.hooking.hooking.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import shop.hooking.hooking.entity.Card;
import shop.hooking.hooking.entity.Folder;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
public class FolderResDto {
private List<Folder> folders;

@Builder
public FolderResDto(List<Folder> folders){
this.folders=folders;

}
}
21 changes: 21 additions & 0 deletions src/main/java/shop/hooking/hooking/dto/response/ScrapResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package shop.hooking.hooking.dto.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import shop.hooking.hooking.entity.Card;
import shop.hooking.hooking.entity.Folder;


@Getter
@NoArgsConstructor
public class ScrapResDto {
private Long cardId;
private Long folderId;

@Builder
public ScrapResDto(Card card, Folder folder){
this.cardId=card.getId();
this.folderId = folder.getId();
}
}
32 changes: 32 additions & 0 deletions src/main/java/shop/hooking/hooking/entity/Contain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package shop.hooking.hooking.entity;

import lombok.*;
import javax.persistence.*;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "contain")
public class Contain {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "contain_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="foler_id")
private Folder folder;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="scrap_id")
private Scrap scrap;



@Builder
public Contain(Folder folder, Scrap scrap) {
this.folder=folder;
this.scrap=scrap;
}
}
32 changes: 32 additions & 0 deletions src/main/java/shop/hooking/hooking/entity/Folder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package shop.hooking.hooking.entity;

import lombok.*;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "folder")
public class Folder {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "folder_id")
private Long id;

@Column(name = "name")
private String name;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Builder
public Folder(User user, String name) {
this.user = user;
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package shop.hooking.hooking.repository;


import org.springframework.data.jpa.repository.JpaRepository;
import shop.hooking.hooking.entity.Contain;
import shop.hooking.hooking.entity.Scrap;
import shop.hooking.hooking.entity.User;

import java.util.List;
import java.util.Optional;

public interface ContainRepository extends JpaRepository<Contain, Long> {


List<Contain> findByFolderId(Long folderId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package shop.hooking.hooking.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import shop.hooking.hooking.entity.Folder;
import shop.hooking.hooking.entity.User;

import java.util.*;

public interface FolderRepository extends JpaRepository<Folder, Long>{

Optional<Folder> findFolderById(Long aLong);

List<Folder> findByUser(User user);
}
Loading

0 comments on commit c42d793

Please sign in to comment.