Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
[#44] 팔로우 구현 (#45)
Browse files Browse the repository at this point in the history
* [#44] 팔로우  구현

- 팔로우 API, service 구현
- sendFollow -> follow로 변경
  • Loading branch information
choitaehoon committed Dec 22, 2020
1 parent f1fba85 commit 7d11dc6
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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;
}

}
39 changes: 39 additions & 0 deletions src/main/java/com/social/instagram/domain/Follow.java
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();
}

}
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 src/main/java/com/social/instagram/service/FollowService.java
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);
}

}

0 comments on commit 7d11dc6

Please sign in to comment.