Skip to content

Commit

Permalink
Merge pull request #180 from prgrms-web-devcourse-final-project/develop
Browse files Browse the repository at this point in the history
update jwt필터 무시 메서드별로 등록
  • Loading branch information
Dom1046 authored Dec 5, 2024
2 parents ad513bd + 0c1438f commit 616efb9
Show file tree
Hide file tree
Showing 45 changed files with 1,229 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mallangs.domain.article.dto.request.ArticleCreateRequest;
import com.mallangs.domain.article.dto.request.MapBoundsRequest;
import com.mallangs.domain.article.dto.response.ArticlePageResponse;
import com.mallangs.domain.article.dto.response.ArticleResponse;
import com.mallangs.domain.article.dto.response.MapBoundsResponse;
import com.mallangs.domain.article.entity.CaseStatus;
Expand All @@ -14,8 +15,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -60,13 +61,13 @@ public ResponseEntity<ArticleResponse> createArticle(
// 회원 visible + 자신의 글 조회 가능
// 비회원 mapVisible 만 조회 가능
@Operation(summary = "글타래 단건 조회", description = "글타래를 단건 조회합니다.")
@GetMapping("/public/{articleId}")
@GetMapping("/{articleId}")
public ResponseEntity<ArticleResponse> getArticleByArticleId(
@Parameter(description = "조회할 글타래 ID", required = true) @PathVariable Long articleId,
@AuthenticationPrincipal CustomMemberDetails principal) {

String userRole = principal.getRole();
Long memberId = principal.getMemberId();
String userRole = (principal == null) ? "GUEST" : principal.getRole();
Long memberId = (principal == null) ? -1L : principal.getMemberId();

ArticleResponse articleResponse = articleService.getArticleById(articleId, userRole, memberId);

Expand All @@ -79,35 +80,35 @@ public ResponseEntity<ArticleResponse> getArticleByArticleId(
@Operation(summary = "관리자 글타래 전체 조회", description = "관리자가 글타래를 조회합니다.")
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@GetMapping("/admin")
public ResponseEntity<Page<ArticleResponse>> getArticles(
public ResponseEntity<ArticlePageResponse> getArticles(
@PageableDefault(page = 0, size = 10)
@Parameter(description = "페이징 요청 정보", required = true) Pageable pageable,
@RequestParam(value = "articleType", required = false) String articleType, // 대분류
@RequestParam(value = "placeCategory", required = false) String placeCategory) { // 소분류

Page<ArticleResponse> articles;
ArticlePageResponse articles;

if (articleType == null || articleType.isEmpty()) {
articles = articleService.findAllTypeArticles(pageable);
articles = articleService.findAllTypeArticles(pageable); // 전체
} else {
if (placeCategory == null || placeCategory.isEmpty()) {
if (placeCategory == null || placeCategory.isEmpty()) { // 대분류
articles = articleService.findArticlesByArticleType(pageable, articleType);
} else {
} else { // 장소, 사용자 등록 위치 소분류
articles = articleService.findPlaceArticlesByCategory(pageable, articleType, placeCategory);
}
}

return ResponseEntity.ok(articles);
}

// 실종 페이지
// 실종 페이지 // list
// map visible 만 보임
@Operation(summary = "실종 글타래 전체 조회", description = "실종 글타래를 조회합니다.")
@GetMapping("/public/lost")
public ResponseEntity<Page<ArticleResponse>> getLostArticles(
@Parameter(description = "페이징 요청 정보", required = true) Pageable pageable,
public ResponseEntity<List<ArticleResponse>> getLostArticles(
@RequestParam(value = "lostStatus", required = false) CaseStatus lostStatus) {

Page<ArticleResponse> articles = articleService.findLostArticles(pageable, lostStatus);
List<ArticleResponse> articles = articleService.findLostArticles(lostStatus);

return ResponseEntity.ok(articles);
}
Expand Down Expand Up @@ -158,27 +159,24 @@ public ResponseEntity<List<MapBoundsResponse>> getMarkersInBounds(
// map visible 만 보임
@Operation(summary = "글타래 검색", description = "글타래에서 검색합니다.")
@GetMapping("/public/search")
public ResponseEntity<Page<ArticleResponse>> searchSightingPosts(
@Parameter(description = "페이지 요청 정보", required = true) Pageable pageable,
public ResponseEntity<List<ArticleResponse>> searchSightingPosts(
@RequestParam String keyword) {

Page<ArticleResponse> articles = articleService.findArticlesByKeyword(pageable, keyword);
List<ArticleResponse> articles = articleService.findArticlesByKeyword(keyword);
return ResponseEntity.ok(articles);
}


// 회원 자신이 작성한 글타래 목록 조회
// 회원 자신이 작성한 글타래 목록 조회 // list
// is deleted false 안 보임
@Operation(summary = "사용자가 작성한 전체 글타래 조회", description = "사용자가 자신이 작성한 글타래 목록을 조회합니다.")
@PreAuthorize("hasAuthority('ROLE_USER')")
@PreAuthorize("hasAuthority('ROLE_USER') or hasAuthority('ROLE_ADMIN')")
@GetMapping("/myArticles")
public ResponseEntity<Page<ArticleResponse>> getArticlesByMemberId(
@Parameter(description = "페이지 요청 정보", required = true) Pageable pageable,
public ResponseEntity<List<ArticleResponse>> getArticlesByMemberId(
@Parameter(description = "현재 인증된 사용자 정보", required = true)
@AuthenticationPrincipal CustomMemberDetails principal) {

Page<ArticleResponse> articles = articleService.findArticlesByMemberId(pageable,
principal.getMemberId());
List<ArticleResponse> articles = articleService.findArticlesByMemberId(principal.getMemberId());
return ResponseEntity.ok(articles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
})
public class ArticleCreateRequest {

@NotBlank(message = "글 타입은 필수입니다.", groups = ValidationGroups.CreateGroup.class)
@NotNull(message = "글 타입은 필수입니다.", groups = ValidationGroups.CreateGroup.class)
@JsonProperty("type")
private ArticleType articleType; // 글타래 종류

@NotBlank(message = "글 상태는 필수입니다.", groups = ValidationGroups.CreateGroup.class)
@NotNull(message = "글 상태는 필수입니다.", groups = ValidationGroups.CreateGroup.class)
private BoardStatus articleStatus;

@NotBlank(message = "제목은 필수입니다.", groups = ValidationGroups.CreateGroup.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mallangs.domain.pet.entity.PetType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,7 +20,7 @@
@Schema(description = "자식 클래스 DTO", allOf = ArticleCreateRequest.class)
public class LostCreateRequest extends ArticleCreateRequest {

@NotBlank(message = "동물 타입은 필수입니다.", groups = ValidationGroups.CreateGroup.class)
@NotNull(message = "동물 타입은 필수입니다.", groups = ValidationGroups.CreateGroup.class)
private PetType petType;

private String breed;
Expand All @@ -43,7 +44,7 @@ public class LostCreateRequest extends ArticleCreateRequest {

private String contact;

@NotBlank(message = "실종 상태는 필수입니다.", groups = ValidationGroups.CreateGroup.class)
@NotNull(message = "실종 상태는 필수입니다.", groups = ValidationGroups.CreateGroup.class)
private CaseStatus lostStatus;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mallangs.domain.article.dto.response;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ArticlePageResponse {

private List<ArticleResponse> articles;
private long totalElements;
private int totalPages;
private int currentPage;
private int pageSize;


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mallangs.domain.article.entity.Article;
import com.mallangs.domain.article.entity.ArticleType;
import com.mallangs.domain.article.entity.CaseStatus;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -20,12 +21,17 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {

// 모든 사용자
// 실종 게시판 별도 확인
// article 에서 map visible
@Query("SELECT l FROM LostArticle l JOIN Article a ON l.id = a.id WHERE l.lostStatus = :lostStatus AND a.mapVisibility = 'VISIBLE'")
Page<Article> findLostArticles(Pageable pageable, CaseStatus lostStatus);
// article 에서 map visible // jpql 은 join 필요 없음
@Query("SELECT l FROM LostArticle l WHERE l.lostStatus = :lostStatus AND l.mapVisibility = 'VISIBLE'")
List<Article> findLostArticles(@Param("lostStatus") CaseStatus lostStatus);

// 관리자 목록 조회
// 다양한 타입 설정

// 장소 // 사용자 등록 위치 구분
@Query("SELECT p FROM PlaceArticle p WHERE p.isPublicData = :isPublicData")
Page<Article> findPlaceArticlesByType(Pageable pageable, boolean isPublicData);

// 장소 중에 소분류
@Query("SELECT p FROM PlaceArticle p WHERE p.isPublicData = :isPublicData AND p.category = :placeCategory")
Page<Article> findPlaceArticlesByCategory(Pageable pageable, boolean isPublicData,
Expand All @@ -34,15 +40,14 @@ Page<Article> findPlaceArticlesByCategory(Pageable pageable, boolean isPublicDat
// 멤버 개인 글타래 목록 조회
// 논리 삭제 된 것 제외
@Query("SELECT a FROM Article a WHERE a.member.memberId = :memberId AND a.isDeleted = false")
Page<Article> findByMemberId(Pageable pageable, Long memberId);
List<Article> findByMemberId(Long memberId);

// 모든 사용자
// 검색
@Query("SELECT a FROM Article a WHERE (a.title LIKE %:title% OR a.description LIKE %:description%) AND a.mapVisibility = 'VISIBLE'")
Page<Article> findByTitleContainingOrDescriptionContainingAndMapVisibility(
List<Article> findByTitleContainingOrDescriptionContainingAndMapVisibility(
@Param("title") String title,
@Param("description") String description,
Pageable pageable);
@Param("description") String description);


}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public List<MapBoundsResponse> findArticlesInBounds(double southWestLat, double
);
}

// 실종 구조
@Override
public List<MapBoundsResponse> findArticlesInBoundsByType(double southWestLat,
double southWestLon, double northEastLat, double northEastLon, String type) {
Expand Down Expand Up @@ -73,16 +74,17 @@ public List<MapBoundsResponse> findArticlesInBoundsByType(double southWestLat,
);
}

// 장소 / 사용자 등록 위치
@Override
public List<MapBoundsResponse> findPlaceArticlesInBoundsByType(double southWestLat,
double southWestLon, double northEastLat, double northEastLon, boolean isPublicData) {

String query = String.format(
"SELECT a.article_id, a.type, a.title, ST_X(a.geography) AS latitude, " +
"ST_Y(a.geography) AS longitude, a.description " +
"FROM place p "
+ "JOIN article a ON p.article_id = a.article_id" +
"WHERE MBRContains(ST_GeomFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))', 4326), a.geography) "
"FROM place_article p "
+ "JOIN article a ON p.article_id = a.article_id "
+ "WHERE MBRContains(ST_GeomFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))', 4326), a.geography) "
+ "AND p.is_public_data = %b",
southWestLat, southWestLon,
southWestLat, northEastLon,
Expand Down Expand Up @@ -114,10 +116,10 @@ public List<MapBoundsResponse> findPlaceArticlesInBoundsByCategory(double southW
String query = String.format(
"SELECT a.article_id, a.type, a.title, ST_X(a.geography) AS latitude, " +
"ST_Y(a.geography) AS longitude, a.description " +
"FROM place p "
+ "JOIN article a ON p.article_id = a.article_id" +
"WHERE MBRContains(ST_GeomFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))', 4326), a.geography) "
+ "AND p.place_category = '%s' AND p.is_public_data = %b",
"FROM place_article p "
+ "JOIN article a ON p.article_id = a.article_id "
+ "WHERE MBRContains(ST_GeomFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))', 4326), a.geography) "
+ "AND p.category = '%s' AND p.is_public_data = %b",
southWestLat, southWestLon,
southWestLat, northEastLon,
northEastLat, northEastLon,
Expand Down
Loading

0 comments on commit 616efb9

Please sign in to comment.