-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from White-Long-tailed-Tit/feature/12-register…
…-github [feature/12-register-github] 깃허브 등록
- Loading branch information
Showing
10 changed files
with
172 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/wltt/issuetree/user/controller/UserController.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.wltt.issuetree.user.controller; | ||
|
||
import com.wltt.issuetree.global.SlackUrlEncodedForm; | ||
import com.wltt.issuetree.user.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.util.MultiValueMap; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/users") | ||
public class UserController { | ||
private final UserService userService; | ||
|
||
@PostMapping( | ||
value = "", | ||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public void addUser( | ||
@RequestBody final MultiValueMap<String, Object> data | ||
) { | ||
userService.addUser(new SlackUrlEncodedForm(data)); | ||
} | ||
} |
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,37 @@ | ||
package com.wltt.issuetree.user.domain; | ||
|
||
import com.wltt.issuetree.global.BaseEntity; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.elasticsearch.annotations.Document; | ||
import org.springframework.data.elasticsearch.annotations.Field; | ||
import org.springframework.data.elasticsearch.annotations.FieldType; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Document(indexName = "users") | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Getter | ||
public class User extends BaseEntity { | ||
@Id | ||
private String id; | ||
|
||
@Field(type = FieldType.Keyword) | ||
private String githubId; | ||
|
||
@Field(type = FieldType.Keyword) | ||
private String slackId; | ||
|
||
@Override | ||
public boolean isNew() { | ||
return id == null || (getCreatedDate() == null); | ||
} | ||
|
||
@Builder(builderMethodName = "of") | ||
public User(String githubId, String slackId) { | ||
this.githubId = githubId; | ||
this.slackId = slackId; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/wltt/issuetree/user/domain/repository/UserRepository.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,10 @@ | ||
package com.wltt.issuetree.user.domain.repository; | ||
|
||
import com.wltt.issuetree.global.elasticsearch.repository.ElasticsearchRepository; | ||
import com.wltt.issuetree.user.domain.User; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserRepository extends ElasticsearchRepository<User, String> { | ||
Optional<User> findByGithubId(String githubId); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/wltt/issuetree/user/parser/UserParser.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,16 @@ | ||
package com.wltt.issuetree.user.parser; | ||
|
||
import com.wltt.issuetree.global.SlackUrlEncodedForm; | ||
import com.wltt.issuetree.user.domain.User; | ||
|
||
public class UserParser { | ||
public static User parseToUser(final SlackUrlEncodedForm request) { | ||
final String userId = request.getUserId(); | ||
final String githubId = request.getText(); | ||
|
||
return User.of() | ||
.slackId(userId) | ||
.githubId(githubId) | ||
.build(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/wltt/issuetree/user/service/UserService.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,35 @@ | ||
package com.wltt.issuetree.user.service; | ||
|
||
import com.wltt.issuetree.global.SlackUrlEncodedForm; | ||
import com.wltt.issuetree.global.slasckbot.service.SlackbotService; | ||
import com.wltt.issuetree.user.domain.User; | ||
import com.wltt.issuetree.user.domain.repository.UserRepository; | ||
import com.wltt.issuetree.user.parser.UserParser; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private final UserRepository userRepository; | ||
private final SlackbotService slackbotService; | ||
|
||
@Transactional | ||
public void addUser(SlackUrlEncodedForm slackUrlEncodedForm) { | ||
final User user = UserParser.parseToUser(slackUrlEncodedForm); | ||
userRepository.save(user); | ||
|
||
final String header = "정상적으로 깃허브 아이디가 등록되었습니다."; | ||
String content | ||
= | ||
"*깃허브 아이디:*\n" + | ||
">" + slackUrlEncodedForm.getText() + "\n"; | ||
|
||
slackbotService.chatMessage( | ||
content, | ||
header, | ||
slackUrlEncodedForm.getUserId() | ||
); | ||
} | ||
} |