Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import swyp_8th.bungmakase_backend.config.JwtConfig;
import swyp_8th.bungmakase_backend.domain.BungDogam;
import swyp_8th.bungmakase_backend.domain.UserBungDogam;
Expand All @@ -17,6 +18,7 @@
import swyp_8th.bungmakase_backend.globals.response.ResponseTemplate;
import swyp_8th.bungmakase_backend.repository.UserBungDogamRepository;
import swyp_8th.bungmakase_backend.service.BungDogamService;
import swyp_8th.bungmakase_backend.service.FileStorageService;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -30,6 +32,7 @@ public class BungDogamController {

private final BungDogamService bungDogamService;
private final JwtConfig jwtConfig;
private final FileStorageService fileStorageService;

@GetMapping("/list")
public ResponseEntity<ResponseTemplate<List<BungListResponseDto>>> getAllBungDogam() {
Expand Down Expand Up @@ -120,6 +123,31 @@ public ResponseEntity<ResponseTemplate<BungResponseDto>> getBungDogam(
}
}

@PostMapping(value = "/upload", consumes = {"multipart/form-data"})
public ResponseEntity<ResponseTemplate<Map<String, String>>> uploadImage(@RequestPart("image") MultipartFile image) {

if (image.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ResponseTemplate<>(FailureCode.BAD_REQUEST_400, null));
}

try {
// S3에 이미지 업로드
String imageUrl = fileStorageService.uploadFile(image);

Map<String, String> responseData = new HashMap<>();
responseData.put("imageUrl", imageUrl);

return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseTemplate<>(SuccessCode.SUCCESS_200, responseData));

} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ResponseTemplate<>(FailureCode.SERVER_ERROR_500, null));
}
}


/*@Operation(
summary = "유저 붕어빵 도감 추가용 임시 API",
description = "특정 유저의 붕어빵 도감에 새로운 붕어빵을 추가 (bungId는 1~11)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import jdk.jfr.Registered;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import swyp_8th.bungmakase_backend.domain.Users;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -32,4 +35,9 @@ public interface UserRepository extends JpaRepository<Users, UUID> {

List<Users> findTop3ByOrderByLevelDescRecentCountDesc();

@Transactional
@Modifying
@Query("UPDATE Users u SET u.recentCount = 0")
void resetRecentCounts();

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void addDailyBungLog(UUID userId, BungLogRequestDto bungLogData, List<Mul

user.setBungCount(user.getBungCount() + bungLogData.getBungCount());
user.setRecentCount(user.getRecentCount() + bungLogData.getBungCount());
user.setLevel((calculateUserLevel(user.getBungCount())));

// 2. 붕 도감에서 붕어빵 찾기
BungDogam bung = bungDogamRepository.findByBungName(bungLogData.getBungName())
Expand Down Expand Up @@ -107,6 +108,19 @@ public void addDailyBungLog(UUID userId, BungLogRequestDto bungLogData, List<Mul
}
}

public long calculateUserLevel(long bungCount) {
if (bungCount >= 350) return 10L;
if (bungCount >= 250) return 9L;
if (bungCount >= 170) return 8L;
if (bungCount >= 120) return 7L;
if (bungCount >= 80) return 6L;
if (bungCount >= 50) return 5L;
if (bungCount >= 30) return 4L;
if (bungCount >= 14) return 3L;
if (bungCount >= 7) return 2L;
return 1L;
}

@Transactional
public void suggestBung(SuggestBungRequest request) {
// 입력값 검증
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ public class FileStorageService {

// 파일 업로드 및 URL 반환
public String uploadFile(MultipartFile file) {
// String fileName = file.getOriginalFilename();
//
// try {
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setContentLength(file.getSize()); // 파일 크기 설정
// metadata.setContentType(file.getContentType()); // MIME 타입 설정
//
// amazonS3.putObject(
// new PutObjectRequest(bucket, fileName, file.getInputStream(), metadata) // metadata 적용
// .withCannedAcl(CannedAccessControlList.PublicRead) // 퍼블릭 읽기 권한 부여
// );
//
// return amazonS3.getUrl(bucket, fileName).toString();
// } catch (IOException e) {
// throw new RuntimeException("파일 업로드 중 오류가 발생했습니다.", e);
// }

try {
String fileName = file.getOriginalFilename();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import swyp_8th.bungmakase_backend.config.JwtConfig;
Expand Down Expand Up @@ -37,6 +38,14 @@ public class ProfileService {
private final UserBungImageRepository userBungImageRepository;


// 모든 유저의 recentCount 일주일마다 초기화
@Scheduled(cron = "0 0 0 * * MON", zone = "Asia/Seoul")
public void resetRecentCounts() {

userRepository.resetRecentCounts();

}



public UserProfileResponseDto getProfile(String token) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ ncp:


server:
port: 443
ssl:
key-store: classpath:keystore.p12
key-store-password: bungmakase
key-store-type: PKCS12
enabled: true
tomcat:
threads:
max: 200 # 최대 스레드 수
min-spare: 20 # 최소 대기 스레드 수
port: 8080
# ssl:
# key-store: classpath:keystore.p12
# key-store-password: bungmakase
# key-store-type: PKCS12
# enabled: true
# tomcat:
# threads:
# max: 200 # 최대 스레드 수
# min-spare: 20 # 최소 대기 스레드 수