Skip to content

Commit 036b61a

Browse files
authored
Merge pull request #32 from 9oormthon-univ/feature/GOORM-4-comment
Feature/goorm 4 comment
2 parents b48b205 + 901709c commit 036b61a

7 files changed

Lines changed: 30 additions & 45 deletions

File tree

src/main/java/com/goormthon3/team49/common/auth/CorsConfig.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55
import org.springframework.web.cors.CorsConfiguration;
66
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
77
import org.springframework.web.filter.CorsFilter;
8+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
810

911
@Configuration
10-
public class CorsConfig {
11-
12-
@Bean
13-
public CorsFilter corsFilter() {
14-
CorsConfiguration config = new CorsConfiguration();
15-
config.setAllowCredentials(true); // 인증 정보 포함 허용
16-
config.addAllowedOrigin("http://localhost:3000"); // Origin 허용
17-
config.addAllowedMethod("GET");
18-
config.addAllowedMethod("POST");
19-
config.addAllowedMethod("PUT");
20-
config.addAllowedMethod("DELETE");
21-
config.addAllowedMethod("OPTIONS"); // 명시적으로 OPTIONS 메서드 포함
22-
config.addAllowedHeader("Content-Type"); // Content-Type 명시
23-
config.addAllowedHeader("Authorization"); // Authorization 허용
24-
25-
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
26-
source.registerCorsConfiguration("/**", config);
27-
return new CorsFilter(source);
12+
public class CorsConfig implements WebMvcConfigurer {
13+
@Override
14+
public void addCorsMappings(CorsRegistry registry) {
15+
registry.addMapping("/**")
16+
.allowedOriginPatterns("*")
17+
.allowedMethods("GET", "POST", "PUT", "DELETE")
18+
.allowedHeaders("Authorization", "Content-Type")
19+
.exposedHeaders("Custom-Header")
20+
.allowCredentials(true)
21+
.maxAge(3600);
2822
}
23+
2924
}
3025

3126

27+

src/main/java/com/goormthon3/team49/domain/comment/application/CommentService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public class CommentService {
2323
private final UserRepository userRepository;
2424

2525
@Transactional
26-
public CommentResponse createComment(Long product_id, CommentRequest request, User user) {
27-
Comment comment=Comment.create(request.content(),user,product_id);
26+
public CommentResponse createComment(Long product_id, CommentRequest request, String username) {
27+
Comment comment=Comment.create(request.content(),username,product_id);
2828
commentRepository.save(comment);
29-
return CommentResponse.of(comment,user);
29+
return CommentResponse.of(comment);
3030
}
3131

3232
@Transactional

src/main/java/com/goormthon3/team49/domain/comment/domain/Comment.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@ public class Comment extends BaseTimeEntity {
1616

1717
@Id
1818
@GeneratedValue(strategy = IDENTITY)
19-
private Long id;
19+
private Long commentId;
2020

2121
@Column(nullable = false, length = 2000)
2222
private String content;
2323

24-
@ManyToOne
25-
@JoinColumn
26-
private User user;
24+
@Column(nullable = false)
25+
private String username;
2726

2827
@Column(nullable = false)
2928
private Long productId;
3029

3130

32-
public static Comment create(String content, User user, Long product_id) {
31+
public static Comment create(String content, String username, Long product_id) {
3332
return Comment.builder()
3433
.content(content)
35-
.user(user)
34+
.username(username)
3635
.productId(product_id)
3736
.build();
3837
}
39-
4038
}

src/main/java/com/goormthon3/team49/domain/comment/presentation/CommentController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public ResponseEntity<CommentResponse> createReview(
3535

3636
String token = authHeader.substring(7);
3737
Long kakaouserID=userLoginService.getKakaoUserIdFromAccessToken(token);
38-
User user=userLoginService.findUserByFromKakaoUserId(kakaouserID);
39-
CommentResponse response = commentService.createComment(productId, request, user);
38+
String username=userLoginService.findUserByFromKakaoUserId(kakaouserID).getUserName();
39+
CommentResponse response = commentService.createComment(productId, request, username);
4040

4141
return ResponseEntity.status(CREATED).body(response);
4242
}

src/main/java/com/goormthon3/team49/domain/comment/presentation/response/CommentListResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public static CommentListResponse of(Long product_id, Long comment_count, List<C
1515
.product_id(product_id)
1616
.comment_count(comment_count)
1717
.comments(comments.stream()
18-
.map(comment -> CommentResponse.of(comment, comment.getUser())) // User 객체를 제공
19-
.toList())
18+
.map(CommentResponse::of) // CommentResponse.of(comment) -> 이 부분 수정
19+
.toList()) // 끝에 toList()를 제대로 닫기
2020
.build();
2121
}
2222
}
23+

src/main/java/com/goormthon3/team49/domain/comment/presentation/response/CommentResponse.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ public record CommentResponse(
1616
@DateTimeFormat(pattern="yyyy-MM-dd")
1717
String createdAt
1818
) {
19-
public static CommentResponse of(Comment comment, User user) {
19+
public static CommentResponse of(Comment comment) {
2020
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
2121
return CommentResponse.builder()
22-
.comment_id(comment.getId())
23-
.user_id(user.getUserId())
24-
.username(user.getUserName())
22+
.comment_id(comment.getCommentId())
23+
.username(comment.getUsername())
2524
.content(comment.getContent())
2625
.createdAt(comment.getCreatedAt().format(formatter))
2726
.build();

src/main/java/com/goormthon3/team49/domain/user/presentation/UserInfoResponseDto.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ public static class KakaoAccount {
2525
@JsonProperty("profile")
2626
private Profile profile;
2727

28-
@JsonSetter("profile")
29-
public void setProfile(Profile profile) {
30-
if (profile == null) {
31-
this.profile = new Profile(); // 기본값을 설정 (빈 Profile 객체)
32-
} else {
33-
this.profile = profile;
34-
}
35-
}
36-
3728
@Getter
3829
@NoArgsConstructor
3930
@JsonIgnoreProperties(ignoreUnknown = true)

0 commit comments

Comments
 (0)