Skip to content

Commit

Permalink
Merge pull request #166 from SMU-SATTO/feature/#21
Browse files Browse the repository at this point in the history
✨ feat: 사진 업로드 관련 S3 환경 및 설정 수정, 이벤트 도메인 API 오류 수정
  • Loading branch information
chamm99 authored Jul 21, 2024
2 parents 779604b + 62ae9a9 commit 764dd32
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 362 deletions.
5 changes: 0 additions & 5 deletions src/main/java/com/example/satto/S3/FileFolder.java

This file was deleted.

68 changes: 0 additions & 68 deletions src/main/java/com/example/satto/S3/service/FileUploadService.java

This file was deleted.

60 changes: 0 additions & 60 deletions src/main/java/com/example/satto/config/OpenApiConfig.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/com/example/satto/config/S3Component.java

This file was deleted.

42 changes: 32 additions & 10 deletions src/main/java/com/example/satto/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.example.satto.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import jakarta.annotation.PostConstruct;
import lombok.Getter;

@Configuration
@Getter
public class S3Config {

private AWSCredentials awsCredentials;

@Value("${cloud.aws.credentials.access-Key}")
private String accessKey;

Expand All @@ -20,14 +29,27 @@ public class S3Config {
@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3Client amazonS3Client() {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
@Value("${cloud.aws.s3.bucket}")
private String bucket;

@Value("${cloud.aws.s3.folder.folderName1}")
private String path;

@PostConstruct
public void init() {
this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
}

return (AmazonS3Client) AmazonS3ClientBuilder
.standard()
@Bean
public AmazonS3 amazonS3() {
return AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}

@Bean
public AWSCredentialsProvider awsCredentialsProvider() {
return new AWSStaticCredentialsProvider(awsCredentials);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public BaseResponse<String> deletePhotoContest(
return BaseResponse.onSuccess(eventService.deletePhotoContest(photoContestId, user));
}

// @Operation(method = "POST", summary = "사진 콘테스트: 사진 업로드", description = "사진 콘테스트 참여")
// @PostMapping(consumes = "multipart/form-data")
// public BaseResponse<PhotoContestResponseDto> joinPhotoContest(
// @RequestParam("file")MultipartFile multipartFile,
// @AuthenticationPrincipal Users user
// ) throws IOException {
// return BaseResponse.onSuccess(eventService.joinPhotoContest(multipartFile, user));
// }
@Operation(method = "POST", summary = "사진 콘테스트: 사진 업로드", description = "사진 콘테스트 참여")
@PostMapping(consumes = "multipart/form-data")
public BaseResponse<PhotoContestResponseDto.SavedPhotoContest> joinPhotoContest(
@RequestParam("file")MultipartFile multipartFile,
@AuthenticationPrincipal Users user
) throws IOException {
return BaseResponse.onSuccess(eventService.joinPhotoContest(multipartFile, user));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.satto.domain.event.controller;

import com.example.satto.domain.event.dto.PhotoContestListResponseDto;
import com.example.satto.domain.event.dto.PhotoContestResponseDto;
import com.example.satto.domain.event.dto.TimetableContestListResponseDto;
import com.example.satto.domain.event.dto.TimetableContestResponseDto;
import com.example.satto.domain.event.service.EventService;
import com.example.satto.domain.users.entity.Users;
import com.example.satto.global.common.BaseResponse;
Expand All @@ -10,6 +12,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -53,4 +58,12 @@ public BaseResponse<String> deletePhotoContest(
) {
return BaseResponse.onSuccess(eventService.deleteTimetableContest(timetableContestId, user));
}
@Operation(method = "POST", summary = "시간표 경진 대회: 사진 업로드", description = "시간표 경진 대회 참여")
@PostMapping(consumes = "multipart/form-data")
public BaseResponse<TimetableContestResponseDto.SavedTimetableContest> joinTimetableContest(
@RequestParam("file") MultipartFile multipartFile,
@AuthenticationPrincipal Users user
) throws IOException {
return BaseResponse.onSuccess(eventService.joinTimetableContest(multipartFile, user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ public record PhotoContestResponseDto(
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
@Builder
public record SavedPhotoContest(
String name,
String photo,
Long likeCount,
Long dislikeCount,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.satto.domain.event.dto;

import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record TimetableContestResponseDto(
Long timetableContestId,
String name,
Expand All @@ -11,4 +14,13 @@ public record TimetableContestResponseDto(
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
@Builder
public record SavedTimetableContest(
String name,
String photo,
Long likeCount,
Long dislikeCount,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface EventRepository extends JpaRepository<Event, Long>, EventRepositoryCustom {
Optional<Event> findByCategory(String photoContest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.example.satto.domain.users.entity.QUsers;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -27,24 +28,23 @@ public List<TimetableContestResponseDto> findAllTimetableContest() {
QTimetableContestDislike timetableContestDislike = QTimetableContestDislike.timetableContestDislike;
QUsers user = QUsers.users;

return null;
// return queryFactory
// .select(Projections.constructor(TimetableContestResponseDto.class,
// timetableContest.timetableContestId,
// user.name,
// timetableContest.photoImg,
// Expressions.as(JPAExpressions
// .select(timetableContestLike.count())
// .from(timetableContestLike)
// .where(timetableContestLike.timetableContest.eq(timetableContest)), "likeCount"),
// Expressions.as(JPAExpressions
// .select(timetableContestDislike.count())
// .from(timetableContestDislike)
// .where(timetableContestDislike.timetableContest.eq(timetableContest)), "dislikeCount"),
// timetableContest.createdAt,
// timetableContest.updatedAt))
// .from(timetableContest)
// .leftJoin(timetableContest.user, user)
// .fetchAll();
return queryFactory
.select(Projections.constructor(TimetableContestResponseDto.class,
timetableContest.timetableContestId,
user.name,
timetableContest.photoImg,
Expressions.as(JPAExpressions
.select(timetableContestLike.count())
.from(timetableContestLike)
.where(timetableContestLike.timetableContest.eq(timetableContest)), "likeCount"),
Expressions.as(JPAExpressions
.select(timetableContestDislike.count())
.from(timetableContestDislike)
.where(timetableContestDislike.timetableContest.eq(timetableContest)), "dislikeCount"),
timetableContest.createdAt,
timetableContest.updatedAt))
.from(timetableContest)
.leftJoin(timetableContest.user, user)
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface EventService {

String deleteTimetableContest(Long timetableContestId, Users user);

// TODO 사진 업로드 관련 기능
//PhotoContestResponseDto joinPhotoContest(MultipartFile multipartFile, Users user);
//TimetableContestResponseDto joinTimetableContest(MultipartFile multipartFile, Users user);
TimetableContestResponseDto.SavedTimetableContest joinTimetableContest(MultipartFile multipartFile, Users user);

PhotoContestResponseDto.SavedPhotoContest joinPhotoContest(MultipartFile multipartFile, Users user);
}
Loading

0 comments on commit 764dd32

Please sign in to comment.