Skip to content

Commit eef549c

Browse files
authored
Merge pull request #92 from FixLog/develop
Develop
2 parents 95f8275 + dcd2feb commit eef549c

11 files changed

Lines changed: 53 additions & 11 deletions

File tree

src/main/java/com/example/FixLog/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3737
.requestMatchers(HttpMethod.GET, "/members/check-nickname").permitAll()
3838
.requestMatchers(HttpMethod.GET, "/", "/main", "/main/**").permitAll()
3939
.requestMatchers(HttpMethod.GET, "/posts/**").permitAll()
40+
.requestMatchers(HttpMethod.GET, "/tags").permitAll()
41+
.requestMatchers("/api/s3/**").permitAll()
4042
// h2-console (로컬 테스트용)
4143
.requestMatchers(HttpMethod.GET, "/h2-console/**").permitAll()
4244
// 배포 확인용 임시 허용

src/main/java/com/example/FixLog/controller/AuthController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import com.example.FixLog.dto.Response;
44
import com.example.FixLog.dto.member.LoginRequestDto;
55
import com.example.FixLog.dto.member.LoginResponseDto;
6+
import com.example.FixLog.exception.ErrorCode;
67
import com.example.FixLog.service.AuthService;
8+
import jakarta.servlet.http.HttpServletRequest;
79
import lombok.RequiredArgsConstructor;
810
import org.springframework.http.ResponseEntity;
911
import org.springframework.web.bind.annotation.*;
@@ -20,4 +22,18 @@ public ResponseEntity<Response<LoginResponseDto>> login(@RequestBody LoginReques
2022
LoginResponseDto result = authService.login(requestDto);
2123
return ResponseEntity.ok(Response.success("로그인 성공", result));
2224
}
25+
26+
@PostMapping("/logout")
27+
public ResponseEntity<Response<String>> logout(HttpServletRequest request) {
28+
String token = request.getHeader("Authorization");
29+
30+
if (token != null && token.startsWith("Bearer ")) {
31+
return ResponseEntity.ok(Response.success("로그아웃 완료. 클라이언트에서 토큰을 삭제하세요.", null));
32+
} else {
33+
return ResponseEntity
34+
.badRequest()
35+
.body(Response.fail(ErrorCode.UNAUTHORIZED.getMessage()));
36+
}
37+
}
38+
2339
}

src/main/java/com/example/FixLog/controller/MypageMemberController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import jakarta.validation.Valid;
1717
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1818
import org.springframework.web.bind.annotation.*;
19+
import com.example.FixLog.dto.s3.PresignedUploadResponseDto;
20+
1921

2022
import java.util.Map;
2123

@@ -55,9 +57,9 @@ public ResponseEntity<Response<PresignResponseDto>> presignProfileImage(
5557
) {
5658
if (member == null) throw new CustomException(ErrorCode.UNAUTHORIZED);
5759

58-
String key = s3Service.generateKey("profile", filename);
59-
String uploadUrl = s3Service.generatePresignedUrl("profile", filename, 15);
60-
String fileUrl = s3Service.getObjectUrl(key);
60+
PresignedUploadResponseDto responseDto = s3Service.generatePresignedUploadUrl("profile", filename, 15);
61+
String uploadUrl = responseDto.getPresignedUrl();
62+
String fileUrl = responseDto.getFileUrl();
6163

6264
PresignResponseDto dto = new PresignResponseDto(uploadUrl, fileUrl);
6365
return ResponseEntity.ok(Response.success("Presigned URL 발급 성공", dto));
@@ -86,4 +88,4 @@ public ResponseEntity<Response<String>> editBio(
8688
memberService.editBio(member, requestDto.getBio());
8789
return ResponseEntity.ok(Response.success("소개글 수정 성공", "SUCCESS"));
8890
}
89-
}
91+
}

