Skip to content

Commit

Permalink
Merge pull request #18 from TaetaetaE01/main
Browse files Browse the repository at this point in the history
회의록 상세조회, 전체조회 페이징처리 및 검색기능 구현
  • Loading branch information
TaetaetaE01 authored Aug 4, 2024
2 parents 8bbe964 + be32961 commit 762e28f
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 35 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ dependencies {

// S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.1.RELEASE'

// Pageable
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.example.bigbrotherbe.domain.meetings.controller;

import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse;
import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import com.example.bigbrotherbe.domain.meetings.service.MeetingsService;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -38,4 +45,25 @@ public ResponseEntity<Void> deleteMeetings(@PathVariable("meetingsId") Long meet
meetingsService.deleteMeetings(meetingsId);
return ResponseEntity.ok().build();
}

@GetMapping("/{meetingsId}")
public ResponseEntity<MeetingsResponse> getMeetingsById(@PathVariable("meetingsId") Long MeetingsId) {
MeetingsResponse meetingsResponse = meetingsService.getMeetingsById(MeetingsId);
return ResponseEntity.ok().body(meetingsResponse);
}

@GetMapping("all/{affiliationId}")
public ResponseEntity<Page<Meetings>> getMeetingsList(@PathVariable("affiliationId") Long affiliationId,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "10") int size,
@RequestParam(name = "search", required = false) String search) {
Page<Meetings> meetingsPage;
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "id"));
if (search != null && !search.isEmpty()) {
meetingsPage = meetingsService.searchMeetings(affiliationId, search, pageable);
} else {
meetingsPage = meetingsService.getMeetings(affiliationId, pageable);
}
return ResponseEntity.ok().body(meetingsPage);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.example.bigbrotherbe.domain.meetings.dto;
package com.example.bigbrotherbe.domain.meetings.dto.request;

import com.example.bigbrotherbe.domain.meetings.entity.Meetings;

import com.example.bigbrotherbe.global.file.entity.File;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bigbrotherbe.domain.meetings.dto;
package com.example.bigbrotherbe.domain.meetings.dto.request;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.bigbrotherbe.domain.meetings.dto.response;

