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
18 changes: 18 additions & 0 deletions src/main/java/com/example/prdoit/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Watchable;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://prdoit-s3-bucket.s3-website.ap-northeast-2.amazonaws.com")
.allowedMethods("GET", "POST", "PUT", "DELETE");
}
}
81 changes: 81 additions & 0 deletions src/main/java/com/example/prdoit/controller/ContentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.example.prdoit.controller;

import com.example.prdoit.dto.content.ContentRequestDto;
import com.example.prdoit.dto.content.ContentUpdateDto;
import com.example.prdoit.exception.CustomException;
import com.example.prdoit.service.content.ContentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("/content")
@RequiredArgsConstructor
public class ContentController {

private final ContentService contentService;

@GetMapping()
public ResponseEntity<Object> getAllContent(@RequestParam(value = "query", required = false, defaultValue = "all") String query,
@RequestParam(value = "level", required = false, defaultValue = "-1") int level,
@RequestParam(value = "size", required = false, defaultValue = "5") int size,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
try{
if(level == -1){
return ResponseEntity.ok(contentService.getContentQuery(query, size, page));
} else {
return ResponseEntity.ok(contentService.getContentQueryWithLevel(query, level, size, page));
}
} catch (CustomException e) {
log.error("[getAllContent] 컨텐츠 조회 실패", e);
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
log.error("[getAllContent] 컨텐츠 조회 실패", e);
return ResponseEntity.internalServerError().body("컨텐츠 조회에 실패했습니다.");
}
}

@PostMapping()
public ResponseEntity<Object> postContent(@RequestBody ContentRequestDto contentRequestDto) {
try {
contentService.postContent(contentRequestDto);
return ResponseEntity.ok("컨텐츠 등록에 성공했습니다.");
} catch (CustomException e) {
log.error("[postContent] 컨텐츠 등록 실패", e);
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
log.error("[postContent] 컨텐츠 등록 실패", e);
return ResponseEntity.internalServerError().body("컨텐츠 등록에 실패했습니다.");
}
}

@PatchMapping()
public ResponseEntity<Object> updateContent(@RequestBody ContentUpdateDto contentUpdateDto) {
try {
contentService.updateContent(contentUpdateDto);
return ResponseEntity.ok("컨텐츠 수정에 성공했습니다.");
} catch (CustomException e) {
log.error("[updateContent] 컨텐츠 수정 실패", e);
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
log.error("[updateContent] 컨텐츠 수정 실패", e);
return ResponseEntity.internalServerError().body("컨텐츠 수정에 실패했습니다.");
}
}

@GetMapping("/{contentId}")
public ResponseEntity<Object> getContentDetail(@PathVariable String contentId) {
try {
return ResponseEntity.ok(contentService.getContentDetail(contentId));
} catch (CustomException e) {
log.error("[getContentDetail] 컨텐츠 상세 조회 실패", e);
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
log.error("[getContentDetail] 컨텐츠 상세 조회 실패", e);
return ResponseEntity.internalServerError().body("컨텐츠 상세 조회에 실패했습니다.");
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/example/prdoit/dto/content/ContentDetailDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.prdoit.dto.content;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentDetailDto {

private String contentId;
private String contentTitle;
private String contentContent;
private int contentView;
private int contentLike;
private int contentLevel;
private int isVideo;
private String writer;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.content;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentRequestDto {

private String contentTitle;
private String contentContent;
private int contentLevel;
private int isVideo;
private String userId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
@Builder
public class ContentResponseDto {

private int contentId;
private String contentId;
private String contentTitle;
private int contentView;
private int contentLike;
private String contentLevel;
private int contentLevel;
private String writer;
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/prdoit/dto/content/ContentUpdateDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.content;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentUpdateDto {

private String contentId;
private String contentTitle;
private String contentContent;
private int contentLevel;
private int isVideo;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Data
@AllArgsConstructor
Expand All @@ -18,6 +20,10 @@ public class CommentCommentTable {

private String commentCommentContent;

private String userNickname;

private LocalDateTime commentCommentDate;

@ManyToOne
@JoinColumn(name = "commentId")
private CommentTable commentId;
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/example/prdoit/model/CommentTable.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.example.prdoit.model;

import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Data
@AllArgsConstructor
Expand All @@ -21,8 +24,14 @@ public class CommentTable {

private String commentNickname;

private LocalDateTime commentDate;

@ManyToOne
@JoinColumn(name = "contentId", nullable = true)
private ContentTable contentId;

@ManyToOne
@JoinColumn(name = "userId")
private IdTable id;
@JoinColumn(name = "communityId", nullable = true)
private CommunityTable communityId;

}
3 changes: 1 addition & 2 deletions src/main/java/com/example/prdoit/model/CommunityTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
public class CommunityTable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int communityId;
private String communityId;

private String communityContent;

Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/example/prdoit/model/ContentCommentTable.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/com/example/prdoit/model/ContentReplyTable.java

This file was deleted.

7 changes: 4 additions & 3 deletions src/main/java/com/example/prdoit/model/ContentTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
public class ContentTable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int contentId;
private String contentId;

private String contentTitle;

private String contentContent;

private String contentLevel;
private int contentLevel;

private int contentView;

private int isVideo;

private int contentLike;

@ManyToOne
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/com/example/prdoit/model/GuideLineTable.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/com/example/prdoit/model/IdTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class IdTable {
@JsonIgnore
private List<ReadTable> readTable;

@OneToMany(mappedBy = "id", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<ReportTable> reportTable;

@OneToMany(mappedBy = "id", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<CommunityTable> communityTable;
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/com/example/prdoit/model/ReportTable.java

This file was deleted.

Loading