Skip to content

Commit

Permalink
�chore: spotless와 githook github workflow 추가 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirageoasis authored Aug 13, 2024
2 parents 26d3357 + a908e53 commit 642709d
Show file tree
Hide file tree
Showing 64 changed files with 851 additions and 570 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Spotless Check
on: [ pull_request ]

jobs:
spotless:
name: Spotless Check
runs-on: ubuntu-latest

steps:
- name: Clone repo with submodules
uses: actions/checkout@v3
with:
fetch-depth: 1
submodules: true # 서브모듈도 함께 체크아웃

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run Spotless
run: ./gradlew spotlessCheck
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
id 'com.diffplug.spotless' version '6.23.3'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}

Expand Down Expand Up @@ -56,10 +57,20 @@ dependencies {
}

tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
}

spotless {
java {
target 'src/**/*.java' // 대상 파일 지정
googleJavaFormat().aosp()
importOrder('java', 'javax', 'jakarta', 'org', 'com')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}

asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'
Expand Down
43 changes: 43 additions & 0 deletions scripts/install-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# implementation: team3-rdParty pre-commit and pre-push hook installer
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Original Author
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

install_git_hooks() {
local magic_str_commit="team3-rdParty standard pre-commit hook"
local magic_str_push="team3-rdParty standard pre-push hook"

# pre-commit hook 설정
if [ -f .git/hooks/pre-commit ]; then
grep -Fq "$magic_str_commit" .git/hooks/pre-commit
if [ $? -eq 0 ]; then
:
else
echo "" >> .git/hooks/pre-commit
cat scripts/pre-commit.sh >> .git/hooks/pre-commit
fi
else
cp scripts/pre-commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
fi

# pre-push hook 설정
if [ -f .git/hooks/pre-push ]; then
grep -Fq "$magic_str_push" .git/hooks/pre-push
if [ $? -eq 0 ]; then
:
else
echo "" >> .git/hooks/pre-push
cat scripts/pre-push.sh >> .git/hooks/pre-push
fi
else
cp scripts/pre-push.sh .git/hooks/pre-push
chmod +x .git/hooks/pre-push
fi
}

install_git_hooks
12 changes: 12 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# implementation: team3-rdParty pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

# backend.ai monorepo standard pre-commit hook
BASE_PATH=$(cd "$(dirname "$0")"/../.. && pwd)
${BASE_PATH}/scripts/pre-commit.sh "$@"
14 changes: 14 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# implementation: team3-rdParty pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

BASE_PATH=$(cd "$(dirname "$0")"/.. && pwd)
echo "Performing lint for changed files ..."

# Gradle을 사용하여 spotlessCheck 검사 수행
./gradlew spotlessCheck
12 changes: 12 additions & 0 deletions scripts/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# implementation: team3-rdParty pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoais
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

# team3-rdParty pre-push hook
BASE_PATH=$(cd "$(dirname "$0")"/../.. && pwd)
${BASE_PATH}/scripts/pre-push.sh "$@"
35 changes: 35 additions & 0 deletions scripts/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# implementation: team3-rdParty pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

BASE_PATH=$(cd "$(dirname "$0")"/.. && pwd)

CURRENT_COMMIT=$(git rev-parse --short HEAD)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -n "$(echo "$CURRENT_BRANCH" | sed -n '/^[[:digit:]]\{1,\}\.[[:digit:]]\{1,\}/p')" ]; then
# if we are on the release branch, use it as the base branch.
BASE_BRANCH="$CURRENT_BRANCH"
else
BASE_BRANCH="main"
fi
if [ "$1" != "origin" ]; then
# extract the owner name of the target repo
ORIGIN="$(echo "$1" | grep -o '://[^/]\+/[^/]\+/' | grep -o '/[^/]\+/$' | tr -d '/')"
cleanup_remote() {
git remote remove "$ORIGIN"
}
trap cleanup_remote EXIT
git remote add "$ORIGIN" "$1"
git fetch -q --depth=1 --no-tags "$ORIGIN" "$BASE_BRANCH"
else
ORIGIN="origin"
fi
echo "Performing lint and check on ${ORIGIN}/${BASE_BRANCH}..HEAD@${CURRENT_COMMIT} ..."

# Gradle을 사용하여 spotlessCheck 검사 수행
./gradlew spotlessCheck
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class TicketingApplication {
public static void main(String[] args) {
SpringApplication.run(TicketingApplication.class, args);
}

}
10 changes: 6 additions & 4 deletions src/main/java/com/thirdparty/ticketing/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.thirdparty.ticketing.domain;

