Skip to content

Commit 764dd32

Browse files
authored
Merge pull request #166 from SMU-SATTO/feature/#21
✨ feat: 사진 업로드 관련 S3 환경 및 설정 수정, 이벤트 도메인 API 오류 수정
2 parents 779604b + 62ae9a9 commit 764dd32

22 files changed

+245
-362
lines changed

src/main/java/com/example/satto/S3/FileFolder.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/com/example/satto/S3/service/FileUploadService.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/com/example/satto/config/OpenApiConfig.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/java/com/example/satto/config/S3Component.java

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package com.example.satto.config;
22

3-
import com.amazonaws.auth.AWSStaticCredentialsProvider;
4-
import com.amazonaws.auth.BasicAWSCredentials;
5-
import com.amazonaws.services.s3.AmazonS3Client;
6-
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
73
import org.springframework.beans.factory.annotation.Value;
84
import org.springframework.context.annotation.Bean;
95
import org.springframework.context.annotation.Configuration;
106

7+
import com.amazonaws.auth.AWSCredentials;
8+
import com.amazonaws.auth.AWSCredentialsProvider;
9+
import com.amazonaws.auth.AWSStaticCredentialsProvider;
10+
import com.amazonaws.auth.BasicAWSCredentials;
11+
import com.amazonaws.services.s3.AmazonS3;
12+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
13+
14+
import jakarta.annotation.PostConstruct;
15+
import lombok.Getter;
16+
1117
@Configuration
18+
@Getter
1219
public class S3Config {
1320

21+
private AWSCredentials awsCredentials;
22+
1423
@Value("${cloud.aws.credentials.access-Key}")
1524
private String accessKey;
1625

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

23-
@Bean
24-
public AmazonS3Client amazonS3Client() {
25-
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
32+
@Value("${cloud.aws.s3.bucket}")
33+
private String bucket;
34+
35+
@Value("${cloud.aws.s3.folder.folderName1}")
36+
private String path;
37+
38+
@PostConstruct
39+
public void init() {
40+
this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
41+
}
2642

27-
return (AmazonS3Client) AmazonS3ClientBuilder
28-
.standard()
43+
@Bean
44+
public AmazonS3 amazonS3() {
45+
return AmazonS3ClientBuilder.standard()
2946
.withRegion(region)
30-
.withCredentials(new AWSStaticCredentialsProvider(credentials))
47+
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
3148
.build();
3249
}
50+
51+
@Bean
52+
public AWSCredentialsProvider awsCredentialsProvider() {
53+
return new AWSStaticCredentialsProvider(awsCredentials);
54+
}
3355
}

src/main/java/com/example/satto/domain/event/controller/PhotoContestController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public BaseResponse<String> deletePhotoContest(
5858
return BaseResponse.onSuccess(eventService.deletePhotoContest(photoContestId, user));
5959
}
6060

61-
// @Operation(method = "POST", summary = "사진 콘테스트: 사진 업로드", description = "사진 콘테스트 참여")
62-
// @PostMapping(consumes = "multipart/form-data")
63-
// public BaseResponse<PhotoContestResponseDto> joinPhotoContest(
64-
// @RequestParam("file")MultipartFile multipartFile,
65-
// @AuthenticationPrincipal Users user
66-
// ) throws IOException {
67-
// return BaseResponse.onSuccess(eventService.joinPhotoContest(multipartFile, user));
68-
// }
61+
@Operation(method = "POST", summary = "사진 콘테스트: 사진 업로드", description = "사진 콘테스트 참여")
62+
@PostMapping(consumes = "multipart/form-data")
63+
public BaseResponse<PhotoContestResponseDto.SavedPhotoContest> joinPhotoContest(
64+
@RequestParam("file")MultipartFile multipartFile,
65+
@AuthenticationPrincipal Users user
66+
) throws IOException {
67+
return BaseResponse.onSuccess(eventService.joinPhotoContest(multipartFile, user));
68+
}
6969
}

src/main/java/com/example/satto/domain/event/controller/TimetableContestController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.example.satto.domain.event.controller;
22

33
import com.example.satto.domain.event.dto.PhotoContestListResponseDto;
4+
import com.example.satto.domain.event.dto.PhotoContestResponseDto;
45
import com.example.satto.domain.event.dto.TimetableContestListResponseDto;
6+
import com.example.satto.domain.event.dto.TimetableContestResponseDto;
57
import com.example.satto.domain.event.service.EventService;
68
import com.example.satto.domain.users.entity.Users;
79
import com.example.satto.global.common.BaseResponse;
@@ -10,6 +12,9 @@
1012
import lombok.RequiredArgsConstructor;
1113
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1214
import org.springframework.web.bind.annotation.*;
15+
import org.springframework.web.multipart.MultipartFile;
16+
17+
import java.io.IOException;
1318

1419
@RestController
1520
@RequiredArgsConstructor
@@ -53,4 +58,12 @@ public BaseResponse<String> deletePhotoContest(
5358
) {
5459
return BaseResponse.onSuccess(eventService.deleteTimetableContest(timetableContestId, user));
5560
}
61+
@Operation(method = "POST", summary = "시간표 경진 대회: 사진 업로드", description = "시간표 경진 대회 참여")
62+
@PostMapping(consumes = "multipart/form-data")
63+
public BaseResponse<TimetableContestResponseDto.SavedTimetableContest> joinTimetableContest(
64+
@RequestParam("file") MultipartFile multipartFile,
65+
@AuthenticationPrincipal Users user
66+
) throws IOException {
67+
return BaseResponse.onSuccess(eventService.joinTimetableContest(multipartFile, user));
68+
}
5669
}

src/main/java/com/example/satto/domain/event/dto/PhotoContestResponseDto.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ public record PhotoContestResponseDto(
1414
LocalDateTime createdAt,
1515
LocalDateTime updatedAt
1616
) {
17+
@Builder
18+
public record SavedPhotoContest(
19+
String name,
20+
String photo,
21+
Long likeCount,
22+
Long dislikeCount,
23+
LocalDateTime createdAt,
24+
LocalDateTime updatedAt
25+
) {}
1726
}

src/main/java/com/example/satto/domain/event/dto/TimetableContestResponseDto.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.example.satto.domain.event.dto;
22

3+
import lombok.Builder;
4+
35
import java.time.LocalDateTime;
46

7+
@Builder
58
public record TimetableContestResponseDto(
69
Long timetableContestId,
710
String name,
@@ -11,4 +14,13 @@ public record TimetableContestResponseDto(
1114
LocalDateTime createdAt,
1215
LocalDateTime updatedAt
1316
) {
17+
@Builder
18+
public record SavedTimetableContest(
19+
String name,
20+
String photo,
21+
Long likeCount,
22+
Long dislikeCount,
23+
LocalDateTime createdAt,
24+
LocalDateTime updatedAt
25+
) {}
1426
}

src/main/java/com/example/satto/domain/event/repository/EventRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

7+
import java.util.Optional;
8+
79
@Repository
810
public interface EventRepository extends JpaRepository<Event, Long>, EventRepositoryCustom {
11+
Optional<Event> findByCategory(String photoContest);
912
}

0 commit comments

Comments
 (0)