-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from TRIP-Side-Project/dev
spring applicaiton 포트 변경
- Loading branch information
Showing
69 changed files
with
2,200 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/api/trip/common/auditing/config/AuditingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.api.trip.common.auditing.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class AuditingConfig { | ||
|
||
// TODO: 회원가입 후 유저 정보를 가져와서 넣어주는 방법을 모르겠습니다... | ||
/** | ||
@Bean | ||
public AuditorAware<String> auditorAware() { | ||
return () -> Optional.of("user1"); | ||
} | ||
*/ | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/api/trip/common/auditing/entity/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.api.trip.common.auditing.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
@Column(nullable = false, updatable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(nullable = false) | ||
private LocalDateTime modifiedAt; | ||
|
||
private LocalDateTime deletedAt; | ||
|
||
} |
5 changes: 3 additions & 2 deletions
5
.../trip/common/security/SecurityConfig.java → ...ommon/security/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...om/api/trip/common/security/JwtToken.java → ...pi/trip/common/security/jwt/JwtToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...rip/common/security/JwtTokenProvider.java → ...common/security/jwt/JwtTokenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ommon/security/MemberSecurityService.java → ...curity/service/MemberSecurityService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/api/trip/common/security/util/SecurityUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.api.trip.common.security.util; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
public class SecurityUtils { | ||
public static String getCurrentUsername() { | ||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication == null || authentication.getName() == null) { | ||
throw new RuntimeException("인증 정보가 없습니다!"); | ||
} | ||
return authentication.getName(); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/api/trip/domain/article/controller/ArticleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.api.trip.domain.article.controller; | ||
|
||
import com.api.trip.domain.article.controller.dto.*; | ||
import com.api.trip.domain.article.service.ArticleService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/articles") | ||
@RequiredArgsConstructor | ||
public class ArticleController { | ||
|
||
private final ArticleService articleService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Long> createArticle(@RequestBody CreateArticleRequest request) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
return ResponseEntity.ok(articleService.createArticle(request, email)); | ||
} | ||
|
||
@PatchMapping("/{articleId}") | ||
public ResponseEntity<Void> updateArticle(@PathVariable Long articleId, @RequestBody UpdateArticleRequest request) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
articleService.updateArticle(articleId, request, email); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping("/{articleId}") | ||
public ResponseEntity<Void> deleteArticle(@PathVariable Long articleId) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
articleService.deleteArticle(articleId, email); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/{articleId}") | ||
public ResponseEntity<ReadArticleResponse> readArticle(@PathVariable Long articleId) { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
return ResponseEntity.ok(articleService.readArticle(articleId, email)); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<GetArticlesResponse> getArticles( | ||
@PageableDefault(size = 8) Pageable pageable, | ||
@RequestParam(value = "filter", required = false) String filter | ||
) { | ||
return ResponseEntity.ok(articleService.getArticles(pageable, filter)); | ||
} | ||
|
||
@GetMapping("/me") | ||
public ResponseEntity<GetMyArticlesResponse> getMyArticles() { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
return ResponseEntity.ok(articleService.getMyArticles(email)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/api/trip/domain/article/controller/dto/CreateArticleRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.api.trip.domain.article.controller.dto; | ||
|
||
import com.api.trip.domain.article.model.Article; | ||
import com.api.trip.domain.member.model.Member; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CreateArticleRequest { | ||
|
||
private String title; | ||
private String content; | ||
|
||
public Article toEntity(Member writer) { | ||
return Article.builder() | ||
.writer(writer) | ||
.title(title) | ||
.content(content) | ||
.build(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/api/trip/domain/article/controller/dto/GetArticlesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.api.trip.domain.article.controller.dto; | ||
|
||
import com.api.trip.domain.article.model.Article; | ||
import com.api.trip.domain.member.model.Member; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class GetArticlesResponse { | ||
|
||
private int totalPages; | ||
private long totalElements; | ||
private int page; | ||
private boolean hasNext; | ||
private boolean hasPrevious; | ||
private int requestSize; | ||
private int resultSize; | ||
private List<ArticleDto> result; | ||
|
||
public static GetArticlesResponse of(Page<Article> articlePage) { | ||
Page<ArticleDto> articleDtoPage = articlePage.map(ArticleDto::of); | ||
return builder() | ||
.totalPages(articleDtoPage.getTotalPages()) | ||
.totalElements(articleDtoPage.getTotalElements()) | ||
.page(articleDtoPage.getNumber() + 1) | ||
.hasNext(articleDtoPage.hasNext()) | ||
.hasPrevious(articleDtoPage.hasPrevious()) | ||
.requestSize(articleDtoPage.getSize()) | ||
.resultSize(articleDtoPage.getNumberOfElements()) | ||
.result(articleDtoPage.getContent()) | ||
.build(); | ||
} | ||
|
||
@Getter | ||
@Builder | ||
private static class ArticleDto { | ||
|
||
private Long articleId; | ||
private String title; | ||
private Long writerId; | ||
private String writerNickname; | ||
private String writerRole; | ||
private long viewCount; | ||
private long likeCount; | ||
private LocalDateTime createdAt; | ||
|
||
private static ArticleDto of(Article article) { | ||
Member writer = article.getWriter(); | ||
return builder() | ||
.articleId(article.getId()) | ||
.title(article.getTitle()) | ||
.writerId(writer.getId()) | ||
.writerNickname(writer.getNickname()) | ||
.writerRole(writer.getRole().name()) | ||
.viewCount(article.getViewCount()) | ||
.likeCount(article.getLikeCount()) | ||
.createdAt(article.getCreatedAt()) | ||
.build(); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/api/trip/domain/article/controller/dto/GetMyArticlesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.api.trip.domain.article.controller.dto; | ||
|
||
import com.api.trip.domain.article.model.Article; | ||
import com.api.trip.domain.member.model.Member; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class GetMyArticlesResponse { | ||
|
||
private List<ArticleDto> articles; | ||
|
||
public static GetMyArticlesResponse of(List<Article> articles) { | ||
List<ArticleDto> articleDtos = articles.stream() | ||
.map(ArticleDto::of) | ||
.toList(); | ||
|
||
return new GetMyArticlesResponse(articleDtos); | ||
} | ||
|
||
@Getter | ||
@Builder | ||
private static class ArticleDto { | ||
|
||
private Long articleId; | ||
private String title; | ||
private Long writerId; | ||
private String writerNickname; | ||
private String writerRole; | ||
private LocalDateTime createdAt; | ||
|
||
private static ArticleDto of(Article article) { | ||
Member writer = article.getWriter(); | ||
return builder() | ||
.articleId(article.getId()) | ||
.title(article.getTitle()) | ||
.writerId(writer.getId()) | ||
.writerNickname(writer.getNickname()) | ||
.writerRole(writer.getRole().name()) | ||
.createdAt(article.getCreatedAt()) | ||
.build(); | ||
} | ||
} | ||
} |
Oops, something went wrong.