feat: 20221013 save and Profile Service Init Implement

This commit is contained in:
minseokkang
2022-10-13 17:23:08 +09:00
parent 331ad36c8b
commit ddba2c7376
7 changed files with 100 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
package com.io.realworld.domain.aggregate.profile.controller;
import com.io.realworld.domain.aggregate.profile.service.ProfileService;
import com.io.realworld.domain.aggregate.profile.service.ProfileServiceImpl;
import com.io.realworld.domain.aggregate.user.dto.UserAuth;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/profiles")
public class ProfilesController {
private final ProfileService profileService;
public ProfilesController(ProfileService profileService){
this.profileService = profileService;
}
@GetMapping("/{username}")
public String getProfile(@AuthenticationPrincipal UserAuth userAuth, @PathVariable String username){
return profileService.getProfile(userAuth,username);
}
}

View File

@@ -0,0 +1,25 @@
package com.io.realworld.domain.aggregate.profile.entity;
import com.io.realworld.domain.aggregate.user.entity.User;
import javax.persistence.*;
@Table(name="follows", uniqueConstraints = {
@UniqueConstraint(name="follow_followee_pair_unique",columnNames = {"followee","follower"})
})
@Entity
public class Follow {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name = "followee")
private User followee;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name="follower")
private User follower;
}

View File

@@ -0,0 +1,12 @@
package com.io.realworld.domain.aggregate.profile.repository;
import com.io.realworld.domain.aggregate.profile.entity.Follow;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
interface ProfileRepository extends JpaRepository<Follow,Long> {
Optional<Follow> findByFolloweeIdAndFollowerId(Long followeeId, Long followerId);
}

View File

@@ -0,0 +1,8 @@
package com.io.realworld.domain.aggregate.profile.service;
import com.io.realworld.domain.aggregate.user.dto.UserAuth;
public interface ProfileService {
String getProfile(UserAuth userAuth, String username);
}

View File

@@ -0,0 +1,23 @@
package com.io.realworld.domain.aggregate.profile.service;
import com.io.realworld.domain.aggregate.user.dto.UserAuth;
import com.io.realworld.domain.aggregate.profile.repository.*;
import com.io.realworld.domain.aggregate.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
@RequiredArgsConstructor
public class ProfileServiceImpl implements ProfileService{
private final UserRepository userRepository;
@Override
public String getProfile(UserAuth userAuth, String username) {
return null;
}
}

View File

@@ -18,13 +18,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@RestController
@Slf4j
@RequestMapping("/api/user")
public class UserController {
private final UserServiceImpl userService;
private final UserService userService;
public UserController(UserServiceImpl userService) {
public UserController(UserService userService) {
this.userService = userService;
}

View File

@@ -16,7 +16,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
@Configuration
@RequiredArgsConstructor