Skip to content

Commit

Permalink
Merge pull request #95 from Snap-Spot/!HOTFIX
Browse files Browse the repository at this point in the history
πŸ”§ fix: λ‘œκ·ΈμΈν•˜μ§€ μ•Šμ•„λ„ 사진 μž‘κ°€ 상세 쑰회 κ°€λŠ₯ν•˜λ„λ‘ μˆ˜μ •
  • Loading branch information
xyzwv authored Oct 9, 2023
2 parents e282141 + 6e1f3f2 commit e705133
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
16 changes: 16 additions & 0 deletions snapspot-admin/src/main/java/snap/dto/MemberRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package snap.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import snap.domains.member.entity.Member;

@Getter
@NoArgsConstructor
public class MemberRes {

private Member member;

public MemberRes(Member member){
this.member = member;
}
}
12 changes: 12 additions & 0 deletions snapspot-admin/src/main/java/snap/service/JwtSecurityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import snap.domains.member.entity.Member;
import snap.domains.member.service.MemberDomainService;
import snap.dto.MemberRes;
import snap.dto.TokenRes;
import snap.enums.Role;
import snap.jwt.JwtTokenUtil;

import java.time.Duration;

import javax.servlet.http.HttpServletRequest;

@Service
@RequiredArgsConstructor
public class JwtSecurityService {
private final JwtTokenUtil jwtUtil;
private final AuthenticationManagerBuilder authenticationManagerBuilder;
private final PasswordEncoder passwordEncoder;
private final RedisService redisService;
private final MemberDomainService memberDomainService;

public TokenRes createJwt(String email, String password) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(email, password);
Expand Down Expand Up @@ -57,4 +63,10 @@ public Boolean validateRefreshToken(Member member, String refreshToken) {
public String encryptPassword(String password) {
return passwordEncoder.encode(password);
}

public MemberRes getMemberByRequest(HttpServletRequest request){
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return new MemberRes(memberDomainService.findMemberByEmail(authentication.getName())
.orElseGet(() -> null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import snap.domains.member.entity.Member;
import snap.domains.photographer.entity.Photographer;
import snap.dto.request.PhotographerFilterReq;
import snap.resolver.AuthMember;
import snap.resolver.AuthPhotographer;
import snap.service.JwtSecurityService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequiredArgsConstructor
@RequestMapping("/photographers")
Expand All @@ -31,6 +33,7 @@ public class PhotographerController {
private final PhotographerService photographerService;
private final ReviewService reviewService;
private final MemberService memberService;
private final JwtSecurityService jwtSecurityService;

@GetMapping("/me")
public ResponseEntity<PhotographerResponseDto> photographerInfoFind(@AuthPhotographer Photographer photographer) {
Expand All @@ -44,7 +47,8 @@ public ResponseEntity<PhotographerResponseDto> photographerInfoUpdate(@AuthPhoto
}

@GetMapping("/{photographerId}")
public ResponseEntity<PhotographerWithHeartDto> photographerFindById(@PathVariable Long photographerId, @AuthMember Member member) {
public ResponseEntity<PhotographerWithHeartDto> photographerFindById(@PathVariable Long photographerId, HttpServletRequest request) {
Member member = jwtSecurityService.getMemberByRequest(request).getMember();
return new ResponseEntity<>(photographerService.findPhotographer(photographerId, member), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public Photographer deleteHeart(Member member, Long photographerId){
}

public Boolean existsHeart(Member member, Photographer photographer){
if (member == null) return false;
return heartRepository.existsByMemberAndPhotographer(member, photographer);
}
}

0 comments on commit e705133

Please sign in to comment.