This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#44] 팔로우 구현 - 팔로우 API, service 구현 - sendFollow -> follow로 변경
- Loading branch information
1 parent
f1fba85
commit 7d11dc6
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/social/instagram/controller/FollowController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.social.instagram.controller; | ||
|
||
import com.social.instagram.domain.Follow; | ||
import com.social.instagram.service.FollowService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
import static com.social.instagram.util.httpstatus.ResponseConstants.RESPONSE_ENTITY_CREATE; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/follows") | ||
public class FollowController { | ||
|
||
private final FollowService followService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> follow(@RequestBody Follow follow) { | ||
followService.follow(follow); | ||
|
||
return RESPONSE_ENTITY_CREATE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.social.instagram.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Follow { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private long id; | ||
|
||
private String userId; | ||
|
||
private String followId; | ||
|
||
@Builder | ||
public Follow(String userId, String followId) { | ||
this.userId = userId; | ||
this.followId = followId; | ||
} | ||
|
||
public static Follow from(String userId, String followId) { | ||
return Follow.builder() | ||
.userId(userId) | ||
.followId(followId) | ||
.build(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/social/instagram/repository/FollowRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.social.instagram.repository; | ||
|
||
import com.social.instagram.domain.Follow; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FollowRepository extends JpaRepository<Follow, Long> { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/social/instagram/service/FollowService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.social.instagram.service; | ||
|
||
import com.social.instagram.domain.Follow; | ||
import com.social.instagram.repository.FollowRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FollowService { | ||
|
||
private final FollowRepository followRepository; | ||
|
||
public void follow(Follow follow) { | ||
followRepository.save(follow); | ||
} | ||
|
||
} |