Skip to content

Commit

Permalink
Merge pull request #140 from prgrms-web-devcourse-final-project/develop
Browse files Browse the repository at this point in the history
HomeController 추가 Main 반영
  • Loading branch information
iam52 authored Dec 4, 2024
2 parents 258bc39 + a9a5e62 commit 7e939cb
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mallangs.domain.article.service;
package com.mallangs.domain.article.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -10,7 +10,6 @@
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

Expand All @@ -20,7 +19,7 @@

@Log4j2 // Lombok을 사용한 로깅 기능 활성화
@RestController // REST API 컨트롤러로 지정
@RequestMapping("/tourapi") // "/tourapi" 경로로 들어오는 요청 처리
@RequestMapping("/tourapi/v1") // "/tourapi" 경로로 들어오는 요청 처리
@Tag(name = "Tour API", description = " 한국관광공사 반려동물 동반여행_서비스1.0.0 API 호출 컨트롤러")
public class TourApiController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@Tag(name = "커뮤니티 & 실종신고-목격제보 API", description = "커뮤니티/실종신고-목격제보 관련 API")
@RestController
@RequestMapping("/api/board")
@RequestMapping("/api/v1/board")
@RequiredArgsConstructor
@Slf4j
public class BoardController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@Tag(name = "카테고리 API", description = "카테고리 관리 API")
@RestController
@RequestMapping("/api/category")
@RequestMapping("/api/v1/category")
@RequiredArgsConstructor
@Slf4j
public class CategoryController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
@Tag(name = "테스트용 컨트롤러 사용 X", description = " 테스트용 사용 X")
public class ChatViewControllerTest {

@GetMapping("/")
@Operation(summary = "테스트 사용X", description = "테스트용 컨트롤러 사용X")
public String homePage() {
return "index"; // index.html 템플릿 반환
}
// @GetMapping("/")
// @Operation(summary = "테스트 사용X", description = "테스트용 컨트롤러 사용X")
// public String homePage() {
// return "index"; // index.html 템플릿 반환
// }

@GetMapping("/chat-rooms")
@Operation(summary = "테스트 사용X", description = "테스트용 컨트롤러 사용X")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comments")
@RequestMapping("/api/v1/comments")
@Tag(name = "댓글", description = "댓글 CRUD")
public class CommentController {
private final CommentService commentService;
Expand Down
54 changes: 43 additions & 11 deletions src/main/java/com/mallangs/domain/image/entity/Image.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
package com.mallangs.domain.image.entity;

import com.mallangs.domain.chat.entity.ChatMessage;
import com.mallangs.domain.article.entity.Article;
import com.mallangs.domain.board.entity.Board;
import com.mallangs.domain.member.entity.Member;
import com.mallangs.domain.pet.entity.Pet;
import com.mallangs.domain.review.entity.Review;
import com.mallangs.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "image")
public class Image {
@AllArgsConstructor
@Builder
public class Image extends BaseTimeEntity {
@Id
@Column(nullable = false, unique = true)
private String url;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long imageId;

private String originalFileName;
// 이미지가 필요한 도메인: Article, Board, Member, Pet, Review
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "article_id")
private Article article;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;

private String contentType;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pet_id")
private Pet pet;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "review_id")
private Review review;

@Enumerated(EnumType.STRING)
private ImageOrder imageOrder;

@Column(nullable = false)
private Integer width;
private String originalFileName;

@Column(nullable = false)
private Integer height;
private String storedFileName;

@Column(nullable = false)
private int fileSize;

@Column(nullable = false)
private String s3Url;

@Column(nullable = false)
private Integer width;

@Column(nullable = false)
private Integer height;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mallangs.domain.image.entity;

public enum ImageOrder {
FIRST, SECOND, THIRD, FOURTH
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
package com.mallangs.domain.image.repository;

import com.mallangs.domain.article.entity.Article;
import com.mallangs.domain.board.entity.Board;
import com.mallangs.domain.image.entity.Image;
import com.mallangs.domain.member.entity.Member;
import com.mallangs.domain.pet.entity.Pet;
import com.mallangs.domain.review.entity.Review;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ImageRepository extends JpaRepository<Image, Long> {

// Article에 연결된 이미지 조회
List<Image> findByArticle(Article article);

// Board에 연결된 이미지 조회
List<Image> findByBoard(Board board);

// Member에 연결된 이미지 조회
List<Image> findByMember(Member member);

// Pet에 연결된 이미지 조회
List<Image> findByPet(Pet pet);

// Review에 연결된 이미지 조회
List<Image> findByReview(Review review);

// Article에 연결된 이미지 삭제
void deleteByArticle(Article article);

// Board에 연결된 이미지 삭제
void deleteByBoard(Board board);

// Member에 연결된 이미지 삭제
void deleteByMember(Member member);

// Pet에 연결된 이미지 삭제
void deleteByPet(Pet pet);

// Review에 연결된 이미지 삭제
void deleteByReview(Review review);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Log4j2
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/auth")
@RequestMapping("/api/v1/auth")
@Tag(name = "소셜로그인 / 세션으로 토큰 받는 컨트롤러", description = "네이버 소셜로그인 인증 요청주소: `http://localhost:8080/oauth2/authorization/naver`\n" +
"`구글 소셜로그인 인증 요청주소: http://localhost:8080/oauth2/authorization/google`\n"
+ "인증 완료 후 토큰 생성 API 엔드포인트 = `api/auth/get-access-token`\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/pets")
@RequestMapping("/api/v1/pets")
@RequiredArgsConstructor
@Tag(name = "반려동물(말랑이)", description = "반려동물 CRUD")
public class PetController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/place-articles")
@RequestMapping("/api/v1/place-articles")
@Tag(name = "리뷰", description = "장소 리뷰 API (CRUD). 장소 글타래는 일반 글타래와 동일하게 articleId를 고유 식별자로 사용하지만, 명확성을 위해 placeArticleId를 엔드포인트에 사용합니다. (받는 값은 articleId)")
public class ReviewController {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mallangs/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
http
.authorizeHttpRequests((auth) ->
auth
.requestMatchers("/favicon.ico").permitAll()
.requestMatchers("/").permitAll()
.requestMatchers("/api/v1/member/register", "/api/v1/member/login",
"/api/v1/member/logout", "/api/v1/member/find-user-id",
"/api/v1/member/find-password").permitAll() //회원가입,로그인,로그아웃,비번찾기,아이디찾기
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/mallangs/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ public enum ErrorCode {
COMMENT_NOT_MODIFIED(CONFLICT, "댓글 업데이트에 실패했습니다."),
COMMENT_NOT_REMOVED(CONFLICT, "댓글 삭제에 실패했습니다."),
FORBIDDEN_ACCESS(FORBIDDEN, "권한이 없습니다."),
POST_NOT_FOUND(NOT_FOUND, "해당 게시물을 찾을 수 없습니다.");
POST_NOT_FOUND(NOT_FOUND, "해당 게시물을 찾을 수 없습니다."),

// Image
IMAGE_COUNT_EXCEEDED(BAD_REQUEST, "이미지 개수가 혀용치(4개)를 초과했습니다."),
IMAGE_SIZE_EXCEEDED(BAD_REQUEST, "이미지 크기가 허용치(3MB)를 초과했습니다."),
IMAGE_NOT_FOUND(NOT_FOUND, "이미지를 찾을 수 없습니다."),
INVAILD_IMAGE_FORMAT(BAD_REQUEST, "지원하지 않는 이미지 형식입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/mallangs/global/jwt/filter/JWTFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public class JWTFilter extends OncePerRequestFilter {
private final AccessTokenBlackList accessTokenBlackList;
private final MemberRepository memberRepository;

// favicon.ico 요청은 필터링하지 않음
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
String path = request.getServletPath();
return "/favicon.ico".equals(path);
}

@Override
//jwt Token 전용 필터 ( 토큰 유효한지 확인 )
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
Expand Down Expand Up @@ -212,4 +219,6 @@ private Cookie createCookie(String refreshCookie) {
cookie.setHttpOnly(true);
return cookie;
}


}
18 changes: 18 additions & 0 deletions src/main/java/com/mallangs/web/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mallangs.web;

import com.mallangs.global.exception.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HomeController {
@GetMapping("/")
public ResponseEntity<ErrorResponse> home() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.from(HttpStatus.UNAUTHORIZED, "인증되지 않은 요청입니다."));
}
}

0 comments on commit 7e939cb

Please sign in to comment.