Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.0 #271

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/aws-cicd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- develop
- feat/LA-20_3

env:
REGISTRY: "docker.io"
Expand Down Expand Up @@ -56,6 +57,7 @@ jobs:
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-admin/src/main/resources/application-secret.properties

- name: Build layer-api module
run: ./gradlew :layer-api:build
Expand All @@ -69,6 +71,12 @@ jobs:
- name: Test layer-batch module
run: ./gradlew :layer-batch:test

- name: Build layer-admin module
run: ./gradlew :layer-admin:build

- name: Test layer-admin module
run: ./gradlew :layer-admin:test

- name: Docker Hub Login
uses: docker/login-action@v1
with:
Expand All @@ -82,6 +90,7 @@ jobs:
images: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin

- name: Push layer-api Docker Image
uses: docker/build-push-action@v4
Expand All @@ -104,6 +113,16 @@ jobs:
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest

- name: Push layer-admin Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-admin
file: ./layer-admin/Dockerfile-admin # Dockerfile ์ด๋ฆ„ ์ง€์ •
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin:latest

deploy:
name: Deploy
needs: [ build, setup ]
Expand All @@ -119,6 +138,7 @@ jobs:
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-admin/src/main/resources/application-secret.properties

- name: Archive Files
run: |
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/aws-cicd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- chore/migration

env:
REGISTRY: "docker.io"
Expand Down Expand Up @@ -57,6 +56,7 @@ jobs:
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-admin/src/main/resources/application-secret.properties

- name: Build layer-api module
run: ./gradlew :layer-api:build
Expand All @@ -70,6 +70,12 @@ jobs:
- name: Test layer-batch module
run: ./gradlew :layer-batch:test

- name: Build layer-admin module
run: ./gradlew :layer-admin:build

- name: Test layer-admin module
run: ./gradlew :layer-admin:test

- name: Docker Hub Login
uses: docker/login-action@v1
with:
Expand All @@ -83,6 +89,7 @@ jobs:
images: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin

- name: Push layer-api Docker Image
uses: docker/build-push-action@v4
Expand All @@ -106,6 +113,16 @@ jobs:
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
no-cache: true

- name: Push layer-admin Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-admin
file: ./layer-admin/Dockerfile-admin # Dockerfile ์ด๋ฆ„ ์ง€์ •
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin:latest

deploy:
name: Deploy
needs: [ build, setup ]
Expand All @@ -121,6 +138,7 @@ jobs:
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-admin/src/main/resources/application-secret.properties

- name: Archive Files
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ credentials.json


