Skip to content

Commit

Permalink
Merge pull request #19 from angel-bridge/dev
Browse files Browse the repository at this point in the history
bug: scope 에러 수정
  • Loading branch information
sseuldev authored Dec 28, 2024
2 parents ed39b5e + 20128d8 commit 4a94f14
Show file tree
Hide file tree
Showing 23 changed files with 644 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package angel_bridge.angel_bridge_server.domain.education.controller;

import angel_bridge.angel_bridge_server.domain.education.dto.RecommendationProgramResponse;
import angel_bridge.angel_bridge_server.domain.education.dto.response.EducationDetailResponseDto;
import angel_bridge.angel_bridge_server.domain.education.dto.response.EducationResponseDto;
import angel_bridge.angel_bridge_server.domain.education.service.EducationService;
import angel_bridge.angel_bridge_server.global.common.response.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -22,8 +24,49 @@ public class EducationController {

@Operation(summary = "추천 프로그램 조회", description = "3개의 추천 프로그램 조회하는 API")
@GetMapping("/recommendations")
public CommonResponse<List<RecommendationProgramResponse>> getRecommendationProgram() {
public CommonResponse<List<EducationResponseDto>> getRecommendationProgram() {

return new CommonResponse<>(educationService.getRecommendationProgram(), "추천 프로그램 조회에 성공하였습니다.");
}

@Operation(summary = "전체 프로그램 조회", description = "전체 프로그램 조회하는 API")
@GetMapping
public CommonResponse<List<EducationResponseDto>> getAllProgram(@RequestParam(defaultValue = "1") int page) {

return new CommonResponse<>(educationService.getAllProgram(page), "전체 프로그램 조회에 성공하였습니다.");
}

@Operation(summary = "모집 중인 전체 프로그램 조회", description = "모집 중인 전체 프로그램 조회하는 API")
@GetMapping("/ongoing")
public CommonResponse<List<EducationResponseDto>> getAllOngoingProgram(@RequestParam(defaultValue = "1") int page) {

return new CommonResponse<>(educationService.getAllOngoingProgram(page), "모집 중인 전체 프로그램 조회에 성공하였습니다.");
}

@Operation(summary = "모집 예정인 전체 프로그램 조회", description = "모집 예정인 전체 프로그램 조회하는 API")
@GetMapping("/upcoming")
public CommonResponse<List<EducationResponseDto>> getAllUpcomingProgram(@RequestParam(defaultValue = "1") int page) {

return new CommonResponse<>(educationService.getAllUpcomingProgram(page), "모집 예정인 전체 프로그램 조회에 성공하였습니다.");
}

@Operation(summary = "프로그램 상세 페이지 조회", description = "프로그램 상세 페이지를 조회하는 API")
@GetMapping("/{educationId}")
public CommonResponse<EducationDetailResponseDto> getEducationDetail(@PathVariable Long educationId) {

return new CommonResponse<>(educationService.getEducationDetail(educationId), "프로그램 상세 페이지 조회에 성공하였습니다.");
}

@Operation(summary = "프로그램 검색", description = "프로그램 이름 기준 검색하는 API")
@GetMapping("/search")
public CommonResponse<List<EducationResponseDto>> searchEducationByTitle(@RequestParam String keyword, @RequestParam(defaultValue = "1") int page, @Parameter(
examples = {
@ExampleObject(name = "'전체'에서 검색", value = "ALL"),
@ExampleObject(name = "'모집중'에서 검색", value = "ONGOING"),
@ExampleObject(name = "'모집예정'에서 검색", value = "UPCOMING")
}
) @RequestParam(defaultValue = "ALL") String status) {

return new CommonResponse<>(educationService.searchEducationByTitle(keyword, page, status), "해당 keyword에 대한 교육 프로그램 조회에 성공하였습니다.");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package angel_bridge.angel_bridge_server.domain.education.dto.response;

import angel_bridge.angel_bridge_server.domain.education.entity.Education;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.time.LocalDate;

@Builder
public record EducationDetailResponseDto(

@Schema(description = "제목", example = "예비 창업 패키지 2주 완성")
String title,
@Schema(description = "프로그램 소개", example = "21일 간 9개의 미션 수행 및 피드백")
String description,

@Schema(description = "시작날짜", example = "2024-12-16")
LocalDate educationStartDate,

@Schema(description = "종료날짜", example = "2025-01-05")
LocalDate educationEndDate,

@Schema(description = "모집 시작일", example = "2024-12-20")
LocalDate recruitmentStartDate,

@Schema(description = "모집 마감일", example = "2025-01-05")
LocalDate recruitmentEndDate,

@Schema(description = "가격", example = "119,000원")
String price,

@Schema(description = "프리뷰 이미지", example = "프리뷰 이미지 url")
String preFile,

@Schema(description = "디테일 이미지", example = "디테일 이미지 url")
String detailFile

) {

public static EducationDetailResponseDto from(Education education, String preImage, String detailImage) {

return EducationDetailResponseDto.builder()
.title(education.getEducationTitle())
.description(education.getEducationDescription())
.educationStartDate(education.getEducationStartDate())
.educationEndDate(education.getEducationEndDate())
.recruitmentStartDate(education.getRecruitmentStartDate())
.recruitmentEndDate(education.getRecruitmentEndDate())
.price(education.getPrice())
.preFile(preImage)
.detailFile(detailImage)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package angel_bridge.angel_bridge_server.domain.education.dto.response;

import angel_bridge.angel_bridge_server.domain.education.entity.Education;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
public record EducationResponseDto(

@Schema(description = "프로그램 id", example = "1")
Long educationId,

@Schema(description = "프리뷰 이미지", example = "프리뷰 이미지 url")
String preImage,

@Schema(description = "프로그램 소개", example = "21일 간 9개의 미션 수행 및 피드백")
String description,

@Schema(description = "제목", example = "예비 창업 패키지 2주 완성")
String title,

@Schema(description = "모집 여부", example = "모집중 | 모집예정 | 모집종료")
String recruitmentStatus
) {

public static EducationResponseDto from(Education education, String preImage) {
return EducationResponseDto.builder()
.educationId(education.getId())
.preImage(preImage)
.description(education.getEducationDescription())
.title(education.getEducationTitle())
.recruitmentStatus(education.getRecruitmentStatus().getDescription())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package angel_bridge.angel_bridge_server.domain.education.service;

import angel_bridge.angel_bridge_server.domain.education.dto.RecommendationProgramResponse;
import angel_bridge.angel_bridge_server.domain.education.dto.response.EducationDetailResponseDto;
import angel_bridge.angel_bridge_server.domain.education.dto.request.AdminEducationRequestDto;
import angel_bridge.angel_bridge_server.domain.education.dto.response.AdminEducationResponseDto;
import angel_bridge.angel_bridge_server.domain.education.dto.response.EducationResponseDto;
import angel_bridge.angel_bridge_server.domain.education.entity.Education;
import angel_bridge.angel_bridge_server.domain.education.entity.RecruitmentStatus;
import angel_bridge.angel_bridge_server.global.exception.ApplicationException;
import angel_bridge.angel_bridge_server.global.repository.EducationRepository;
import angel_bridge.angel_bridge_server.global.s3.service.ImageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
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.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static angel_bridge.angel_bridge_server.global.exception.ExceptionCode.IMAGE_UPLOAD_ERROR;
import static angel_bridge.angel_bridge_server.global.exception.ExceptionCode.NOT_FOUND_EDUCATION_ID;
import static angel_bridge.angel_bridge_server.global.exception.ExceptionCode.*;

@Service
@Slf4j
Expand All @@ -32,7 +33,7 @@ public class EducationService {
private final EducationRepository educationRepository;

// [GET] 일반 사용자 추천 교육 프로그램 조회
public List<RecommendationProgramResponse> getRecommendationProgram() {
public List<EducationResponseDto> getRecommendationProgram() {

// 모집 중인 프로그램 (마감 기간이 가까운 순으로 정렬)
List<Education> ongoingEducations
Expand All @@ -43,19 +44,19 @@ public List<RecommendationProgramResponse> getRecommendationProgram() {
= educationRepository.findEducationsByStatus(RecruitmentStatus.UPCOMING);

// 모집 중인 프로그램에서 최대 3개 선택
List<RecommendationProgramResponse> responses = ongoingEducations.stream()
List<EducationResponseDto> responses = ongoingEducations.stream()
.limit(3)
.map(education -> RecommendationProgramResponse.from(
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())
))
.collect(Collectors.toList());

// 모집 중인 프로그램에서 부족한 경우, 모집 예정인 프로그램에서 추가 선택
int remaining = 3 - responses.size();
if (remaining > 0) {
List<RecommendationProgramResponse> upcomingResponses = upcomingEducations.stream()
List<EducationResponseDto> upcomingResponses = upcomingEducations.stream()
.limit(remaining)
.map(education -> RecommendationProgramResponse.from(
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())
))
.toList();
Expand Down Expand Up @@ -144,4 +145,84 @@ public void deleteEducation(Long educationId) {

educationRepository.delete(education);
}

// [GET] 일반 사용자 전체 프로그램 조회
public List<EducationResponseDto> getAllProgram(int page) {

if (page == 0)
throw new ApplicationException(BAD_REQUEST_ERROR);
Pageable pageable = PageRequest.of(page - 1, 12);

return educationRepository.findAll(pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();
}

// [GET] 일반 사용자 모집 중인 전체 프로그램 조회
public List<EducationResponseDto> getAllOngoingProgram(int page) {

if (page == 0)
throw new ApplicationException(BAD_REQUEST_ERROR);
Pageable pageable = PageRequest.of(page - 1, 12);

return educationRepository.findByRecruitmentStatusAndDeletedAtIsNull(RecruitmentStatus.ONGOING, pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();
}

// [GET] 일반 사용자 모집 예정인 전체 프로그램 조회
public List<EducationResponseDto> getAllUpcomingProgram(int page) {

if (page == 0)
throw new ApplicationException(BAD_REQUEST_ERROR);
Pageable pageable = PageRequest.of(page - 1, 12);

return educationRepository.findByRecruitmentStatusAndDeletedAtIsNull(RecruitmentStatus.UPCOMING, pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();
}

// [GET] 일반 사용자 프로그램 상세 페이지 조회
public EducationDetailResponseDto getEducationDetail(Long educationId) {

Education education = findEducationById(educationId);
return EducationDetailResponseDto.from(education, education.getEducationPreImage(), education.getEducationDetailImage());
}

// [GET] 프로그램 검색 조회
public List<EducationResponseDto> searchEducationByTitle(String keyword, int page, String status) {

if (page == 0)
throw new ApplicationException(BAD_REQUEST_ERROR);

Pageable pageable = PageRequest.of(page - 1, 12);

// 1. 전체 리스트에서 검색하는 경우
if (status.equals("ALL")) {
return educationRepository.findByTitle(keyword, pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();

// 2. 모집중인 리스트에서 검색하는 경우
} else if (status.equals("ONGOING")) {
return educationRepository.findByTitleAndStatus(keyword, RecruitmentStatus.ONGOING, pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();

// 3. 모집예정인 리스트에서 검색하는 경우
} else if (status.equals("UPCOMING")) {
return educationRepository.findByTitleAndStatus(keyword, RecruitmentStatus.UPCOMING, pageable)
.map(education -> EducationResponseDto.from(
education, imageService.getImageUrl(education.getEducationPreImage())))
.stream().toList();

} else {
throw new ApplicationException(BAD_REQUEST_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package angel_bridge.angel_bridge_server.domain.member.controller;

import angel_bridge.angel_bridge_server.domain.member.dto.request.AuthRequestDto;
import angel_bridge.angel_bridge_server.domain.member.dto.response.MemberResponseDto;
import angel_bridge.angel_bridge_server.domain.member.service.AuthService;
import angel_bridge.angel_bridge_server.global.common.response.CommonResponse;
import angel_bridge.angel_bridge_server.global.jwt.JWTUtil;
import angel_bridge.angel_bridge_server.global.oauth2.dto.CustomOAuth2User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/auth")
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor
@Tag(name = "Auth", description = "카카오 소셜로그인 관련 API")
@Tag(name = "Auth", description = "인증 관련 API")
public class AuthController {

private final AuthService authService;
private final JWTUtil jwtUtil;

@PostMapping("/reissue")
@Operation(summary = "토큰 재발급", description = "토큰 재발급 요청 API")
Expand All @@ -34,6 +38,15 @@ public CommonResponse<Void> reissue(HttpServletRequest request, HttpServletRespo

authService.setNewTokens(response, newAccessToken, RefreshTokenCookie);

return new CommonResponse<>("토근 재발급을 성공하였습니다");
return new CommonResponse<>("토큰 재발급을 성공하였습니다");
}

@PostMapping("/signup")
@Operation(summary = "회원가입 정보 입력", description = "회원가입 시 초기 정보 입력 받는 API")
public CommonResponse<MemberResponseDto> saveMemberInfo(@AuthenticationPrincipal CustomOAuth2User userDetails, @Valid @RequestBody AuthRequestDto request) {

Long memberId = userDetails.getMemberId();

return new CommonResponse<>(authService.saveMemberInfo(request, memberId), "사용자 추가 정보 입력을 성공하였습니다.");
}
}
Loading

0 comments on commit 4a94f14

Please sign in to comment.