Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
848cd9b
Feat: MessageService 메서드 추가 #124
hot666666 Dec 6, 2023
5cdf109
Feat: Message 관련 DTO 업데이트 #124
hot666666 Dec 6, 2023
a8c0e7c
Feat: Message API 업데이트 #124
hot666666 Dec 6, 2023
a77ac97
Test: Message 테스트 코드 추가 #124
hot666666 Dec 6, 2023
d99e56b
Style: 기본 값이 있는 엔티티 필드에 @Builder.Default 지정
hot666666 Dec 7, 2023
1e1f041
Fix: LectureRepository,UserLectureService 테스트코드 수정
hot666666 Dec 7, 2023
01b570f
Test: RedisService 테스트코드 작성
hot666666 Dec 7, 2023
d9a05e6
Feat: 필터체인에 세션필터를 추가 #124
hot666666 Dec 7, 2023
b67d391
Fix: JwtAuthenticationFilter 순서 지정 #124
hot666666 Dec 7, 2023
ba591f0
Fix: DTO에서 휴대폰 번호 검증 추가 #124
hot666666 Dec 7, 2023
ded0ef0
Feat: 오류 Code 추가 #124
hot666666 Dec 7, 2023
8800264
Feat: EducationApplication API에서 인증된 번호 사용 업데이트 #124
hot666666 Dec 7, 2023
e5c313d
Feat: EducationApplication, ClassGroup Service 업데이트 #124
hot666666 Dec 7, 2023
8137f30
Feat: EducationApplicationRepository 업데이트 #124
hot666666 Dec 7, 2023
01fda0a
Test: SessionFilter 테스트코드 작성 #124
hot666666 Dec 7, 2023
6da4d09
Fix: 강의(교육) 신청 관련 테스트 업데이트 #124
hot666666 Dec 7, 2023
d8a5831
Style: 기본값 있는 필드에 Builder.Default 추가
hot666666 Dec 8, 2023
2fc2ffb
Feat: 강의 컨텐츠의 이미지 관련 오류 Code 추가 #120
hot666666 Dec 9, 2023
f48afc4
Style: CreateLectureReq 수정
hot666666 Dec 9, 2023
097f73a
Feat: 강의 컨텐츠 관련 DTO 작성 #120
hot666666 Dec 9, 2023
4942ff0
Feat: 강의 컨텐츠 관련 엔티티 작성 #120
hot666666 Dec 9, 2023
5dda67f
Feat: 강의 컨텐츠 관련 Mapper 작성 #120
hot666666 Dec 9, 2023
19e00ce
Feat: 강의 컨텐츠 이미지 레포지터리 추가 #120
hot666666 Dec 9, 2023
6d7291c
Feat: 강의 컨텐츠 서비스 및 API 추가 #120
hot666666 Dec 9, 2023
bd722ff
Chore: chmod +x ./gradlew
hot666666 Dec 9, 2023
a0971cf
Refact: 강의 컨텐츠 서비스 리팩토링 #120
hot666666 Dec 9, 2023
649a8f2
Fix: 강의컨텐츠 이미지 관련 Code 오류 수정 #120
hot666666 Dec 10, 2023
4f3691c
Test: ContentImageS3ServiceImpl 테스트코드 작성 #120
hot666666 Dec 10, 2023
56a17e4
Test: 강의 컨텐츠 서비스 관련 테스트코드 추가 #120
hot666666 Dec 10, 2023
e852059
Docs: 강의 컨텐츠 API 설명 추가 #120
hot666666 Dec 10, 2023
eec1148
Refact: 매직넘버 처리 및 validate 함수 분리
hot666666 Dec 18, 2023
7d14a33
Fix: validate 함수 관련 부분 수정
hot666666 Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -38,61 +40,76 @@ public class EducationApplicationApi {
private final EducationApplicationService applicationService;
private final ClassGroupService classGroupService;

@ModelAttribute("phoneNumber")
public String getPhoneNumber(HttpServletRequest request) {
// SessionFilter에서 넣어준 phoneNumber를 가져온다
return (String) request.getAttribute("phoneNumber");
}

/* Education Application */

@ApiOperation(value = "교육 신청 작성", notes = "교육을 신청합니다.")
@PostMapping
public SuccessResponse<?> create(@RequestBody @Valid EducationApplicationReq applicationReq) {
EducationApplicationRes savedApplication = applicationService.save(applicationReq);
public SuccessResponse<?> create(@ModelAttribute("phoneNumber") String phoneNumber,
@RequestBody @Valid EducationApplicationReq applicationReq) {
EducationApplicationRes savedApplication = applicationService.save(applicationReq, phoneNumber);
return SuccessResponse.successResponse(savedApplication);
}

@ApiOperation(value = "휴대폰 번호로 작성한 교육 신청 조회", notes = "신청한 교육을 핸드폰 번호를 통해 조회합니다.")
@GetMapping
public SuccessResponse<?> read(@RequestBody @Valid RetrieveApplicationReq retrieveApplicationReq) {
public SuccessResponse<?> read(@ModelAttribute("phoneNumber") String phoneNumber,
@RequestBody @Valid RetrieveApplicationReq retrieveApplicationReq) {
List<EducationApplicationRes> applications = applicationService
.findByPhoneNumber(retrieveApplicationReq);
.findByPhoneNumber(retrieveApplicationReq, phoneNumber);
return SuccessResponse.successResponse(applications);
}

@ApiOperation(value = "신청한 교육 수정", notes = "신청한 교육을 수정합니다.")
@PutMapping("/{applicationId}")
public SuccessResponse<?> update(@PathVariable Long applicationId,
public SuccessResponse<?> update(@ModelAttribute("phoneNumber") String phoneNumber,
@PathVariable Long applicationId,
@RequestBody @Valid EducationApplicationReq applicationReq) {
EducationApplicationRes updatedApplication = applicationService.update(applicationId, applicationReq);
EducationApplicationRes updatedApplication = applicationService.update(applicationId, applicationReq,
phoneNumber);
return SuccessResponse.successResponse(updatedApplication);
}

@ApiOperation(value = "신청한 교육 삭제", notes = "신청한 교육을 삭제합니다. 학급정보도 같이 삭제됩니다.")
@DeleteMapping("/{applicationId}")
public SuccessResponse<?> delete(@PathVariable Long applicationId) {
applicationService.delete(applicationId);
public SuccessResponse<?> delete(@ModelAttribute("phoneNumber") String phoneNumber,
@PathVariable Long applicationId) {
applicationService.delete(applicationId, phoneNumber);
return SuccessResponse.successResponse("신청이 삭제되었습니다.");
}

/* Class Group */

@ApiOperation(value = "신청한 교육에 학급정보 추가", notes = "우선 교육을 신청해야 합니다.")
@PostMapping("/{applicationId}/classGroup")
public SuccessResponse<?> addClassGroup(@PathVariable Long applicationId,
public SuccessResponse<?> addClassGroup(@ModelAttribute("phoneNumber") String phoneNumber,
@PathVariable Long applicationId,
@RequestBody @Valid ClassGroupReq classGroupReq) {
ClassGroupRes savedClassGroup = classGroupService.addClassGroupToApplication(applicationId, classGroupReq);
ClassGroupRes savedClassGroup = classGroupService.addClassGroupToApplication(applicationId, classGroupReq,
phoneNumber);
return SuccessResponse.successResponse(savedClassGroup);
}

@ApiOperation(value = "학급정보 업데이트", notes = "우선 교육을 신청해야 합니다.")
@PutMapping("/{applicationId}/classGroup/{classGroupId}")
public SuccessResponse<?> updateClassGroup(@PathVariable Long applicationId, @PathVariable Long classGroupId,
public SuccessResponse<?> updateClassGroup(@ModelAttribute("phoneNumber") String phoneNumber,
@PathVariable Long applicationId, @PathVariable Long classGroupId,
@RequestBody @Valid ClassGroupReq classGroupReq) {
ClassGroupRes updatedClassGroup = classGroupService.updateClassGroup(applicationId, classGroupId,
classGroupReq);
classGroupReq, phoneNumber);
return SuccessResponse.successResponse(updatedClassGroup);
}

@ApiOperation(value = "학급정보 삭제", notes = "학급정보가 삭제됩니다.")
@DeleteMapping("/{applicationId}/classGroup/{classGroupId}")
public SuccessResponse<?> deleteClassGroup(@PathVariable Long applicationId, @PathVariable Long classGroupId) {
classGroupService.deleteClassGroup(applicationId, classGroupId);
public SuccessResponse<?> deleteClassGroup(@ModelAttribute("phoneNumber") String phoneNumber,
@PathVariable Long applicationId, @PathVariable Long classGroupId) {
classGroupService.deleteClassGroup(applicationId, classGroupId, phoneNumber);
return SuccessResponse.successResponse("학급정보가 삭제되었습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.DoroServer.domain.educationApplication.api;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.filter.GenericFilterBean;

import com.example.DoroServer.global.exception.Code;
import com.example.DoroServer.global.exception.SessionIdException;
import com.example.DoroServer.global.jwt.RedisService;

import java.io.IOException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class SessionFilter extends GenericFilterBean {
// 해당 필터는 "/education-application"에 대한 요청에 대해서만 적용

private final RedisService redisService;

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();

if (requestURI.startsWith("/education-application")) {
String sessionId = httpRequest.getHeader("Session-Id");
if (sessionId == null) {
log.debug("유효한 Session-Id가 없습니다, uri: {}", requestURI);
throw new SessionIdException(Code.SESSION_ID_NOT_FOUND);
}
String phoneNumber = redisService.getValues(sessionId);
if (phoneNumber == null) {
log.debug("유효한 Session-Id가 아닙니다, uri: {}", requestURI);
throw new SessionIdException(Code.SESSION_ID_NOT_VALID);
}
httpRequest.setAttribute("phoneNumber", phoneNumber);

}

chain.doFilter(request, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.DoroServer.domain.educationApplication.api;

import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import java.io.IOException;

import org.springframework.web.filter.GenericFilterBean;

import com.example.DoroServer.global.common.AuthErrorResponse;
import com.example.DoroServer.global.exception.Code;
import com.example.DoroServer.global.exception.SessionIdException;

public class SessionFilterHandler extends GenericFilterBean {

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
chain.doFilter(request, response);
} catch (SessionIdException e) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("application/json");
httpResponse.setCharacterEncoding("utf-8");
Code code = e.getMessage().equals("SESSION_ID_NOT_FOUND") ? Code.SESSION_ID_NOT_FOUND
: Code.SESSION_ID_NOT_VALID;
httpResponse.setStatus(code.getHttpStatus().value());
AuthErrorResponse authErrorResponse = buildAuthErrorResponse(code);
httpResponse.getWriter().write(authErrorResponse.toString());

return;
}
}

// 리팩터링 필요 - static 메서드가 아닌 별개의 클래스에서 메서드 생성
public static AuthErrorResponse buildAuthErrorResponse(Code errorCode) {
return AuthErrorResponse.builder()
.errorCode(errorCode)
.message(errorCode.getMessage())
.cause(SessionFilter.class.getName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.validation.constraints.Email;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -27,6 +28,7 @@ public class EducationApplicationReq {
private String position; // 신청자 직위

@NotBlank
@Pattern(regexp = "^01([016789])([0-9]{3,4})([0-9]{4})$", message = "올바른 휴대폰 번호 형식이 아닙니다.")
private String phoneNumber; // 신청자 전화번호

@Email
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.DoroServer.domain.educationApplication.dto;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -15,5 +16,6 @@
@AllArgsConstructor
public class RetrieveApplicationReq {
@NotBlank
@Pattern(regexp = "^01([016789])([0-9]{3,4})([0-9]{4})$", message = "올바른 휴대폰 번호 형식이 아닙니다.")
private String phoneNumber; // 신청자 전화번호
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.DoroServer.domain.educationApplication.repository;

import java.util.List;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

import com.example.DoroServer.domain.educationApplication.entity.EducationApplication;
Expand All @@ -10,4 +10,6 @@ public interface EducationApplicationRepository extends JpaRepository<EducationA

List<EducationApplication> findByPhoneNumber(String phoneNumber);

Optional<EducationApplication> findByIdAndPhoneNumber(Long id, String phoneNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ public class EducationApplicationService {
/* Education Application */

// create
public EducationApplicationRes save(EducationApplicationReq applicationReq) {
public EducationApplicationRes save(EducationApplicationReq applicationReq, String phoneNumber) {
throwExceptionIfNotEqual(applicationReq.getPhoneNumber(), phoneNumber);

EducationApplication educationApplication = mapper.toEntity(applicationReq);
EducationApplication savedEducationApplication = repository.save(educationApplication);

return mapper.toDTO(savedEducationApplication);
}

// read
public List<EducationApplicationRes> findByPhoneNumber(RetrieveApplicationReq retrieveApplicationReq) {
List<EducationApplication> educationApplications = repository
.findByPhoneNumber(retrieveApplicationReq.getPhoneNumber());
public List<EducationApplicationRes> findByPhoneNumber(RetrieveApplicationReq retrieveApplicationReq,
String phoneNumber) {
throwExceptionIfNotEqual(retrieveApplicationReq.getPhoneNumber(), phoneNumber);

List<EducationApplication> educationApplications = repository.findByPhoneNumber(phoneNumber);

return mapper.toDTO(educationApplications);
}

// update
public EducationApplicationRes update(Long id, EducationApplicationReq applicationReq) {
EducationApplication educationApplication = repository.findById(id)
.orElseThrow(() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));
public EducationApplicationRes update(Long id, EducationApplicationReq applicationReq, String phoneNumber) {
throwExceptionIfNotEqual(applicationReq.getPhoneNumber(), phoneNumber);

EducationApplication educationApplication = repository.findByIdAndPhoneNumber(id, phoneNumber).orElseThrow(
() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));

mapper.toEntity(applicationReq, educationApplication);
EducationApplication updatedEducationApplication = repository.save(educationApplication);
Expand All @@ -52,8 +58,18 @@ public EducationApplicationRes update(Long id, EducationApplicationReq applicati
}

// delete
public void delete(Long id) {
repository.deleteById(id);
public void delete(Long id, String phoneNumber) {
EducationApplication educationApplication = repository.findByIdAndPhoneNumber(id, phoneNumber).orElseThrow(
() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));

repository.delete(educationApplication);
}

public static void throwExceptionIfNotEqual(String phoneNumber1, String phoneNumber2) {
// 두 번호가 같지 않으면 예외 발생
if (!phoneNumber2.equals(phoneNumber1)) {
throw new BaseException(Code.EDUCATION_APPLICATION_DIFFERENT_PHONE);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class ClassGroupService {
/* Class Group */

// create
public ClassGroupRes addClassGroupToApplication(Long applicationId, ClassGroupReq classGroupReq) {
EducationApplication educationApplication = educationApplicationRepository.findById(applicationId)
public ClassGroupRes addClassGroupToApplication(Long applicationId, ClassGroupReq classGroupReq,
String phoneNumber) {
EducationApplication educationApplication = educationApplicationRepository
.findByIdAndPhoneNumber(applicationId, phoneNumber)
.orElseThrow(() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));

ClassGroup classGroup = mapper.toEntity(classGroupReq);
Expand All @@ -37,21 +39,33 @@ public ClassGroupRes addClassGroupToApplication(Long applicationId, ClassGroupRe
}

// update
public ClassGroupRes updateClassGroup(Long id, Long classGroupId, ClassGroupReq classGroupReq) {
ClassGroup target = classGroupRepository.findById(classGroupId)
public ClassGroupRes updateClassGroup(Long applicationId, Long classGroupId, ClassGroupReq classGroupReq,
String phoneNumber) {
EducationApplication educationApplication = educationApplicationRepository
.findByIdAndPhoneNumber(applicationId, phoneNumber)
.orElseThrow(() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));

ClassGroup classGroup = educationApplication.getClassGroups().stream()
.filter(group -> group.getId().equals(classGroupId))
.findFirst()
.orElseThrow(() -> new BaseException(Code.EDUCATION_CLASS_GROUP_NOT_FOUND));

mapper.toEntity(classGroupReq, target);
ClassGroup updatedClassGroup = classGroupRepository.save(target);
mapper.toEntity(classGroupReq, classGroup);
ClassGroup updatedClassGroup = classGroupRepository.save(classGroup);

return mapper.toDTO(updatedClassGroup);
}

// delete
public void deleteClassGroup(Long id, Long classGroupId) {
ClassGroup classGroup = classGroupRepository.findById(classGroupId)
public void deleteClassGroup(Long applicationId, Long classGroupId, String phoneNumber) {
EducationApplication educationApplication = educationApplicationRepository
.findByIdAndPhoneNumber(applicationId, phoneNumber)
.orElseThrow(() -> new BaseException(Code.EDUCATION_APPLICATION_NOT_FOUND));

educationApplication.getClassGroups().stream()
.filter(group -> group.getId().equals(classGroupId))
.findFirst()
.orElseThrow(() -> new BaseException(Code.EDUCATION_CLASS_GROUP_NOT_FOUND));
classGroup.getEducationApplication().getId().equals(id);

classGroupRepository.deleteById(classGroupId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.DoroServer.domain.lecture.entity.Lecture;
import com.example.DoroServer.domain.lecture.entity.LectureDate;
import com.example.DoroServer.domain.lecture.entity.LectureStatus;
import com.example.DoroServer.domain.lectureContent.dto.LectureContentDto;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -50,7 +49,7 @@ public class CreateLectureReq {
@NotBlank
private String staff; // 강의 스태프 수
@NotBlank
private String mainPayment; //강사 급여
private String mainPayment; // 강사 급여
@NotBlank
private String subPayment;
@NotBlank
Expand All @@ -61,6 +60,8 @@ public class CreateLectureReq {
private String time; // 시간
@NotBlank
private String remark;

@Builder.Default
@NotNull
private List<LocalDate> lectureDates = new ArrayList<>(); // 강의 날짜
@NotNull
Expand Down
Loading