layer-api/src/main/resources/tokens/StoredCredential
layer-batch/src/main/resources/application-secret.properties
layer-batch/src/main/resources/application-secret.properties
layer-admin/src/main/resources/application-secret.properties
22 changes: 20 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ project(":layer-api") {
implementation project(path: ':layer-domain')
implementation project(path: ':layer-external')


implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-validation'

Expand All @@ -82,7 +81,6 @@ project(":layer-api") {
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
testImplementation 'org.springframework.boot:spring-boot-starter-test'


// openfeign
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:4.1.2")

Expand Down Expand Up @@ -195,4 +193,24 @@ project(":layer-batch") {
runtimeOnly 'com.mysql:mysql-connector-j'
}

}

project(":layer-admin") {
jar.enabled = false
bootJar.enabled = true

dependencies {
implementation project(path: ':layer-domain')

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'

// swagger
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
}

}
Binary file added config/tokens/StoredCredential.txt
Binary file not shown.
10 changes: 10 additions & 0 deletions layer-admin/Dockerfile-admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM openjdk:17

ARG JAR_FILE=./build/libs/*.jar
ARG SPRING_PROFILE

COPY ${JAR_FILE} layer-admin.jar

ENV SPRING_PROFILE=${SPRING_PROFILE}

ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul" ,"-jar" ,"layer-admin.jar"]
14 changes: 14 additions & 0 deletions layer-admin/src/main/java/org/layer/AdminApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.layer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}

}
23 changes: 23 additions & 0 deletions layer-admin/src/main/java/org/layer/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.layer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable) // CSRF ๋น„ํ™œ์„ฑํ™”
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll() // ๋ชจ๋“  ์š”์ฒญ ํ—ˆ์šฉ
)
.httpBasic(AbstractHttpConfigurer::disable); // HTTP Basic ์ธ์ฆ ๋น„ํ™œ์„ฑํ™”

return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.layer.member.controller;

import org.layer.member.controller.dto.GetMembersActivitiesResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "[ADMIN] ํšŒ์› ์„œ๋น„์Šค", description = "ํšŒ์› ๊ด€๋ จ api")
public interface AdminMemberApi {

@Operation(summary = "ํšŒ์› ํ™œ๋™ ๋ชฉ๋ก ์กฐํšŒ")
@Parameters({
@Parameter(name = "password", description = "ํŒจ์Šค์›Œ๋“œ", example = "abcdef", required = true),
@Parameter(name = "page", description = "ํŽ˜์ด์ง€ ์ˆ˜, ์ตœ์†Ÿ๊ฐ’ 1", example = "1", required = true),
@Parameter(name = "take", description = "๊ฐ€์ ธ์˜ฌ ๋ฐ์ดํ„ฐ ์ˆ˜", example = "20", required = true)
})
ResponseEntity<GetMembersActivitiesResponse> getMemberActivities(
@RequestParam String password,
@RequestParam int page,
@RequestParam int take);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.layer.member.controller;

import org.layer.member.controller.dto.GetMembersActivitiesResponse;
import org.layer.member.service.AdminMemberService;
import org.springframework.http.ResponseEntity;
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;

import lombok.RequiredArgsConstructor;

@RequestMapping("/members")
@RequiredArgsConstructor
@RestController
public class AdminMemberController implements AdminMemberApi {
private final AdminMemberService adminMemberService;

@Override
@GetMapping
public ResponseEntity<GetMembersActivitiesResponse> getMemberActivities(
@RequestParam String password,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "20") int take) {

return ResponseEntity.ok().body(adminMemberService.getMemberActivities(password, page, take));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.layer.member.controller.dto;

import java.time.LocalDateTime;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@Schema(name = "GetMemberActivityResponse", description = "ํšŒ์› ํ™œ๋™ Dto")
public record GetMemberActivityResponse(
@NotNull
@Schema(description = "ํšŒ์› ์ด๋ฆ„", example = "ํ™๊ธธ๋™")
String name,
@NotNull
@Schema(description = "์ตœ๊ทผ ํ™œ๋™ ๋‚ ์งœ", example = "2024-11-30T16:21:47.031Z")
LocalDateTime recentActivityDate,
@NotNull
@Schema(description = "์†Œ์†๋œ ์ŠคํŽ˜์ด์Šค ์ˆ˜", example = "7")
long spaceCount,
@NotNull
@Schema(description = "์ž‘์„ฑํ•œ ํšŒ๊ณ  ์ˆ˜", example = "15")
long retrospectAnswerCount,
@NotNull
@Schema(description = "ํšŒ์›๊ฐ€์ž… ๋‚ ์งœ", example = "2024-10-30T16:21:47.031Z")
LocalDateTime signUpDate,
@NotNull
@Schema(description = "ํšŒ์›๊ฐ€์ž… ํ”Œ๋žซํผ", example = "KAKAO")
String socialType
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.layer.member.controller.dto;

import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@Schema(name = "GetMembersActivitiesResponse", description = "ํšŒ์› ํ™œ๋™ ๋ชฉ๋ก Dto")
public record GetMembersActivitiesResponse(
@NotNull
@Schema(description = "ํšŒ์› ํ™œ๋™ ๋ชฉ๋ก", example = "")
List<GetMemberActivityResponse> responses

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.layer.member.service;

import java.util.List;

import org.layer.domain.answer.repository.AdminAnswerRepository;
import org.layer.domain.member.entity.Member;
import org.layer.domain.member.repository.AdminMemberRepository;
import org.layer.domain.space.repository.AdminMemberSpaceRelationRepository;
import org.layer.member.controller.dto.GetMemberActivityResponse;
import org.layer.member.controller.dto.GetMembersActivitiesResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class AdminMemberService {
private final AdminMemberRepository adminMemberRepository;
private final AdminMemberSpaceRelationRepository adminMemberSpaceRelationRepository;
private final AdminAnswerRepository adminAnswerRepository;

@Value("${admin.password}")
private String password;

public GetMembersActivitiesResponse getMemberActivities(String password, int page, int take) {

// TODO: ๊ฒ€์ฆ ๋กœ์ง ํ•„ํ„ฐ๋‹จ์œผ๋กœ ์˜ฎ๊ธฐ๊ธฐ
if (!password.equals(this.password)) {
throw new IllegalArgumentException("๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
}

PageRequest pageRequest = PageRequest.of(page - 1, take);
Page<Member> members = adminMemberRepository.findAll(pageRequest);

List<GetMemberActivityResponse> responses = members.getContent().stream()
.map(member -> {

Long spaceCount = adminMemberSpaceRelationRepository.countAllByMemberId(member.getId());
Long retrospectAnswerCount = adminAnswerRepository.countAllByMemberId(member.getId());

return new GetMemberActivityResponse(member.getName(), null, spaceCount, retrospectAnswerCount,
member.getCreatedAt(), member.getSocialType().name());
}).toList();

return new GetMembersActivitiesResponse(responses);
}
}
Loading
Loading