Skip to content

Commit

Permalink
fix: spotlessApply 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
lass9436 committed Aug 13, 2024
2 parents 559a75c + 642709d commit b640895
Show file tree
Hide file tree
Showing 77 changed files with 1,361 additions and 694 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
10 changes: 10 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

= 회원(Member)

== 회원 생성

=== request

operation::member-controller-test/create-member[snippets='http-request,request-fields']

=== response

operation::member-controller-test/create-member[snippets='http-response,response-fields']

= 공연(Performance)

= 장소(Place)
Expand Down
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
4 changes: 2 additions & 2 deletions src/main/java/com/thirdparty/ticketing/domain/ItemResult.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.thirdparty.ticketing.domain;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
public class ItemResult<T> {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/thirdparty/ticketing/domain/member/Member.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
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;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
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;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Builder
@AllArgsConstructor
@Table(name = "member")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {
Expand All @@ -23,10 +31,13 @@ public class Member extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long memberId;

@Column(nullable = false, unique = true)
private String email;

@Column(nullable = false)
private String password;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private MemberRole memberRole;

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
@@ -0,0 +1,31 @@
package com.thirdparty.ticketing.domain.member.controller;

import jakarta.validation.Valid;

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")
public class MemberController {

private final MemberService memberService;

@PostMapping
public ResponseEntity<CreateMemberResponse> createMember(
@RequestBody @Valid MemberCreationRequest request) {
CreateMemberResponse response = memberService.createMember(request);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}
}
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
Loading

0 comments on commit b640895

Please sign in to comment.