-
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.
Merge pull request #37 from aws-cloud-clubs/feat/follow_function_fix
Feat/follow function fix
- Loading branch information
Showing
76 changed files
with
2,697 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: deploy_lambda | ||
|
||
on: | ||
push: | ||
branches: [ feat/follow_service#6 ] | ||
workflow_dispatch: | ||
inputs: | ||
logLevel: | ||
description: 'Log level' | ||
required: true | ||
default: 'warning' | ||
tags: | ||
description: 'Test Deploy' | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: JDK 세팅 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle without test | ||
run: ./gradlew clean build buildZip | ||
|
||
- name: Create deployment package | ||
run: | | ||
mkdir -p deployment | ||
cp build/libs/*.jar deployment/ | ||
if [ -d "lib" ]; then | ||
cp -R lib/* deployment/ | ||
fi | ||
cd deployment | ||
zip -r ../follow_service.zip . | ||
- name: AWS 계정 세팅 | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: S3에 패키지 업로드 | ||
run: | | ||
aws s3 cp follow_service.zip s3://gureumi-s3/lambda-function.zip | ||
- name: 람다 배포 | ||
run: | | ||
aws lambda update-function-code \ | ||
--function-name ${{ secrets.LAMBDA_FOLLOW_FUNCTION_NAME }} \ | ||
--s3-bucket gureumi-s3 \ | ||
--s3-key lambda-function.zip |
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,61 @@ | ||
name: deploy_lambda | ||
|
||
on: | ||
push: | ||
branches: [ feat/like_service ] | ||
workflow_dispatch: | ||
inputs: | ||
logLevel: | ||
description: 'Log level' | ||
required: true | ||
default: 'warning' | ||
tags: | ||
description: 'Test Deploy' | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: JDK 세팅 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle without test | ||
run: ./gradlew clean build -x test buildZip | ||
|
||
- name: Create deployment package | ||
run: | | ||
mkdir -p deployment | ||
cp build/distributions/lambda-function.zip deployment/ | ||
if [ -d "lib" ]; then | ||
cp -R lib/* deployment/ | ||
fi | ||
cd deployment | ||
zip -r ../function.zip . | ||
- name: AWS 계정 세팅 | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: S3에 패키지 업로드 | ||
run: | | ||
aws s3 cp function.zip s3://gureumi-s3/deploy/function.zip | ||
- name: 람다 배포 | ||
run: | | ||
aws lambda update-function-code \ | ||
--function-name ${{ secrets.LAMBDA_FUNCTION_NAME }} \ | ||
--s3-bucket gureumi-s3 \ | ||
--s3-key deploy/function.zip |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/goormy/hackathon/common/util/LocalDateTimeConverter_DS.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,25 @@ | ||
package com.goormy.hackathon.common.util; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class LocalDateTimeConverter_DS { | ||
|
||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
public LocalDateTime convertToLocalDateTime(String source) { | ||
try { | ||
return LocalDateTime.parse(source, formatter); | ||
} catch (DateTimeParseException e) { | ||
throw new IllegalArgumentException( | ||
"Invalid date time format. Please use this pattern: yyyy-MM-dd HH:mm:ss"); | ||
} | ||
} | ||
|
||
public String convertToString(LocalDateTime source) { | ||
return source.format(formatter); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/goormy/hackathon/common/util/LocalDateTimeConverter__SY.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,15 @@ | ||
package com.goormy.hackathon.common.util; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public final class LocalDateTimeConverter__SY { | ||
|
||
private LocalDateTimeConverter__SY() { | ||
} | ||
|
||
public static String convert(LocalDateTime value) { | ||
return value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); | ||
} | ||
|
||
} |
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,32 @@ | ||
package com.goormy.hackathon.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.sqs.SqsClient; | ||
|
||
@Configuration | ||
public class AwsConfig { | ||
|
||
|
||
@Value("${spring.cloud.aws.credentials.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${spring.cloud.aws.credentials.secret-key}") | ||
private String secretKey; | ||
|
||
@Value("${spring.cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public SqsClient sqsClient() { | ||
return SqsClient.builder() | ||
.region(Region.of(region)) | ||
.credentialsProvider(StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create(accessKey, secretKey))) | ||
.build(); | ||
} | ||
} |
Empty file.
52 changes: 52 additions & 0 deletions
52
src/main/java/com/goormy/hackathon/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,52 @@ | ||
package com.goormy.hackathon.controller; | ||
|
||
import com.goormy.hackathon.dto.HashtagDto_sieun; | ||
import com.goormy.hackathon.entity.Hashtag; | ||
import com.goormy.hackathon.entity.User; | ||
import com.goormy.hackathon.service.FollowSQSService; | ||
import com.goormy.hackathon.service.FollowService; | ||
import com.goormy.hackathon.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
public class FollowController { | ||
|
||
@Autowired | ||
private FollowSQSService followSQSService; | ||
|
||
@Autowired | ||
private FollowService followService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@PostMapping("/follow") | ||
public ResponseEntity<String> follow(@RequestHeader long userId, @RequestParam long hashtagId) { | ||
followSQSService.sendFollowRequest(userId,hashtagId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@PostMapping("/unfollow") | ||
public ResponseEntity<String> unfollow(@RequestHeader long userId, @RequestParam long hashtagId) { | ||
followSQSService.sendUnfollowRequest(userId,hashtagId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@GetMapping("/followings") | ||
public List<HashtagDto_sieun> getFollowedHashtags(@RequestHeader("userId") Long userId) { | ||
User user = userService.findById(userId); | ||
|
||
List<Hashtag> hashtags = followService.getFollowedHashtags(user); | ||
|
||
return hashtags.stream() | ||
.map(hashtag -> new HashtagDto_sieun(hashtag.getId(), hashtag.getName(), hashtag.getType().toString())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.