├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── main │ ├── java │ │ └── com │ │ │ └── community │ │ │ └── soccer │ │ │ ├── domain │ │ │ ├── item │ │ │ │ ├── Position.java │ │ │ │ └── PositionDto.java │ │ │ ├── board │ │ │ │ ├── dao │ │ │ │ │ ├── BoardCreateDao.java │ │ │ │ │ ├── BoardSearchDao.java │ │ │ │ │ ├── BoardEditDao.java │ │ │ │ │ └── BoardFindDao.java │ │ │ │ ├── request │ │ │ │ │ ├── BoardCreateRequest.java │ │ │ │ │ └── BoardEditRequest.java │ │ │ │ └── Board.java │ │ │ ├── member │ │ │ │ ├── dao │ │ │ │ │ ├── MemberCreateDao.java │ │ │ │ │ ├── MemberFindAllDao.java │ │ │ │ │ ├── MemberLoginDao.java │ │ │ │ │ ├── MemberFindDao.java │ │ │ │ │ ├── MemberSearchDao.java │ │ │ │ │ └── MemberEditDao.java │ │ │ │ ├── request │ │ │ │ │ ├── CreateMemberRequest.java │ │ │ │ │ └── EditMemberRequest.java │ │ │ │ ├── dto │ │ │ │ │ └── MemberDto.java │ │ │ │ └── Member.java │ │ │ ├── game │ │ │ │ ├── dao │ │ │ │ │ ├── GameSearchDao.java │ │ │ │ │ ├── GameCreateDao.java │ │ │ │ │ ├── GameEditDao.java │ │ │ │ │ └── GameFindDao.java │ │ │ │ ├── request │ │ │ │ │ ├── GameEditRequest.java │ │ │ │ │ └── GameCreateRequest.java │ │ │ │ └── Game.java │ │ │ └── player │ │ │ │ ├── dao │ │ │ │ ├── PlayerCreateDao.java │ │ │ │ └── PlayerFindDao.java │ │ │ │ ├── request │ │ │ │ └── PlayerCreateRequest.java │ │ │ │ └── Player.java │ │ │ ├── error │ │ │ └── ErrorCreate.java │ │ │ ├── SoccerApplication.java │ │ │ ├── exception │ │ │ └── PageRequestException.java │ │ │ ├── repository │ │ │ ├── PlayerRepository.java │ │ │ ├── MemberRepository.java │ │ │ ├── BoardRepository.java │ │ │ └── GameRepository.java │ │ │ ├── service │ │ │ ├── BoardService.java │ │ │ ├── MemberService.java │ │ │ ├── GameService.java │ │ │ └── PlayerService.java │ │ │ ├── config │ │ │ └── CorsFilter.java │ │ │ └── controller │ │ │ ├── PlayerApiController.java │ │ │ ├── MemberApiController.java │ │ │ ├── BoardApiController.java │ │ │ └── GameApiController.java │ └── resources │ │ └── application.yml └── test │ └── java │ └── com │ └── community │ └── soccer │ ├── SoccerApplicationTests.java │ ├── controller │ └── GameApiControllerTest.java │ └── service │ └── MemberServiceTest.java ├── README.md ├── .gitignore ├── .github └── workflows │ └── main.yml ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'soccer' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PersesTitan/Spring-Soccer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/item/Position.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.item; 2 | 3 | public enum Position { 4 | FW, MF, DF, GK 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/dao/BoardCreateDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.dao; 2 | 3 | public record BoardCreateDao(Long id) { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/dao/BoardSearchDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.dao; 2 | 3 | public record BoardSearchDao(T boardList) { } -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberCreateDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | public record MemberCreateDao(Long id) { } 4 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberFindAllDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | public record MemberFindAllDao (T members) { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberLoginDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | public record MemberLoginDao(String loginId, String password) { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/request/BoardCreateRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.request; 2 | 3 | public record BoardCreateRequest(String title, String content) { } 4 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/request/BoardEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.request; 2 | 3 | public record BoardEditRequest(String title, String content) { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/item/PositionDto.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.item; 2 | 3 | public record PositionDto(Integer masterFW, Integer masterMF, Integer masterDF, Integer masterGK) { } 4 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/request/CreateMemberRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.request; 2 | 3 | public record CreateMemberRequest(String loginId, String nickName, String password) { } 4 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/error/ErrorCreate.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.error; 2 | 3 | public class ErrorCreate extends RuntimeException { 4 | public ErrorCreate(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dto/MemberDto.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dto; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public record MemberDto(Long id, String nickName, LocalDateTime createDate) { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberFindDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public record MemberFindDao(Long id, String nickName, LocalDateTime createDate) { 6 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 9th-soccer-BE 2 | 3 |
4 | 5 | ### 축구 커뮤니티 웹 사이트 프로젝트 6 | 7 | - 엔티티 클래스 & ERD 설계 링크: [Click me! 비밀번호: 7717](https://gitmind.com/app/flowchart/cf611704042) 8 | - API 링크: [Click me!](https://www.notion.so/API-0759d2678d6a4b698aa608bd1a64fd27) 9 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/dao/GameSearchDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.dao; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | 5 | import java.util.List; 6 | 7 | public record GameSearchDao(List games) { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/player/dao/PlayerCreateDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.player.dao; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | 5 | public record PlayerCreateDao(Long id, Position position, String phone) { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/player/dao/PlayerFindDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.player.dao; 2 | 3 | import com.community.soccer.domain.player.Player; 4 | 5 | import java.util.List; 6 | 7 | public record PlayerFindDao(List players) { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/player/request/PlayerCreateRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.player.request; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | 5 | public record PlayerCreateRequest(Position position, String phone) { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberSearchDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | 5 | import java.util.List; 6 | 7 | public record MemberSearchDao(List members) { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/dao/MemberEditDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.dao; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public record MemberEditDao(Long id, String password, String loginId, String nickName, LocalDateTime createDate) { } 6 | -------------------------------------------------------------------------------- /src/test/java/com/community/soccer/SoccerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SoccerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/com/community/soccer/controller/GameApiControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.controller; 2 | 3 | import org.springframework.boot.test.context.SpringBootTest; 4 | import org.springframework.transaction.annotation.Transactional; 5 | 6 | @SpringBootTest 7 | @Transactional 8 | class GameApiControllerTest { 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/SoccerApplication.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SoccerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SoccerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/dao/BoardEditDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.dao; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | public record BoardEditDao(Long id, String title, String content, T member, 8 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 9 | LocalDateTime localDateTime) { } 10 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | # database 3 | datasource: 4 | url: jdbc:postgresql://ec2-54-159-22-90.compute-1.amazonaws.com:5432/ddi1o6vilfp7tg 5 | username: qytqnhuinsxveb 6 | password: e7c8fd7ce8f147f9fffd5c8e4c9e1c939ededd3e0245607fa907454193670901 7 | 8 | # jpa 9 | jpa: 10 | database: postgresql 11 | show-sql: true 12 | hibernate: 13 | ddl-auto: update 14 | dialect: org.hibernate.dialect.PostgreSQL10DialectDialect -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/request/EditMemberRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member.request; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | public record EditMemberRequest(String id, String password, String loginId, String nickName, 8 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 9 | LocalDateTime createDate) { } 10 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/exception/PageRequestException.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.exception; 2 | 3 | public class PageRequestException extends RuntimeException { 4 | public PageRequestException() { 5 | super(); 6 | } 7 | 8 | public PageRequestException(String message) { 9 | super(message); 10 | } 11 | 12 | public PageRequestException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/dao/BoardFindDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board.dao; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | 6 | import java.time.LocalDateTime; 7 | 8 | public record BoardFindDao(Long id, String title, String content, Member member, 9 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 10 | LocalDateTime localDateTime) { } 11 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/request/GameEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.request; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | public record GameEditRequest(@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 8 | LocalDateTime startDate, 9 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 10 | LocalDateTime endDate, String region) { } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | 39 | # yml 올라감 방지 40 | application-oauth.yml -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/dao/GameCreateDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.dao; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | 6 | import java.time.LocalDateTime; 7 | import java.util.Map; 8 | 9 | public record GameCreateDao(Long id, String title, String place, String region, 10 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 11 | LocalDateTime startDate, 12 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 13 | LocalDateTime endDate, 14 | Map requirePlayer, String description) { } 15 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/request/GameCreateRequest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.request; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | 6 | import java.time.LocalDateTime; 7 | import java.util.Map; 8 | 9 | public record GameCreateRequest(String title, String place, String region, 10 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 11 | LocalDateTime startDate, 12 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 13 | LocalDateTime endDate, 14 | Map requirePlayer, String description) { } 15 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/dao/GameEditDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.dao; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | import com.community.soccer.domain.player.Player; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public record GameEditDao(Long id, String title, String place, String region, 12 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 13 | LocalDateTime startDate, 14 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 15 | LocalDateTime endDate, 16 | Map requirePlayer, 17 | String description, List players) { } 18 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/dao/GameFindDao.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game.dao; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | import com.community.soccer.domain.player.Player; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public record GameFindDao(Long id, String title, String place, String region, 12 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 13 | LocalDateTime startDate, 14 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 15 | LocalDateTime endDate, 16 | Map requirePlayer, 17 | String description, List players) { } 18 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/repository/PlayerRepository.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.repository; 2 | 3 | import com.community.soccer.domain.player.Player; 4 | import lombok.RequiredArgsConstructor; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.persistence.EntityManager; 8 | import java.util.List; 9 | 10 | @Repository 11 | @RequiredArgsConstructor 12 | public class PlayerRepository { 13 | 14 | private final EntityManager em; 15 | 16 | public void save(Player player) { 17 | em.persist(player); 18 | } 19 | 20 | public void remove(Player player) { 21 | em.remove(player); 22 | } 23 | 24 | //Player 조회하는 로직 25 | public Player findOne(Long id) { 26 | return em.find(Player.class, id); 27 | } 28 | 29 | //모든 Player 조회하는 로직 30 | public List findAll() { 31 | return em.createQuery("SELECT P FROM Player AS P", Player.class) 32 | .getResultList(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/community/soccer/service/MemberServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.service; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import com.community.soccer.repository.MemberRepository; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | @SpringBootTest 13 | @Transactional 14 | class MemberServiceTest { 15 | 16 | @Autowired 17 | MemberService memberService; 18 | @Autowired 19 | MemberRepository memberRepository; 20 | 21 | @Test 22 | public void 회원가입() { 23 | //given 24 | Member member = Member.createMember("TestLoginId", "TestNickName"); 25 | 26 | //when 27 | Long id = memberService.save(member); 28 | 29 | //then 30 | assertEquals(member, memberRepository.findOne(id)); 31 | } 32 | } -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "master" branch 8 | push: 9 | branches: [ "master" ] 10 | pull_request: 11 | branches: [ "master" ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | - name: checkout 26 | uses: actions/checkout@v3 27 | with: 28 | repository: Couch-Coders/9th-soccer-BE 29 | path: ./be 30 | - uses: actions/setup-java@v3 31 | with: 32 | distribution: 'temurin' 33 | java-version: '17' 34 | - uses: CDNievas/heroku-action@v1.0 35 | with: 36 | heroku_app_name: "soccer-community" 37 | heroku_email: "torampersestitan@gmail.com" 38 | heroku_api_key: ${{secrets.HEROKU_API_KEY}} 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/repository/MemberRepository.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.repository; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import lombok.RequiredArgsConstructor; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.persistence.EntityManager; 8 | import java.util.List; 9 | 10 | @Repository 11 | @RequiredArgsConstructor 12 | public class MemberRepository { 13 | 14 | private final EntityManager em; 15 | 16 | public void save(Member member) { 17 | em.persist(member); 18 | } 19 | 20 | //회원 삭제 21 | public void remove(Member member) { 22 | em.remove(member); 23 | } 24 | 25 | //정보 업데이트 26 | public Member update(Member member, String nickName) { 27 | member.setNickName(nickName); 28 | return member; 29 | } 30 | 31 | //아이디 조회 32 | public Member findOne(Long id) { 33 | return em.find(Member.class, id); 34 | } 35 | 36 | //모든 맴버 리스트 37 | public List findAll() { 38 | return em.createQuery("SELECT M FROM Member AS M", Member.class) 39 | .getResultList(); 40 | } 41 | 42 | //닉네임 검색 로직 43 | public List findSearch(String keyWord) { 44 | return em.createQuery("SELECT M FROM Member AS M WHERE M.nickName LIKE :keyWord", Member.class) 45 | .setParameter("keyWord", "%"+keyWord+"%") 46 | .getResultList(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/service/BoardService.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.service; 2 | 3 | import com.community.soccer.domain.board.Board; 4 | import com.community.soccer.repository.BoardRepository; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | @RequiredArgsConstructor 13 | @Transactional(readOnly = true) 14 | public class BoardService { 15 | 16 | private final BoardRepository boardRepository; 17 | 18 | @Transactional 19 | public Long save(Board board) { 20 | boardRepository.save(board); 21 | return board.getId(); 22 | } 23 | 24 | @Transactional 25 | public void update(Long id, String title, String content) { 26 | Board board = boardRepository.findOne(id); 27 | boardRepository.update(board, title, content); 28 | } 29 | 30 | @Transactional 31 | public void remove(Long id) { 32 | Board board = boardRepository.findOne(id); 33 | boardRepository.remove(board); 34 | } 35 | 36 | public Board findOne(Long id) { 37 | return boardRepository.findOne(id); 38 | } 39 | 40 | public List findAll(int firstRes) { 41 | return boardRepository.findAll(firstRes); 42 | } 43 | 44 | public List findSearch(String title, int firstRes) { 45 | if (title.isBlank()) return boardRepository.findAll(firstRes); 46 | else return boardRepository.findSearch(title, firstRes); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/repository/BoardRepository.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.repository; 2 | 3 | import com.community.soccer.domain.board.Board; 4 | import lombok.RequiredArgsConstructor; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.persistence.EntityManager; 8 | import java.util.List; 9 | 10 | @Repository 11 | @RequiredArgsConstructor 12 | public class BoardRepository { 13 | public static final int PAGE_COUNT = 10; 14 | private final EntityManager em; 15 | 16 | //저장 로직 17 | public void save(Board board) { 18 | em.persist(board); 19 | } 20 | 21 | //삭제 로직 22 | public void remove(Board board) { 23 | em.remove(board); 24 | } 25 | 26 | public void update(Board board, String title, String content) { 27 | board.update(title, content); 28 | } 29 | 30 | public Board findOne(Long id) { 31 | return em.find(Board.class, id); 32 | } 33 | 34 | public List findAll(int firstRes) { 35 | return em.createQuery("SELECT b FROM Board AS b", Board.class) 36 | .setFirstResult(firstRes * PAGE_COUNT) 37 | .setMaxResults(PAGE_COUNT) 38 | .getResultList(); 39 | } 40 | 41 | public List findSearch(String title, int firstRes) { 42 | return em.createQuery("SELECT b FROM Board AS b WHERE b.title = :title", Board.class) 43 | .setParameter("title", "%" + title + "%") 44 | .setFirstResult(firstRes * PAGE_COUNT) 45 | .setMaxResults(PAGE_COUNT) 46 | .getResultList(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/service/MemberService.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.service; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import com.community.soccer.domain.member.dao.MemberEditDao; 5 | import com.community.soccer.domain.member.request.EditMemberRequest; 6 | import com.community.soccer.repository.MemberRepository; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | import java.util.List; 12 | 13 | @Service 14 | @Transactional(readOnly = true) 15 | @RequiredArgsConstructor 16 | public class MemberService { 17 | 18 | private final MemberRepository memberRepository; 19 | 20 | @Transactional 21 | public Long save(Member member) { 22 | memberRepository.save(member); 23 | return member.getId(); 24 | } 25 | 26 | @Transactional 27 | public Member update(Long id, EditMemberRequest request) { 28 | Member member = memberRepository.findOne(id); 29 | String nickName = request.nickName(); 30 | 31 | member.setNickName(nickName); 32 | return memberRepository.update(member, nickName); 33 | } 34 | 35 | @Transactional 36 | public void remove(Long id) { 37 | Member member = memberRepository.findOne(id); 38 | memberRepository.remove(member); 39 | } 40 | 41 | public Member findOne(Long id) { 42 | return memberRepository.findOne(id); 43 | } 44 | 45 | public List findSearch(String keyWord) { 46 | if (keyWord == null || keyWord.isBlank()) return memberRepository.findAll(); 47 | else return memberRepository.findSearch(keyWord); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/config/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.core.Ordered; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.servlet.*; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | @Component 14 | @Order(Ordered.HIGHEST_PRECEDENCE) 15 | @Slf4j 16 | public class CorsFilter implements Filter { 17 | 18 | @Override 19 | public void init(FilterConfig filterConfig) throws ServletException { 20 | 21 | } 22 | 23 | @Override 24 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 25 | HttpServletRequest req = (HttpServletRequest) request; 26 | HttpServletResponse res = (HttpServletResponse) response; 27 | 28 | res.setHeader("Access-Control-Allow-Origin", "*"); 29 | res.setHeader("Access-Control-Allow-Credentials", "true"); 30 | res.setHeader("Access-Control-Allow-Methods","*"); 31 | res.setHeader("Access-Control-Max-Age", "3600"); 32 | res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); 33 | 34 | if("OPTIONS".equalsIgnoreCase(req.getMethod())) { 35 | log.info("host : " + req.getRemoteHost()); 36 | log.info("addr : " + req.getRemoteAddr()); 37 | log.info("port : " + req.getRemotePort()); 38 | res.setStatus(HttpServletResponse.SC_OK); 39 | } else { 40 | chain.doFilter(req, res); 41 | } 42 | } 43 | 44 | @Override 45 | public void destroy() { 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/player/Player.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.player; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | import com.community.soccer.domain.item.Position; 5 | import lombok.AccessLevel; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import org.hibernate.Hibernate; 9 | 10 | import javax.persistence.*; 11 | import javax.validation.constraints.Pattern; 12 | import java.util.Objects; 13 | 14 | @Entity @Getter 15 | @NoArgsConstructor(access = AccessLevel.PROTECTED) 16 | public class Player { 17 | 18 | @Id @GeneratedValue 19 | @Column(name = "player_id") 20 | private Long id; 21 | 22 | @JoinColumn(name = "game_id") 23 | @ManyToOne(fetch = FetchType.LAZY) 24 | private Game game; 25 | 26 | @Enumerated(EnumType.STRING) 27 | private Position position; 28 | 29 | @Pattern(regexp = "^0\\d{1,2}(-\\d{3,4}-\\d{4}|\\d{7,8})$") 30 | private String phone; 31 | 32 | private Player(Position position, String phone) { 33 | this.position = position; 34 | this.phone = phone; 35 | } 36 | 37 | //생성 로직 38 | public static Player createPlayer(Position position, String phone) { 39 | return new Player(position, phone); 40 | } 41 | 42 | //연관 관계 편의 메소드 43 | public void setGame(Game game) { 44 | this.game = game; 45 | game.getPlayers().add(this); 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; 52 | Player player = (Player) o; 53 | return id != null && Objects.equals(id, player.id); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return getClass().hashCode(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/controller/PlayerApiController.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.controller; 2 | 3 | import com.community.soccer.domain.item.Position; 4 | import com.community.soccer.domain.player.Player; 5 | import com.community.soccer.domain.player.dao.PlayerCreateDao; 6 | import com.community.soccer.domain.player.dao.PlayerFindDao; 7 | import com.community.soccer.domain.player.request.PlayerCreateRequest; 8 | import com.community.soccer.service.PlayerService; 9 | import lombok.RequiredArgsConstructor; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import javax.validation.Valid; 13 | import java.util.List; 14 | 15 | @RestController 16 | @RequiredArgsConstructor 17 | @RequestMapping("/games") 18 | public class PlayerApiController { 19 | 20 | private final PlayerService playerService; 21 | 22 | @PostMapping("{game_id}/players") 23 | public PlayerCreateDao create(@PathVariable(name = "game_id") Long gameId, 24 | @RequestBody @Valid PlayerCreateRequest playerCreateRequest) { 25 | String phone = playerCreateRequest.phone(); 26 | Position position = playerCreateRequest.position(); 27 | Player player = playerService.save(gameId, position, phone); 28 | return new PlayerCreateDao(player.getId(), position, phone); 29 | } 30 | 31 | @GetMapping("{game_id}/players") 32 | public PlayerFindDao find(@PathVariable(name = "game_id") Long gameId) { 33 | List players = playerService.findAll(gameId); 34 | return new PlayerFindDao(players); 35 | } 36 | 37 | @DeleteMapping("{game_id}/players/{player_id}") 38 | public void remove(@PathVariable(name = "game_id") Long gameId, 39 | @PathVariable(name = "player_id") Long playerId) { 40 | playerService.remove(gameId, playerId); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/service/GameService.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.service; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | import com.community.soccer.repository.GameRepository; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import java.time.LocalDateTime; 10 | import java.util.List; 11 | 12 | @Service 13 | @Transactional(readOnly = true) 14 | @RequiredArgsConstructor 15 | public class GameService { 16 | 17 | private final GameRepository gameRepository; 18 | 19 | @Transactional 20 | public Long save(Game game) { 21 | gameRepository.save(game); 22 | return game.getId(); 23 | } 24 | 25 | @Transactional 26 | public Game update(Long id, LocalDateTime startDate, LocalDateTime endDate, String region) { 27 | Game game = gameRepository.findOne(id); 28 | return gameRepository.update(game, startDate, endDate, region); 29 | } 30 | 31 | @Transactional 32 | public void remove(Long id) { 33 | Game game = gameRepository.findOne(id); 34 | gameRepository.remove(game); 35 | } 36 | 37 | public Game findOne(Long id) { 38 | return gameRepository.findOne(id); 39 | } 40 | 41 | public List findAll(int pages) { 42 | return gameRepository.findAll(pages); 43 | } 44 | 45 | public List findSearch(LocalDateTime dateTime, String region, int pages) { 46 | return gameRepository.findSearch(dateTime, region, pages); 47 | } 48 | 49 | public List findRegion(String region, int pages) { 50 | return gameRepository.findRegion(region, pages); 51 | } 52 | 53 | public List findDate(LocalDateTime date, int pages) { 54 | return gameRepository.findDate(date, pages); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/board/Board.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.board; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import lombok.AccessLevel; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | import org.hibernate.Hibernate; 9 | 10 | import javax.persistence.*; 11 | import java.time.LocalDateTime; 12 | import java.util.Objects; 13 | 14 | @Entity @Getter 15 | @NoArgsConstructor(access = AccessLevel.PROTECTED) 16 | public class Board { 17 | 18 | @Id @GeneratedValue 19 | @Column(name = "board_id") 20 | private Long id; 21 | 22 | @Setter 23 | private String title; 24 | @Setter @Column(columnDefinition = "TEXT") 25 | private String content; 26 | private LocalDateTime createDate; 27 | 28 | @OneToOne(fetch = FetchType.LAZY) 29 | @JoinColumn(name = "member_id") 30 | private Member member; 31 | 32 | private Board(String title, String content, Member member) { 33 | this.title = title; 34 | this.content = content; 35 | this.member = member; 36 | createDate = LocalDateTime.now(); 37 | } 38 | 39 | //생성 로직 40 | public static Board createBoard(String title, String content, Member member) { 41 | return new Board(title, content, member); 42 | } 43 | 44 | //update 45 | public void update(String title, String content) { 46 | this.setTitle(title); 47 | this.setContent(content); 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) return true; 53 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; 54 | Board board = (Board) o; 55 | return id != null && Objects.equals(id, board.id); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return getClass().hashCode(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/member/Member.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.member; 2 | 3 | import lombok.AccessLevel; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | import org.hibernate.Hibernate; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.validation.constraints.NotBlank; 14 | import javax.validation.constraints.PastOrPresent; 15 | import java.time.LocalDateTime; 16 | import java.util.Objects; 17 | 18 | @Entity @Getter 19 | @NoArgsConstructor(access = AccessLevel.PROTECTED) 20 | public class Member { 21 | 22 | @Id @GeneratedValue 23 | @Column(name = "member_id") 24 | private Long id; 25 | 26 | @Setter @NotBlank 27 | @Column(unique = true) 28 | private String loginId; 29 | @Setter @NotBlank 30 | private String nickName; 31 | @Setter @NotBlank 32 | private String password; 33 | @PastOrPresent 34 | private LocalDateTime createDate; 35 | 36 | private Member(String loginId, String nickName, String password) { 37 | this.loginId = loginId; 38 | this.nickName = nickName; 39 | this.password = password; 40 | createDate = LocalDateTime.now(); 41 | } 42 | 43 | //생성 로직 44 | public static Member createMember(String loginId, String nickName, String password) { 45 | return new Member(loginId, nickName, password); 46 | } 47 | 48 | //equals 49 | @Override 50 | public boolean equals(Object o) { 51 | if (this == o) return true; 52 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; 53 | Member member = (Member) o; 54 | return id != null && Objects.equals(id, member.id); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return getClass().hashCode(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/service/PlayerService.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.service; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | import com.community.soccer.domain.item.Position; 5 | import com.community.soccer.domain.item.PositionDto; 6 | import com.community.soccer.domain.player.Player; 7 | import com.community.soccer.exception.PageRequestException; 8 | import com.community.soccer.repository.GameRepository; 9 | import com.community.soccer.repository.PlayerRepository; 10 | import lombok.RequiredArgsConstructor; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import java.util.List; 15 | import java.util.Objects; 16 | import java.util.Optional; 17 | 18 | @Service 19 | @Transactional(readOnly = true) 20 | @RequiredArgsConstructor 21 | public class PlayerService { 22 | 23 | private final PlayerRepository playerRepository; 24 | private final GameRepository gameRepository; 25 | 26 | @Transactional 27 | public Player save(Long gameId, Position position, String phone) { 28 | Player player = Player.createPlayer(position, phone); 29 | Game game = gameRepository.findOne(gameId); 30 | player.setGame(game); 31 | playerRepository.save(player); 32 | return player; 33 | } 34 | 35 | public List findAll(Long gameId) { 36 | return gameRepository.findOne(gameId).getPlayers(); 37 | } 38 | 39 | @Transactional 40 | public void remove(Long gameId, Long playerId) { 41 | List players = gameRepository 42 | .findOne(gameId) 43 | .getPlayers() 44 | .stream() 45 | .filter(Objects::nonNull) 46 | .filter(v -> Objects.equals(v.getId(), playerId)) 47 | .findFirst() 48 | .stream() 49 | .toList(); 50 | if (players.isEmpty()) throw new PageRequestException("페이지 요청 요류"); 51 | playerRepository.remove(players.get(0)); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/repository/GameRepository.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.repository; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | import com.community.soccer.domain.member.Member; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import javax.persistence.EntityManager; 9 | import java.time.LocalDateTime; 10 | import java.util.List; 11 | 12 | @Repository 13 | @RequiredArgsConstructor 14 | public class GameRepository { 15 | public static final int PAGE_COUNT = 10; 16 | private final EntityManager em; 17 | 18 | public void save(Game game) { 19 | em.persist(game); 20 | } 21 | 22 | // 삭제 23 | public void remove(Game game) { 24 | em.remove(game); 25 | } 26 | 27 | // 업데이트 로직 28 | public Game update(Game game, LocalDateTime startDate, LocalDateTime endDate, String region) { 29 | game.update(startDate, endDate, region); 30 | return game; 31 | } 32 | 33 | //게임 조회 34 | public Game findOne(Long id) { 35 | return em.find(Game.class, id); 36 | } 37 | 38 | public List findAll(int firstRes) { 39 | return em.createQuery("SELECT G FROM Game AS G", Game.class) 40 | .setFirstResult(firstRes * PAGE_COUNT) 41 | .setMaxResults(firstRes) 42 | .getResultList(); 43 | } 44 | 45 | public List findSearch(LocalDateTime date, String region, int firstRes) { 46 | return em.createQuery("SELECT G FROM Game G WHERE (:date BETWEEN G.startDate AND G.endDate) AND G.region LIKE :region", Game.class) 47 | .setParameter("date", date) 48 | .setParameter("region", "%" + region + "%") 49 | .setFirstResult(firstRes * PAGE_COUNT) 50 | .setMaxResults(PAGE_COUNT) 51 | .getResultList(); 52 | } 53 | 54 | public List findRegion(String region, int firstRes) { 55 | return em.createQuery("SELECT G FROM Game G WHERE G.region LIKE :region", Game.class) 56 | .setParameter("region", "%" + region + "%") 57 | .setFirstResult(firstRes * PAGE_COUNT) 58 | .setMaxResults(PAGE_COUNT) 59 | .getResultList(); 60 | } 61 | 62 | public List findDate(LocalDateTime date, int firstRes) { 63 | return em.createQuery("SELECT G FROM Game g WHERE (:date BETWEEN G.startDate AND G.endDate)", Game.class) 64 | .setParameter("date", date) 65 | .setFirstResult(firstRes * PAGE_COUNT) 66 | .setMaxResults(PAGE_COUNT) 67 | .getResultList(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/controller/MemberApiController.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.controller; 2 | 3 | import com.community.soccer.domain.member.Member; 4 | import com.community.soccer.domain.member.dao.MemberCreateDao; 5 | import com.community.soccer.domain.member.dao.MemberEditDao; 6 | import com.community.soccer.domain.member.dao.MemberFindDao; 7 | import com.community.soccer.domain.member.request.CreateMemberRequest; 8 | import com.community.soccer.domain.member.request.EditMemberRequest; 9 | import com.community.soccer.service.MemberService; 10 | import lombok.RequiredArgsConstructor; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.validation.Valid; 15 | import java.time.LocalDateTime; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | @RestController 20 | @RequestMapping("/members") 21 | @RequiredArgsConstructor 22 | public class MemberApiController { 23 | 24 | private final MemberService memberService; 25 | 26 | @PostMapping("") 27 | public MemberCreateDao createMember(@RequestBody @Valid CreateMemberRequest request) { 28 | String loginId = request.loginId(); 29 | String nickName = request.nickName(); 30 | String password = request.password(); 31 | Member member = Member.createMember(loginId, nickName, password); 32 | memberService.save(member); 33 | return new MemberCreateDao(member.getId()); 34 | } 35 | 36 | @GetMapping("/{id}") 37 | public MemberFindDao findOne(@PathVariable("id") Long id) { 38 | Member member = memberService.findOne(id); 39 | String nickName = member.getNickName(); 40 | LocalDateTime createDate = member.getCreateDate(); 41 | 42 | return new MemberFindDao(id, nickName, createDate); 43 | } 44 | 45 | @PatchMapping("/{id}") 46 | public MemberEditDao findEdit(@PathVariable("id") Long id, 47 | @RequestBody @Valid EditMemberRequest request) { 48 | String nickName = request.nickName(); 49 | String password = request.password(); 50 | String loginId = request.loginId(); 51 | LocalDateTime createDate = request.createDate(); 52 | 53 | return new MemberEditDao(id, password, loginId, nickName, createDate); 54 | } 55 | 56 | @DeleteMapping("/{id}") 57 | public void remove(@PathVariable("id") Long id) { 58 | memberService.remove(id); 59 | } 60 | 61 | @GetMapping("") 62 | public List memberSearch(HttpServletRequest request) { 63 | String keyword = request.getParameter("keyword"); 64 | return memberService.findSearch(keyword) 65 | .stream() 66 | .map(o -> new MemberFindDao( 67 | o.getId(), 68 | o.getNickName(), 69 | o.getCreateDate())) 70 | .collect(Collectors.toList()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/controller/BoardApiController.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.controller; 2 | 3 | import com.community.soccer.domain.board.Board; 4 | import com.community.soccer.domain.board.dao.BoardCreateDao; 5 | import com.community.soccer.domain.board.dao.BoardEditDao; 6 | import com.community.soccer.domain.board.dao.BoardFindDao; 7 | import com.community.soccer.domain.board.dao.BoardSearchDao; 8 | import com.community.soccer.domain.board.request.BoardCreateRequest; 9 | import com.community.soccer.domain.member.Member; 10 | import com.community.soccer.error.ErrorCreate; 11 | import com.community.soccer.service.BoardService; 12 | import com.community.soccer.service.MemberService; 13 | import lombok.RequiredArgsConstructor; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.validation.Valid; 17 | import java.time.LocalDateTime; 18 | import java.util.List; 19 | import java.util.stream.Collectors; 20 | 21 | @RestController 22 | @RequestMapping("/boards") 23 | @RequiredArgsConstructor 24 | public class BoardApiController { 25 | 26 | private final MemberService memberService; 27 | private final BoardService boardService; 28 | 29 | @PostMapping("") 30 | public BoardCreateDao saveBoard( 31 | @RequestBody @Valid BoardCreateRequest request, 32 | @CookieValue(name = "memberId", required = false) Long memberId) { 33 | // 로그인이 되어있지 않으면 에러 발생 34 | if (memberId == null) throw new ErrorCreate("로그인이 필요합니다."); 35 | String title = request.title(); 36 | String content = request.content(); 37 | Member member = memberService.findOne(memberId); 38 | Board board = Board.createBoard(title, content, member); 39 | 40 | return new BoardCreateDao(board.getId()); 41 | } 42 | 43 | @GetMapping("/{id}") 44 | public BoardFindDao findOne(@PathVariable("id") Long id) { 45 | Board board = boardService.findOne(id); 46 | String title = board.getTitle(); 47 | String content = board.getContent(); 48 | Member member = board.getMember(); 49 | LocalDateTime createDate = board.getCreateDate(); 50 | 51 | return new BoardFindDao(id, title, content, member, createDate); 52 | } 53 | 54 | @PatchMapping("/{id}") 55 | public BoardEditDao boardEdit(@PathVariable("id") Long id) { 56 | Board board = boardService.findOne(id); 57 | String title = board.getTitle(); 58 | String content = board.getContent(); 59 | Member member = board.getMember(); 60 | LocalDateTime createDate = board.getCreateDate(); 61 | return new BoardEditDao(id, title, content, member, createDate); 62 | } 63 | 64 | @DeleteMapping("/{id}") 65 | public void remove(@PathVariable("id") Long id) { 66 | boardService.remove(id); 67 | } 68 | 69 | @GetMapping("") 70 | public List boardSearchDao( 71 | @RequestParam(value = "title", defaultValue = "") String title, 72 | @RequestParam(value = "page", defaultValue = "0") int page) { 73 | return boardService.findSearch(title, page) 74 | .stream() 75 | .map(value -> new BoardSearchDao(value)) 76 | .collect(Collectors.toList()); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/domain/game/Game.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.domain.game; 2 | 3 | import com.community.soccer.domain.item.PositionDto; 4 | import com.community.soccer.domain.player.Player; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import lombok.AccessLevel; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.Setter; 10 | import org.hibernate.Hibernate; 11 | 12 | import javax.persistence.*; 13 | import javax.validation.constraints.*; 14 | import java.time.LocalDateTime; 15 | import java.util.*; 16 | 17 | @Entity @Getter 18 | @NoArgsConstructor(access = AccessLevel.PROTECTED) 19 | public class Game { 20 | 21 | @Id @GeneratedValue 22 | @Column(name = "game_id") 23 | private Long id; 24 | 25 | @NotBlank 26 | private String title; 27 | @NotBlank 28 | private String place; 29 | @Setter @NotBlank 30 | private String region; 31 | 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 33 | @Setter @NotNull @Future 34 | private LocalDateTime startDate; 35 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 36 | @Setter @NotNull @Future 37 | private LocalDateTime endDate; 38 | 39 | @PositiveOrZero 40 | private Integer masterFW; 41 | @PositiveOrZero 42 | private Integer masterMF; 43 | @PositiveOrZero 44 | private Integer masterDF; 45 | @PositiveOrZero 46 | private Integer masterGK; 47 | 48 | @Column(columnDefinition = "TEXT") 49 | private String description; 50 | 51 | @OneToMany(mappedBy = "game") 52 | private final List players = new ArrayList<>(); 53 | 54 | private Game(String title, String place, String region, 55 | LocalDateTime startDate, LocalDateTime endDate, String description, 56 | PositionDto positionDto) { 57 | this.title = title; 58 | this.place = place; 59 | this.region = region; 60 | this.startDate = startDate; 61 | this.endDate = endDate; 62 | this.description = description; 63 | 64 | this.masterFW = positionDto.masterFW(); 65 | this.masterMF = positionDto.masterMF(); 66 | this.masterDF = positionDto.masterDF(); 67 | this.masterGK = positionDto.masterGK(); 68 | } 69 | 70 | //정보 갱신 메소드 71 | public void update(LocalDateTime startDate, LocalDateTime endDate, String region) { 72 | this.setStartDate(startDate); 73 | this.setEndDate(endDate); 74 | this.setRegion(region); 75 | } 76 | 77 | //생성 메소드 78 | public static Game createGame(String title, String place, String region, 79 | LocalDateTime startDate, LocalDateTime endDate, 80 | String description, PositionDto positionDto) { 81 | return new Game(title, place, region, startDate, endDate, description, positionDto); 82 | } 83 | 84 | @Override 85 | public boolean equals(Object o) { 86 | if (this == o) return true; 87 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; 88 | Game game = (Game) o; 89 | return id != null && Objects.equals(id, game.id); 90 | } 91 | 92 | @Override 93 | public int hashCode() { 94 | return getClass().hashCode(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/community/soccer/controller/GameApiController.java: -------------------------------------------------------------------------------- 1 | package com.community.soccer.controller; 2 | 3 | import com.community.soccer.domain.game.Game; 4 | import com.community.soccer.domain.game.dao.GameCreateDao; 5 | import com.community.soccer.domain.game.dao.GameEditDao; 6 | import com.community.soccer.domain.game.dao.GameFindDao; 7 | import com.community.soccer.domain.game.dao.GameSearchDao; 8 | import com.community.soccer.domain.game.request.GameCreateRequest; 9 | import com.community.soccer.domain.game.request.GameEditRequest; 10 | import com.community.soccer.domain.item.Position; 11 | import com.community.soccer.domain.item.PositionDto; 12 | import com.community.soccer.domain.player.Player; 13 | import com.community.soccer.service.GameService; 14 | import lombok.RequiredArgsConstructor; 15 | import lombok.extern.slf4j.Slf4j; 16 | import org.springframework.web.bind.annotation.*; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.validation.Valid; 22 | import javax.validation.constraints.PositiveOrZero; 23 | import java.time.LocalDateTime; 24 | import java.time.format.DateTimeFormatter; 25 | import java.util.HashMap; 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | @Slf4j 30 | @RestController 31 | @RequestMapping("/games") 32 | @RequiredArgsConstructor 33 | public class GameApiController { 34 | 35 | private final GameService gameService; 36 | 37 | @PostMapping("") 38 | public GameCreateDao save(@RequestBody @Valid GameCreateRequest gameCreateRequest) { 39 | String title = gameCreateRequest.title(); 40 | String place = gameCreateRequest.place(); 41 | String region = gameCreateRequest.region(); 42 | LocalDateTime startDate = gameCreateRequest.startDate(); 43 | LocalDateTime endDate = gameCreateRequest.endDate(); 44 | String description = gameCreateRequest.description(); 45 | 46 | Map requirePlayer = gameCreateRequest.requirePlayer(); 47 | Integer masterFW = requirePlayer.get(Position.FW); 48 | Integer masterMF = requirePlayer.get(Position.MF); 49 | Integer masterDF = requirePlayer.get(Position.DF); 50 | Integer masterGK = requirePlayer.get(Position.GK); 51 | 52 | PositionDto positionDto = new PositionDto(masterFW, masterMF, masterDF, masterGK); 53 | Game game = Game.createGame(title, place, region, startDate, endDate, description, positionDto); 54 | Long id = gameService.save(game); 55 | 56 | return new GameCreateDao(id, title, place, region, startDate, endDate, requirePlayer, description); 57 | } 58 | 59 | @GetMapping("/{id}") 60 | public GameFindDao find(@PathVariable Long id) { 61 | Game game = gameService.findOne(id); 62 | 63 | String title = game.getTitle(); 64 | String place = game.getPlace(); 65 | String region = game.getRegion(); 66 | LocalDateTime startDate = game.getStartDate(); 67 | LocalDateTime endDate = game.getEndDate(); 68 | String description = game.getDescription(); 69 | List players = game.getPlayers(); 70 | 71 | //날짜 확인 72 | overDateRemove(id, endDate); 73 | 74 | return new GameFindDao(id, title, place, region, startDate, endDate, setRequirePlayer(game), description, players); 75 | } 76 | 77 | @PatchMapping("/{id}") 78 | public GameEditDao edit(@PathVariable Long id, 79 | @RequestBody @Valid GameEditRequest gameEditRequest) { 80 | Game game = gameService.findOne(id); 81 | LocalDateTime startDate = gameEditRequest.startDate(); 82 | LocalDateTime endDate = gameEditRequest.endDate(); 83 | String region = gameEditRequest.region(); 84 | 85 | gameService.update(id, startDate, endDate, region); 86 | 87 | String title = game.getTitle(); 88 | String place = game.getPlace(); 89 | String description = game.getDescription(); 90 | List players = game.getPlayers(); 91 | 92 | return new GameEditDao(id, title, place, region, startDate, endDate, setRequirePlayer(game), description, players); 93 | } 94 | 95 | @DeleteMapping("/{id}") 96 | public void delete(@PathVariable Long id) { 97 | gameService.remove(id); 98 | } 99 | 100 | @GetMapping("") 101 | public GameSearchDao search( 102 | @RequestParam(value = "page", defaultValue = "0") int page, 103 | @RequestParam(value = "region", defaultValue = "") String region, 104 | @RequestParam(value = "localDateTime", defaultValue = "") String localDateTime) { 105 | List search = getGameData(localDateTime, region, page); 106 | 107 | //날짜 확인 108 | for (Game game : search) overDateRemove(game.getId(), game.getEndDate()); 109 | return new GameSearchDao(search); 110 | } 111 | 112 | // 조건에 맞는 값 반환 113 | private List getGameData(String localDateTime, String region, int page) { 114 | if (!localDateTime.isBlank()) { 115 | LocalDateTime date = LocalDateTime.parse(localDateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); 116 | return !region.isBlank() ? 117 | gameService.findSearch(date, region, page) : 118 | gameService.findDate(date, page); 119 | } else return !region.isBlank() ? 120 | gameService.findRegion(region, page) : 121 | gameService.findAll(page); 122 | } 123 | 124 | private Map setRequirePlayer(Game game) { 125 | Map requirePlayer = new HashMap<>(); 126 | requirePlayer.put(Position.FW, game.getMasterFW()); 127 | requirePlayer.put(Position.MF, game.getMasterMF()); 128 | requirePlayer.put(Position.DF, game.getMasterDF()); 129 | requirePlayer.put(Position.GK, game.getMasterGK()); 130 | return requirePlayer; 131 | } 132 | 133 | //날짜가 지난 게임 삭제 134 | private void overDateRemove(Long id, LocalDateTime endDate) { 135 | if (endDate.isBefore(LocalDateTime.now())) { 136 | gameService.remove(id); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | --------------------------------------------------------------------------------