Skip to content

Commit

Permalink
Merge pull request #114 from TaetaetaE01/main
Browse files Browse the repository at this point in the history
각 도메인 세팅 수정 및 파일 타입 validate
  • Loading branch information
TaetaetaE01 authored Aug 18, 2024
2 parents c436e7c + 9f0cb6e commit 5bdc68e
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class Event extends BaseTimeEntity {
@Column(name = "event_id")
private Long id;

@Column(name = "title")
@Column(nullable = false, name = "title")
private String title;

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

@Column(name = "target")
Expand All @@ -37,7 +37,7 @@ public class Event extends BaseTimeEntity {
@Column(name = "end_datetime")
private LocalDateTime endDateTime;

@Column(name = "affiliation_id")
@Column(nullable = false, name = "affiliation_id")
private Long affiliationId;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.file.util.FileUtil;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -32,8 +33,11 @@
public class EventServiceImpl implements EventService {

private final EventRepository eventRepository;

private final AffiliationService affiliationService;
private final FileService fileService;

private final FileUtil fileUtil;
private final AuthUtil authUtil;

@Override
Expand All @@ -47,6 +51,8 @@ public void registerEvent(EventRegisterRequest eventRegisterRequest, List<Multip
throw new BusinessException(NOT_COUNCIL_MEMBER);
}

fileUtil.CheckImageFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileSaveDTO fileSaveDTO = FileSaveDTO.builder()
Expand Down Expand Up @@ -77,6 +83,8 @@ public void updateEvent(Long eventId, EventUpdateRequest eventUpdateRequest, Lis
throw new BusinessException(NOT_COUNCIL_MEMBER);
}

fileUtil.CheckImageFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class FAQ extends BaseTimeEntity {
@Id //pk
@GeneratedValue(strategy = GenerationType.IDENTITY) //DB에서 값 자동 생성
@Column(name = "faq_id", updatable = false, unique = true, nullable = false)
@Column(name = "faq_id", updatable = false, unique = true)
private Long id;

@Column(nullable = false, name = "title")
Expand All @@ -26,7 +26,7 @@ public class FAQ extends BaseTimeEntity {
@Column(nullable = false, name = "content", columnDefinition = "TEXT") // 긴 문자열
private String content;

@Column
@Column(nullable = false, name = "affiliation_id")
private Long affiliationId;

@OneToMany
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class Meetings extends BaseTimeEntity {
@Column(name = "meetings_id")
private Long id;

@Column(name = "title")
@Column(nullable = false, name = "title")
private String title;

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

@Column(name = "is_public")
private boolean isPublic;

@Column(name = "affiliation_id")
@Column(nullable = false, name = "affiliation_id")
private Long affiliationId;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.file.util.FileUtil;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -32,10 +33,12 @@
public class MeetingsServiceImpl implements MeetingsService {

private final MeetingsRepository meetingsRepository;

private final FileService fileService;
private final AffiliationService affiliationService;
private final AuthUtil authUtil;

private final AuthUtil authUtil;
private final FileUtil fileUtil;

@Override
@Transactional(rollbackFor = Exception.class)
Expand All @@ -47,6 +50,8 @@ public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, Li
throw new BusinessException(NOT_COUNCIL_MEMBER);
}

fileUtil.checkPdfFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileSaveDTO fileSaveDTO = FileSaveDTO.builder()
Expand Down Expand Up @@ -77,6 +82,8 @@ public void updateMeetings(Long meetingsId, MeetingsUpdateRequest meetingsUpdate
throw new BusinessException(NOT_COUNCIL_MEMBER);
}

fileUtil.checkPdfFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Rule extends BaseTimeEntity {
@Column(name = "rule_id")
private Long id;

@Column(name = "title")
@Column(nullable = false, name = "title")
private String title;

@Column(name = "affiliation_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.file.util.FileUtil;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -37,6 +38,7 @@ public class RuleServiceImpl implements RuleService {
private final AffiliationService affiliationService;

private final AuthUtil authUtil;
private final FileUtil fileUtil;

@Override
@Transactional(rollbackFor = Exception.class)
Expand All @@ -49,6 +51,8 @@ public void registerRule(RuleRegisterRequest ruleRegisterRequest, List<Multipart
throw new BusinessException(NOT_PRESIDENT_MEMBER);
}

fileUtil.checkPdfFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileSaveDTO fileSaveDTO = FileSaveDTO.builder()
Expand All @@ -75,6 +79,8 @@ public void updateRule(Long ruleId, RuleUpdateRequest ruleUpdateRequest, List<Mu
Rule rule = ruleRepository.findById(ruleId)
.orElseThrow(() -> new BusinessException(NO_EXIST_RULE));

fileUtil.checkPdfFiles(multipartFiles);

List<File> files = null;
if (fileService.checkExistRequestFile(multipartFiles)) {
FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ public enum ErrorCode {
NO_EXIST_EMAIL(HttpStatus.NOT_FOUND, "MEMBER-005", "존재하지 않는 이메일입니다."),
INVALID_EMAIL_FORMAT(HttpStatus.BAD_REQUEST, "MEMBER-006", "올바르지 않은 이메일 형식입니다."),
NO_EXIST_MEMBER(HttpStatus.NOT_FOUND, "MEMBER-007", "존재하지 않는 유저입니다."),
MISMATCH_PASSWORD(HttpStatus.NOT_FOUND,"MEMBER-008", "비밀번호가 올바르지 않습니다."),
MISMATCH_PASSWORD(HttpStatus.NOT_FOUND, "MEMBER-008", "비밀번호가 올바르지 않습니다."),
NOT_COUNCIL_MEMBER(HttpStatus.BAD_REQUEST, "MEMBER-008", "해당 학생회 멤버가 아닙니다."),
NOT_PRESIDENT_MEMBER(HttpStatus.BAD_REQUEST, "MEMBER-009", "해당 학생회 회장이 아닙니다."),


// TOKEN
ACCESS_Token_Expired(HttpStatus.BAD_REQUEST, "TOKEN_001", "만료된 access 토큰입니다."),
REFRESH_Token_Expired(HttpStatus.BAD_REQUEST, "TOKEN_002", "만료된 refresh 토큰입니다."),
ACCESS_TOKEN_EXPIRED(HttpStatus.BAD_REQUEST, "TOKEN_001", "만료된 access 토큰입니다."),
REFRESH_TOKEN_EXPIRED(HttpStatus.BAD_REQUEST, "TOKEN_002", "만료된 refresh 토큰입니다."),

// MEETINGS
NO_EXIST_MEETINGS(HttpStatus.NOT_FOUND, "MEETINGS-001", "존재하지 않는 회의록 입니다."),
Expand All @@ -43,11 +42,13 @@ public enum ErrorCode {
// AFFILIATION
NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 소속 입니다."),
INVALID_AFFILIATION(HttpStatus.BAD_REQUEST, "AFFILIATION-002", "해당 학생회는 단과대가 아닙니다."),
NO_FOUND_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-003","해당 학생회 정보를 찾을 수 없습니다."),
NO_FOUND_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-003", "해당 학생회 정보를 찾을 수 없습니다."),

// FILE
FAIL_TO_UPLOAD(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-001", "파일 업로드에 실패하였습니다."),
FAIL_TO_DELETE(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-002", "파일 삭제에 실패하였습니다."),
INVALID_IMAGE_TYPE(HttpStatus.BAD_REQUEST, "FILE-003", "이미지 파일이 아닙니다."),
INVALID_PDF_TYPE(HttpStatus.BAD_REQUEST, "FILE-004", "PDF 파일이 아닙니다."),

// TRANSACTIONS
FAIL_TO_LONG_PARSING(HttpStatus.BAD_REQUEST, "TRANSACTIONS-001", "long 타입 파싱에 실패했습니다."),
Expand All @@ -66,6 +67,7 @@ public enum ErrorCode {

// PATTERN
ILLEGAL_HEADER_PATTERN(HttpStatus.BAD_REQUEST, "PATTERN-001", "헤더의 형식이 맞지 않습니다."),

// AUTHENTICATION
NOT_AUTHENTICATE_REQUEST(HttpStatus.BAD_REQUEST, "AUTHENTICATION-001", "인증 실패한 요청입니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.bigbrotherbe.global.file.util;

import com.example.bigbrotherbe.global.exception.BusinessException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.INVALID_IMAGE_TYPE;
import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.INVALID_PDF_TYPE;

@Component
@RequiredArgsConstructor
public class FileUtil {
public void CheckImageFiles(List<MultipartFile> multipartFiles) {
multipartFiles.stream()
.filter(file -> {
String contentType = file.getContentType();
return contentType == null || !(contentType.equals(MediaType.IMAGE_JPEG_VALUE) ||
contentType.equals("image/jpg") ||
contentType.equals(MediaType.IMAGE_PNG_VALUE) ||
contentType.equals(MediaType.IMAGE_GIF_VALUE));
})
.findFirst()
.ifPresent(file -> {
throw new BusinessException(INVALID_IMAGE_TYPE);
});
}

public void checkPdfFiles(List<MultipartFile> multipartFiles) {
multipartFiles.stream()
.filter(file -> {
String contentType = file.getContentType();
return contentType == null || !contentType.equals(MediaType.APPLICATION_PDF_VALUE);
})
.findFirst()
.ifPresent(file -> {
throw new BusinessException(INVALID_PDF_TYPE);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ public boolean checkPresidentRole(Long affiliationId) {
Member member = getLoginMember();
List<AffiliationMember> affiliationMemberList = affiliationMemberRepository.findAllByMemberId(member.getId());
for (AffiliationMember affiliationMember : affiliationMemberList) {

if (affiliationMember.getAffiliation().getAffiliation_id().equals(affiliationId)) {
if (affiliationMember.getRole().equals(ROLE_PRESIDENT.getRole()) ||
affiliationMember.getRole().equals(ROLE_ADMIN.getRole())) {
if (affiliationMember.getRole().equals(ROLE_PRESIDENT.getRole())) {
return false;
}
}

if (affiliationMember.getRole().equals(ROLE_ADMIN.getRole())) {
return false;
}
}
return true;
}
Expand Down
Loading

0 comments on commit 5bdc68e

Please sign in to comment.