Skip to content

Commit

Permalink
[function] remove auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-sh-lee committed Apr 19, 2024
1 parent 256cc8a commit 6c040ed
Show file tree
Hide file tree
Showing 30 changed files with 616 additions and 532 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

logs/
/src/main/generated/
### STS ###
.apt_generated
.classpath
Expand Down Expand Up @@ -35,3 +36,6 @@ out/

### VS Code ###
.vscode/

### MAC ###
.DS_Store
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-core")
implementation("io.micrometer:micrometer-registry-prometheus")
Expand All @@ -44,7 +43,7 @@ dependencies {
annotationProcessor("org.mapstruct:mapstruct-processor:1.5.5.Final")
implementation("org.projectlombok:lombok-mapstruct-binding:0.2.0")

runtimeOnly("com.mysql:mysql-connector-j")
implementation("com.mysql:mysql-connector-j")

implementation("com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta")
annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}:jakarta")
Expand All @@ -53,7 +52,6 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")
testImplementation("org.springframework.security:spring-security-test")

testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
Expand Down
43 changes: 0 additions & 43 deletions src/main/java/com/example/supersns/auth/AuthController.java

This file was deleted.

59 changes: 0 additions & 59 deletions src/main/java/com/example/supersns/auth/CustomUserDetails.java

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/com/example/supersns/auth/SignInRequest.java

This file was deleted.

101 changes: 0 additions & 101 deletions src/main/java/com/example/supersns/config/SecurityConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.example.supersns.follower;

import com.example.supersns.auth.CustomUserDetails;
import com.example.supersns.user.UserMapper;
import com.example.supersns.user.dto.UserProfileResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -35,15 +33,15 @@ public ResponseEntity<?> getUserFollowees(@PathVariable Long userId) {
return ResponseEntity.ok(users);
}

@PostMapping("/followers/{userId}")
public ResponseEntity<?> followUser(@AuthenticationPrincipal CustomUserDetails me, @PathVariable Long userId) {
followerService.followUser(me, userId);
@PostMapping("/followers/{myId}/{userId}")
public ResponseEntity<?> followUser(@PathVariable Long myId, @PathVariable Long userId) {
followerService.followUser(myId, userId);
return ResponseEntity.ok("follow successfully");
}

@DeleteMapping("/followers/{userId}")
public ResponseEntity<?> unfollowUser(@AuthenticationPrincipal CustomUserDetails me, @PathVariable Long userId) {
followerService.unFollowUser(me, userId);
@DeleteMapping("/followers/{myId}/{userId}")
public ResponseEntity<?> unfollowUser(@PathVariable Long myId, @PathVariable Long userId) {
followerService.unFollowUser(myId, userId);
return ResponseEntity.ok("unfollow successfully");
}

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/example/supersns/follower/FollowerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,34 @@ public FollowerService(FollowerRepository followerRepository,
/**
* Follow user follower.
*
* @param me 기준이 되는 유저
* @param myId 기준이 되는 유저
* @param userId 팔로우할 유저의 아이디
*/
@Transactional
public void followUser(User me, Long userId) {
if (me.getId().equals(userId)) {
public void followUser(Long myId, Long userId) {
if (myId.equals(userId)) {
throw new UserInvalidException(userId);
}
User user = userRepository.findUserById(userId).orElseThrow(() -> new UserNotFoundException(userId));
User me = userRepository.findUserById(myId).orElseThrow(() -> new UserNotFoundException(myId));
Follower follower = new Follower(me, user);
followerRepository.save(follower);
}

/**
* Un follow user.
*
* @param me 기준이 되는 유저
* @param myId 기준이 되는 유저
* @param userId 팔로우 해제할 유저의 아이디
*/
@Transactional
public void unFollowUser(User me, Long userId) {
if (me.getId().equals(userId)) {
public void unFollowUser(Long myId, Long userId) {
if (myId.equals(userId)) {
throw new UserInvalidException(userId);
}
User user = userRepository.findUserById(userId).orElseThrow(() -> new UserNotFoundException(userId));
User me = userRepository.findUserById(myId).orElseThrow(() -> new UserNotFoundException(myId));

followerRepository.deleteByFromAndTo(me, user);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.example.supersns.newsfeed;

import com.example.supersns.auth.CustomUserDetails;
import com.example.supersns.post.PostMapper;
import com.example.supersns.post.PostResponse;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -25,9 +24,8 @@ public NewsfeedController(NewsfeedService newsfeedService,
}

@GetMapping("/newsfeed")
public ResponseEntity<?> getUserNewsfeed(@AuthenticationPrincipal CustomUserDetails me,
Pageable pageable) {
Slice<PostResponse> posts = newsfeedService.getUserNewsfeed(me.getId(), pageable)
public ResponseEntity<?> getUserNewsfeed(@RequestParam Long myId, Pageable pageable) {
Slice<PostResponse> posts = newsfeedService.getUserNewsfeed(myId, pageable)
.map(postMapper::postToPostResponseDto);
return ResponseEntity.ok(posts);
}
Expand Down
Loading

0 comments on commit 6c040ed

Please sign in to comment.