Skip to content

Commit

Permalink
Merge pull request #138 from kakao-tech-campus-2nd-step3/feature/ISSU…
Browse files Browse the repository at this point in the history
…E-82

멤버 프로필 작성
  • Loading branch information
jjt4515 authored Nov 12, 2024
2 parents 293e88e + 309da31 commit 4105c74
Show file tree
Hide file tree
Showing 48 changed files with 608 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

import jdk.jfr.Description;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
import poomasi.domain.auth.token.blacklist.service.TokenBlacklistService;
import poomasi.domain.auth.token.refreshtoken.service.TokenStorageService;
import poomasi.domain.auth.token.util.JwtUtil;
import poomasi.domain.auth.token.refreshtoken.service.TokenRedisService;
import poomasi.domain.member.service.MemberService;


@RequiredArgsConstructor
@Configuration
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/poomasi/domain/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import poomasi.domain.auth.security.filter.CustomUsernamePasswordAuthenticationFilter;
import poomasi.domain.auth.security.filter.JwtAuthenticationFilter;
import poomasi.domain.auth.security.handler.CustomSuccessHandler;
import poomasi.domain.auth.security.userdetail.OAuth2UserDetailServiceImpl;
import poomasi.domain.auth.security.handler.*;
import poomasi.domain.auth.security.userdetail.UserDetailsServiceImpl;
import poomasi.domain.auth.token.util.JwtUtil;