import java.time.ZonedDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.ZonedDateTime;
import lombok.Getter;

import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Getter;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
Expand All @@ -16,8 +19,7 @@ public abstract class BaseEntity {
@Column(updatable = false)
private ZonedDateTime createdAt;

@LastModifiedDate
private ZonedDateTime updatedAt;
@LastModifiedDate private ZonedDateTime updatedAt;

public BaseEntity() {
createdAt = ZonedDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thirdparty.ticketing.domain.member;

import com.thirdparty.ticketing.domain.BaseEntity;
import java.time.ZonedDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand All @@ -9,7 +10,9 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;

import com.thirdparty.ticketing.domain.BaseEntity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.util.Arrays;
import java.util.Set;

import lombok.Getter;

@Getter
public enum MemberRole {
USER(Constant.ROLE_USER, Set.of(Constant.ROLE_USER)), ADMIN(Constant.ROLE_ADMIN, Set.of(Constant.ROLE_USER, Constant.ROLE_ADMIN));
USER(Constant.ROLE_USER, Set.of(Constant.ROLE_USER)),
ADMIN(Constant.ROLE_ADMIN, Set.of(Constant.ROLE_USER, Constant.ROLE_ADMIN));

private final String value;
private final Set<String> authorities;
Expand All @@ -23,7 +25,6 @@ public static MemberRole find(String value) {
.orElseThrow(() -> new IllegalArgumentException("해당하는 역할이 존재하지 않습니다."));
}


private static class Constant {
private static final String ROLE_USER = "ROLE_USER";
private static final String ROLE_ADMIN = "ROLE_ADMIN";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.thirdparty.ticketing.domain.member.controller;

import com.thirdparty.ticketing.domain.member.controller.request.LoginRequest;
import com.thirdparty.ticketing.domain.member.service.AuthService;
import com.thirdparty.ticketing.domain.member.service.response.LoginResponse;
import jakarta.validation.Valid;
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 com.thirdparty.ticketing.domain.member.controller.request.LoginRequest;
import com.thirdparty.ticketing.domain.member.service.AuthService;
import com.thirdparty.ticketing.domain.member.service.response.LoginResponse;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
Expand All @@ -19,8 +22,7 @@ public class AuthController {
private final AuthService authService;

@PostMapping("/login")
public ResponseEntity<LoginResponse> login(
@Valid @RequestBody LoginRequest request) {
public ResponseEntity<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
LoginResponse response = authService.login(request.getEmail(), request.getPassword());
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.thirdparty.ticketing.domain.member.controller;

import com.thirdparty.ticketing.domain.member.controller.request.MemberCreationRequest;
import com.thirdparty.ticketing.domain.member.service.MemberService;
import com.thirdparty.ticketing.domain.member.service.response.CreateMemberResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

import org.springframework.http.HttpStatus;
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 com.thirdparty.ticketing.domain.member.controller.request.MemberCreationRequest;
import com.thirdparty.ticketing.domain.member.service.MemberService;
import com.thirdparty.ticketing.domain.member.service.response.CreateMemberResponse;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/members")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

import org.hibernate.validator.constraints.Length;

import lombok.Data;

@Data
public class LoginRequest {
@Email(message = "이메일 형식이 유효하지 않습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

@Data
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.thirdparty.ticketing.domain.member.repository;

import com.thirdparty.ticketing.domain.member.Member;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import com.thirdparty.ticketing.domain.member.Member;

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.thirdparty.ticketing.domain.member.service;

import java.util.NoSuchElementException;

import jakarta.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.member.repository.MemberRepository;
import com.thirdparty.ticketing.domain.member.service.response.LoginResponse;
import jakarta.transaction.Transactional;
import java.util.NoSuchElementException;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@Transactional
Expand All @@ -18,10 +22,12 @@ public class AuthService {
private final JwtProvider jwtProvider;

public LoginResponse login(String email, String rawPassword) {
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new NoSuchElementException("이메일/비밀번호가 일치하지 않습니다."));
Member member =
memberRepository
.findByEmail(email)
.orElseThrow(() -> new NoSuchElementException("이메일/비밀번호가 일치하지 않습니다."));
passwordEncoder.checkMatches(member, rawPassword);
String accessToken = jwtProvider.createAccessToken(member);
String accessToken = jwtProvider.createAccessToken(member);
return LoginResponse.of(member, accessToken);
}
}
Loading

0 comments on commit 642709d

Please sign in to comment.