import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
@AllArgsConstructor
public class MeetingsResponse {
private Long meetingsId;
private String title;
private String content;
private boolean isPublic;
private Long affiliationId;
private List<String> urlList;

public static MeetingsResponse fromMeetingsResponse(Meetings meetings, List<String> urlList) {
return MeetingsResponse.builder()
.meetingsId(meetings.getId())
.title(meetings.getTitle())
.content(meetings.getContent())
.isPublic(meetings.isPublic())
.affiliationId(meetings.getAffiliationId())
.urlList(urlList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.example.bigbrotherbe.domain.BaseTimeEntity;
import com.example.bigbrotherbe.global.file.entity.File;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;

Expand Down Expand Up @@ -32,6 +34,7 @@ public class Meetings extends BaseTimeEntity {
@Column(name = "affiliation_id")
private Long affiliationId;

@JsonIgnore
@OneToMany(mappedBy = "meetings", cascade = CascadeType.ALL, orphanRemoval = true)
private List<File> files = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.bigbrotherbe.domain.meetings.repository;

import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MeetingsRepository extends JpaRepository<Meetings, Long> {
public interface MeetingsRepository extends JpaRepository<Meetings, Long> {
Page<Meetings> findByAffiliationId(Long affiliationId, Pageable pageable);

Page<Meetings> findByAffiliationIdAndTitleContaining(Long affiliationId, String title, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.example.bigbrotherbe.domain.meetings.service;

import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse;
import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand All @@ -12,4 +16,10 @@ public interface MeetingsService {
void updateMeetings(Long meetingsId, MeetingsUpdateRequest meetingsUpdateRequest, List<MultipartFile> multipartFiles);

void deleteMeetings(Long meetingsId);

MeetingsResponse getMeetingsById(Long meetingsId);

Page<Meetings> getMeetings(Long affiliationId, Pageable pageable);

Page<Meetings> searchMeetings(Long affiliationId, String title, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package com.example.bigbrotherbe.domain.meetings.service;

import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse;
import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import com.example.bigbrotherbe.domain.meetings.repository.MeetingsRepository;
import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.service.MemberService;
import com.example.bigbrotherbe.global.exception.BusinessException;
import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
import com.example.bigbrotherbe.global.file.enums.FileType;
import com.example.bigbrotherbe.global.file.service.FileService;
import com.example.bigbrotherbe.global.jwt.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NO_EXIST_AFFILIATION;
import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NO_EXIST_MEETINGS;
Expand Down Expand Up @@ -91,6 +95,38 @@ public void deleteMeetings(Long meetingsId) {
Meetings meetings = meetingsRepository.findById(meetingsId)
.orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS));

FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder()
.fileType(FileType.MEETINGS.getType())
.files(meetings.getFiles())
.build();

fileService.deleteFile(fileDeleteDTO);
meetingsRepository.delete(meetings);
}

@Override
@Transactional(readOnly = true)
public MeetingsResponse getMeetingsById(Long meetingsId) {
Meetings meetings = meetingsRepository.findById(meetingsId)
.orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS));

List<String> urlList = meetings.getFiles().stream()
.map(File::getUrl)
.toList();

return MeetingsResponse.fromMeetingsResponse(meetings, urlList);
}

@Override
@Transactional(readOnly = true)
public Page<Meetings> getMeetings(Long affiliationId, Pageable pageable) {
return meetingsRepository.findByAffiliationId(affiliationId, pageable);
}

@Override
@Transactional(readOnly = true)
public Page<Meetings> searchMeetings(Long affiliationId, String title, Pageable pageable) {
return meetingsRepository.findByAffiliationIdAndTitleContaining(affiliationId, title, pageable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public enum ErrorCode {
NO_EXIST_FAQ(HttpStatus.NOT_FOUND, "FAQ-001", "존재하지 않는 FAQ 입니다."),

// AFFILIATION
NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 학생회 입니다.");
NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 학생회 입니다."),

// FILE
FAIL_TO_UPLOAD(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-001","파일 업로드에 실패하였습니다."),
FAIL_TO_DELETE(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-002","파일 삭제에 실패하였습니다.");

private final HttpStatus httpStatus;
private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.bigbrotherbe.global.file.dto;

import com.example.bigbrotherbe.global.file.entity.File;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class FileDeleteDTO {
private List<File> files;
private String fileType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.bigbrotherbe.global.file.entity.File;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.bigbrotherbe.global.file.service;

import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
Expand All @@ -13,5 +14,6 @@ public interface FileService {
List<File> saveFile(FileSaveDTO fileSaveDTO);

List<File> updateFile(FileUpdateDTO fileUpdateDTO);
// void deleteFile();

void deleteFile(FileDeleteDTO deleteDTO);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.bigbrotherbe.global.file.service;

import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
Expand Down Expand Up @@ -60,11 +61,21 @@ public List<File> updateFile(FileUpdateDTO fileUpdateDTO) {
return updatedFiles;
}

public void deleteFile(FileDeleteDTO deleteDTO) {
List<File> files = deleteDTO.getFiles();
String fileType = deleteDTO.getFileType();
files.forEach(file -> {
String fileName = file.getUrl().split("/")[3];
s3Util.deleteFile(fileType + "/" + fileName);
});
}

@Override
public boolean checkExistRequestFile(List<MultipartFile> multipartFiles) {
if(multipartFiles == null){
if (multipartFiles == null) {
return false;
}

for (MultipartFile file : multipartFiles) {
if (file.isEmpty()) {
return false;
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/example/bigbrotherbe/global/file/util/S3Util.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.example.bigbrotherbe.global.file.util;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.example.bigbrotherbe.global.exception.BusinessException;
import com.example.bigbrotherbe.global.exception.enums.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -13,6 +16,9 @@
import java.net.URL;
import java.util.UUID;

import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.FAIL_TO_DELETE;
import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.FAIL_TO_UPLOAD;


@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -42,24 +48,18 @@ public String uploadFile(MultipartFile file, String fileType) {
return fileUrl.toString();
} catch (IOException e) {
e.printStackTrace();
// 예외 처리: 실패한 경우 null을 반환하거나 적절한 방식으로 처리
return null;
throw new BusinessException(FAIL_TO_UPLOAD);
} catch (AmazonServiceException e) {
throw new BusinessException(FAIL_TO_UPLOAD);
}
}

// public List<String> uploadFiles(List<MultipartFile> files) {
// List<String> fileUrls = new ArrayList<>();
// for (MultipartFile file : files) {
// String fileUrl = uploadFile(file);
// if (fileUrl != null) {
// fileUrls.add(fileUrl);
// }
// }
// return fileUrls;
// }

public void deleteFile(String path) {
amazonS3Client.deleteObject(bucket, path);
try {
amazonS3Client.deleteObject(bucket, path);
} catch (AmazonServiceException e) {
throw new BusinessException(FAIL_TO_DELETE);
}
}

}
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver

# 태태 로컬 데이터베이스 설정
# datasource:
# url: jdbc:mysql://localhost:3306/bigbrother?serverTimezone=UTC
# driver-class-name: com.mysql.cj.jdbc.Driver
# username: root
# password: 1234
datasource:
url: jdbc:mysql://localhost:3306/bigbrother
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 1234

mail:
host: smtp.gmail.com
Expand Down Expand Up @@ -82,4 +82,4 @@ cloud:
region:
static: ap-northeast-2
stack:
auto: false
auto: false

0 comments on commit 762e28f

Please sign in to comment.