Expand Down Expand Up @@ -78,7 +75,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers(HttpMethod.GET, "/api/review/**").permitAll()
.requestMatchers(HttpMethod.GET, "/health").permitAll()
.requestMatchers(HttpMethod.GET, "/api/image/**").permitAll()
.requestMatchers("/api/sign-up", "/api/login", "api/reissue", "api/payment/**", "api/order/**", "api/reservation/**", "/api/v1/farmer/reservations").permitAll()
.requestMatchers("/api/member/sign-up", "/api/login", "api/reissue", "api/payment/**", "api/order/**", "api/reservation/**", "/api/v1/farmer/reservations").permitAll()
.requestMatchers("/api/need-auth/**").authenticated()
.anyRequest().
authenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public ResponseEntity<?> getFarm(@PathVariable Long farmId) {
public ResponseEntity<?> getFarmList(Pageable pageable) {
return ResponseEntity.ok(farmPlatformService.getFarmList(pageable));
}

@GetMapping("byFarmer/{farmerId}")
public ResponseEntity<?> getFarmsByFarmerId(@PathVariable Long farmerId) {
return ResponseEntity.ok(farmPlatformService.getFarmsByFarmerId(farmerId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public List<FarmResponse> getFarmList(Pageable pageable) {
.map(FarmResponse::fromEntity)
.collect(Collectors.toList());
}

public List<FarmResponse> getFarmsByFarmerId(Long farmerId) {
return farmService.getFarmListByOwnerId(farmerId).stream()
.map(FarmResponse::fromEntity)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package poomasi.domain.image.deleteLinker;

import org.springframework.stereotype.Component;
import poomasi.domain.image.entity.ImageType;

import java.util.HashMap;
import java.util.Map;

@Component
public class ImageDeleteFactory {

private final Map<ImageType, ImageDeleteLinker> handlerMap;

public ImageDeleteFactory(
ProductDeleteLinker productDeleteLinker,
MemberProfileDeleteLinker memberProfileDeleteLinker) {
this.handlerMap = new HashMap<>();
handlerMap.put(ImageType.PRODUCT, productDeleteLinker);
handlerMap.put(ImageType.MEMBER_PROFILE, memberProfileDeleteLinker);
}

public ImageDeleteLinker getDeleteLinker(ImageType type) {
return handlerMap.get(type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poomasi.domain.image.deleteLinker;

import poomasi.domain.image.entity.Image;

public interface ImageDeleteLinker {
void handleImageDeletion(Image image);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package poomasi.domain.image.deleteLinker;

import org.springframework.stereotype.Component;
import poomasi.domain.image.entity.Image;
import poomasi.domain.member._profile.entity.MemberProfile;
import poomasi.domain.member._profile.service.MemberProfileService;

@Component
public class MemberProfileDeleteLinker implements ImageDeleteLinker {

private final MemberProfileService memberProfileService;

public MemberProfileDeleteLinker(MemberProfileService memberProfileService) {
this.memberProfileService = memberProfileService;
}

@Override
public void handleImageDeletion(Image image) {
MemberProfile memberProfile = memberProfileService.getMemberProfileById(image.getReferenceId());
memberProfile.setProfileImage(null);
memberProfileService.saveMemberProfile(memberProfile);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package poomasi.domain.image.deleteLinker;

import org.springframework.stereotype.Component;
import poomasi.domain.image.entity.Image;
import poomasi.domain.product.entity.Product;
import poomasi.domain.product.service.ProductService;

@Component
public class ProductDeleteLinker implements ImageDeleteLinker {

private final ProductService productService;

public ProductDeleteLinker(ProductService productService) {
this.productService = productService;
}

@Override
public void handleImageDeletion(Image image) {
Product product = productService.findProductById(image.getReferenceId());
product.setImageUrl(null);
productService.saveExistedProduct(product);
}
}
9 changes: 4 additions & 5 deletions src/main/java/poomasi/domain/image/entity/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import poomasi.domain.image.dto.ImageRequest;

import java.time.LocalDateTime;
import java.util.Date;

@Entity
@Table(name = "image", uniqueConstraints = {
@UniqueConstraint(columnNames = {"type", "reference_id", "object_key"})
@UniqueConstraint(columnNames = {"type", "reference_id"})
})
@Getter
@Setter
Expand All @@ -22,10 +21,10 @@ public class Image {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
@Column(nullable = false, unique = true)
private String objectKey;

@Column(nullable = false)
@Column(nullable = false, unique = true)
private String imageUrl;

@Enumerated(EnumType.STRING)
Expand All @@ -37,7 +36,7 @@ public class Image {

@Column(name = "created_at", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt = new Date();
private LocalDateTime createdAt = LocalDateTime.now();

@Column(name = "deleted_at")
private LocalDateTime deletedAt;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/poomasi/domain/image/linker/ImageLinker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package poomasi.domain.image.linker;

import poomasi.domain.image.entity.Image;
import poomasi.domain.image.entity.ImageType;

public interface ImageLinker {
boolean supports(ImageType type);
void link(Long referenceId, Image savedImage);
}
23 changes: 23 additions & 0 deletions src/main/java/poomasi/domain/image/linker/ImageLinkerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package poomasi.domain.image.linker;

import org.springframework.stereotype.Component;
import poomasi.domain.image.entity.ImageType;

import java.util.List;

@Component
public class ImageLinkerFactory {

private final List<ImageLinker> linkers;

public ImageLinkerFactory(List<ImageLinker> linkers) {
this.linkers = linkers;
}

public ImageLinker getLinker(ImageType type) {
return linkers.stream()
.filter(linker -> linker.supports(type))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package poomasi.domain.image.linker;

import org.springframework.stereotype.Service;
import poomasi.domain.image.entity.Image;
import poomasi.domain.image.entity.ImageType;
import poomasi.domain.member._profile.entity.MemberProfile;
import poomasi.domain.member._profile.service.MemberProfileService;

@Service
public class MemberProfileImageLinker implements ImageLinker {

private final MemberProfileService memberProfileService;

public MemberProfileImageLinker(MemberProfileService memberProfileService) {
this.memberProfileService = memberProfileService;
}

@Override
public boolean supports(ImageType type) {
return type == ImageType.MEMBER_PROFILE;
}

@Override
public void link(Long referenceId, Image savedImage) {
MemberProfile memberProfile = memberProfileService.getMemberProfileById(referenceId);
memberProfile.setProfileImage(savedImage);
memberProfileService.saveMemberProfile(memberProfile);
}
}


29 changes: 29 additions & 0 deletions src/main/java/poomasi/domain/image/linker/ProductImageLinker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package poomasi.domain.image.linker;

import org.springframework.stereotype.Service;
import poomasi.domain.image.entity.Image;
import poomasi.domain.image.entity.ImageType;
import poomasi.domain.product.entity.Product;
import poomasi.domain.product.service.ProductService;

@Service
public class ProductImageLinker implements ImageLinker {

private final ProductService productService;

public ProductImageLinker(ProductService productService) {
this.productService = productService;
}

@Override
public boolean supports(ImageType type) {
return type == ImageType.PRODUCT;
}

@Override
public void link(Long referenceId, Image savedImage) {
Product product = productService.findProductById(referenceId);
product.setImageUrl(savedImage.getImageUrl());
productService.saveExistedProduct(product);
}
}
Loading

0 comments on commit 4105c74

Please sign in to comment.