Skip to content

Commit

Permalink
백엔드 cors 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
duhwan05 committed Aug 6, 2024
1 parent e21d800 commit d4c5f7a
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 420 deletions.
27 changes: 15 additions & 12 deletions src/main/java/com/example/healthylife/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package com.example.healthylife.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig {

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000",
"https://trendy-healthy.store") // 허용할 도메인
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD")
.allowedHeaders("*")
.allowCredentials(true);
}
};
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOriginPattern("http://localhost:8081/swagger-ui/index.html"); // 특정 origin 허용
config.addAllowedOriginPattern("https://trendy-healthy-backend.store/swagger-ui/"); // 특정 origin 허용
config.addAllowedOriginPattern("http://localhost:3000");
config.addAllowedOriginPattern("https://trendy-healthy.store/");
config.addAllowedMethod("*"); // 모든 HTTP 메서드 허용
config.addAllowedHeader("*"); // 모든 헤더 허용
config.setAllowCredentials(true); // 자격 증명 허용
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.example.healthylife.entity.CommunityEntity;
import com.example.healthylife.service.CommunityService;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.example.healthylife.config.jwt.JwtUtil;
import com.example.healthylife.entity.UserEntity;
import com.example.healthylife.service.Impl.JwtAuthService;
import com.example.healthylife.service.JwtAuthService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -19,19 +20,16 @@
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/jwt")
@RestController
@ApiOperation("로그인 컨트롤러")
public class JwtLoginAuthController {

@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private JwtAuthService jwtAuthService;
@Autowired
private ObjectMapper objectMapper;
private final AuthenticationManager authenticationManager;
private final JwtUtil jwtUtil;
private final JwtAuthService jwtAuthService;
private final ObjectMapper objectMapper;

@ApiOperation("로그인 컨트롤러")
@PostMapping("/authenticate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.example.healthylife.service.TodayService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.example.healthylife.controller;

import com.example.healthylife.config.security.MyUserDetailsService;
import com.example.healthylife.entity.UserEntity;
import com.example.healthylife.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@RequestMapping("/user")
Expand Down
31 changes: 11 additions & 20 deletions src/main/java/com/example/healthylife/entity/UserEntity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.healthylife.entity;

import lombok.*;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
Expand All @@ -12,48 +10,40 @@
@Getter
@Table(name = "user")
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserEntity implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name ="user_sq", unique = true, nullable = false)
// user sequence
@Column(name = "user_sq", unique = true, nullable = false)
private Long userSq;

// user id
@Column(name ="user_id", unique = true, nullable = false, length = 100)
@Column(name = "user_id", unique = true, nullable = false, length = 100)
private String userId;

// user password
@LastModifiedDate
@Column(name ="user_pw", length = 100)
@Column(name = "user_pw", length = 100)
private String userPw;

// user name
@Column(name = "user_name", length = 200)
private String userName;


// user email
@Column(name = "user_email",length = 300)
@Column(name = "user_email", length = 300)
private String userEmail;

// user address
@Column(name = "user_address", length = 400)
private String userAddress;

// user age
@Column(name = "user_age", length = 50)
@Column(name = "user_age")
private Long userAge;

// user phone number
@Column(name = "user_phone", length = 100)
private Long userPhone;
private String userPhone;

// builder
@Builder(toBuilder = true)
public UserEntity(long userSq,String userId, String userPw,String userName,String userEmail,String userAddress, long userAge,
long userPhone){
String userPhone){
this.userSq = userSq;
this.userId = userId;
this.userPw = userPw;
Expand All @@ -65,7 +55,8 @@ public UserEntity(long userSq,String userId, String userPw,String userName,Strin
this.userPhone = userPhone;
}

//비밀번호 암호화
public UserEntity withUserPw(String userPw) {
return this.toBuilder().userPw(userPw).build();
}
}
}

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/com/example/healthylife/health/CustomHealthIndicator

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
package com.example.healthylife.service;

import com.example.healthylife.entity.CommunityCommentsEntity;
import com.example.healthylife.repository.CommunityCommentsRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface CommunityCommentsService {
public class CommunityCommentsService {
private final CommunityCommentsRepository communityCommentsRepository;

public CommunityCommentsService(CommunityCommentsRepository communityCommentsRepository){
this.communityCommentsRepository=communityCommentsRepository;
}

//댓글 전체 리스트
List<CommunityCommentsEntity> communityCommentsList();
public List<CommunityCommentsEntity> communityCommentsList() {
return communityCommentsRepository.findAll();
}

//댓글등록
CommunityCommentsEntity insertComments(CommunityCommentsEntity communityCommentsEntity);
public CommunityCommentsEntity insertComments(CommunityCommentsEntity communityCommentsEntity) {
return communityCommentsRepository.save(communityCommentsEntity);
}

//댓글삭제
void deleteBySq(long commentsSq);
public void deleteBySq(long commentsSq) {

communityCommentsRepository.deleteById(commentsSq);
}

//커뮤니티 내가 쓴 댓글
List<CommunityCommentsEntity> findMyCommunityComments(String userId);
public List<CommunityCommentsEntity> findMyCommunityComments(String userId) {
return communityCommentsRepository.findByUserUserId(userId);
}
}
60 changes: 48 additions & 12 deletions src/main/java/com/example/healthylife/service/CommunityService.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
package com.example.healthylife.service;


import com.example.healthylife.entity.CommunityEntity;
import com.example.healthylife.entity.UserEntity;
import com.example.healthylife.repository.CommunityRepository;
import com.example.healthylife.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;
import java.util.Optional;
@RequiredArgsConstructor
@Service
public class CommunityService {

private final CommunityRepository communityRepository;
private final UserRepository userRepository;



public interface CommunityService {
//글전체조회
List<CommunityEntity> communityList();
//글등록
CommunityEntity registerCommunity(CommunityEntity communityEntity);
//글 수정
CommunityEntity updateCommunity(CommunityEntity communityEntity);
//글삭제
void deleteBySq(long communitySq);
public List<CommunityEntity> communityList() {
return communityRepository.findAll();
}


//커뮤니티 글 작성
public CommunityEntity registerCommunity(CommunityEntity communityEntity) {
return communityRepository.save(communityEntity);
}


//커뮤니티 글 수정
@Transactional
public CommunityEntity updateCommunity(CommunityEntity communityEntity) {

List<CommunityEntity> findMyContents(String userId);
return communityRepository.save(communityEntity);
}

//커뮤니티 글 삭제
public void deleteBySq(long communitySq) {

communityRepository.deleteById(communitySq);
}

public List<CommunityEntity> findMyContents(String userId) {
return communityRepository.findByUserUserId(userId);
}
}
//커뮤니티 내가 쓴 글 조회
// @Override
// public List<CommunityEntity> findMyContents(long userSq) {
// return communityRepository.findByUserUserId(userSq);
// }






This file was deleted.

Loading

0 comments on commit d4c5f7a

Please sign in to comment.