src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public class MyPostPageResponseDto {
2222
private LocalDateTime createdAt;
2323
private int likeCount;
2424
private int forkCount;
25+
private String nickname;
2526

2627
public static MyPostPageResponseDto from(Post post, int forkCount) {
2728
return MyPostPageResponseDto.builder()
2829
.postId(post.getPostId())
30+
.nickname(post.getUserId().getNickname())
2931
.postTitle(post.getPostTitle())
3032
.postSummary(generateSummary(post.getProblem()))
3133
.imageUrl(post.getCoverImage())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.FixLog.dto.s3;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@Getter
7+
@AllArgsConstructor
8+
public class PresignedUploadResponseDto {
9+
private String presignedUrl; // PUT 요청용 presigned URL
10+
private String fileUrl; // 업로드 완료 후 접근 가능한 S3 URL
11+
}
12+

src/main/java/com/example/FixLog/exception/ErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public enum ErrorCode {
1010
USER_NICKNAME_NOT_FOUND(HttpStatus.NOT_FOUND,"존재하지 않는 사용자 아이디입니다."),
1111
USER_EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "회원 이메일을 찾을 수 없습니다."),
12+
USER_DELETED(HttpStatus.FORBIDDEN, "탈퇴한 회원입니다."),
1213
EMAIL_DUPLICATED(HttpStatus.CONFLICT, "중복된 이메일입니다"),
1314
NICKNAME_DUPLICATED(HttpStatus.CONFLICT, "중복된 닉네임입니다"),
1415
ALREADY_FOLLOWING(HttpStatus.CONFLICT, "이미 팔로우 중입니다"),
@@ -29,7 +30,8 @@ public enum ErrorCode {
2930
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "권한이 없습니다."),
3031
INVALID_REQUEST(HttpStatus.BAD_REQUEST, "요청 데이터가 유효하지 않습니다."),
3132
S3_UPLOAD_FAILED(HttpStatus.BAD_REQUEST, "S3 파일 업로드에 실패했습니다."),
32-
IMAGE_UPLOAD_FAILED(HttpStatus.NOT_FOUND, "이미지 파일이 업로드되지 않았습니다.");
33+
IMAGE_UPLOAD_FAILED(HttpStatus.NOT_FOUND, "이미지 파일이 업로드되지 않았습니다."),
34+
LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃이 정상적으로 처리되었습니다.");
3335

3436
private final HttpStatus status;
3537
private final String message;

src/main/java/com/example/FixLog/service/AuthService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public LoginResponseDto login(LoginRequestDto requestDto) {
2626
Member member = memberRepository.findByEmail(requestDto.getEmail())
2727
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));
2828

29+
if (member.getIsDeleted()) {
30+
throw new CustomException(ErrorCode.USER_DELETED);
31+
}
32+
2933
if (!passwordEncoder.matches(requestDto.getPassword(), member.getPassword())) {
3034
throw new CustomException(ErrorCode.INVALID_PASSWORD);
3135
}

src/main/java/com/example/FixLog/service/MainPageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MainPageService(PostRepository postRepository, MemberService memberServic
3030
// 이미지 null일 때 default 사진으로 변경 (프로필 사진,
3131
public String getDefaultImage(String image){
3232
String imageUrl = (image == null || image.isBlank())
33-
? "https://example.com/default-cover-image.png" : image;
33+
? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" : image;
3434
System.out.println(imageUrl);
3535
return imageUrl;
3636
}

src/main/java/com/example/FixLog/service/PostService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public PostService(PostRepository postRepository, PostLikeRepository postLikeRep
5757
// 이미지 null일 때 default 사진으로 변경 (프로필 사진,
5858
public String getDefaultImage(String image){
5959
String imageUrl = (image == null || image.isBlank())
60-
? "https://example.com/default-cover-image.png" : image;
60+
? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" : image;
6161
System.out.println(imageUrl);
6262
return imageUrl;
6363
}

src/main/java/com/example/FixLog/service/S3Service.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.amazonaws.services.s3.AmazonS3;
55
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
66
import com.amazonaws.services.s3.model.ObjectMetadata;
7+
import com.example.FixLog.dto.s3.PresignedUploadResponseDto;
78
import com.example.FixLog.exception.CustomException;
89
import com.example.FixLog.exception.ErrorCode;
910
import lombok.RequiredArgsConstructor;
@@ -46,7 +47,7 @@ public String generateKey(String dirName, String filename) {
4647
return dirName + "/" + UUID.randomUUID() + "_" + filename;
4748
}
4849

49-
public String generatePresignedUrl(String dirName, String filename, int minutes) {
50+
public PresignedUploadResponseDto generatePresignedUploadUrl(String dirName, String filename, int minutes) {
5051
String key = generateKey(dirName, filename);
5152
Date expiration = new Date(System.currentTimeMillis() + minutes * 60L * 1000L);
5253

@@ -55,10 +56,11 @@ public String generatePresignedUrl(String dirName, String filename, int minutes)
5556
.withExpiration(expiration);
5657

5758
URL url = amazonS3.generatePresignedUrl(request);
58-
return url.toString();
59+
60+
return new PresignedUploadResponseDto(url.toString(), getObjectUrl(key));
5961
}
6062

6163
public String getObjectUrl(String key) {
6264
return amazonS3.getUrl(bucket, key).toString();
6365
}
64-
}
66+
}

0 commit comments

Comments
 (0)