From ddff47b916380c701b44ba03e55a3d66f21e9f49 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sat, 4 Nov 2023 21:06:21 +0900 Subject: [PATCH 01/38] Update: docker.yml add docker build push nginx --- .github/workflows/docker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d460640..e31eca9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -32,8 +32,11 @@ jobs: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build -t ${{ secrets.DOCKER_REPO }}/mappin-server . docker push ${{ secrets.DOCKER_REPO }}/mappin-server - docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx . + + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f Dockerfile-nginx . docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx + - name: Install Docker on EC2 uses: appleboy/ssh-action@v0.1.6 From 4d8d95d4d76baf87a365150bd7d8d4a3cf385ef3 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sat, 4 Nov 2023 21:06:34 +0900 Subject: [PATCH 02/38] Update: docker.yml add docker build push nginx --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e31eca9..6cef02e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,7 @@ name: Issue 18 Workflow on: push: branches: - - main + - dev jobs: build: runs-on: ubuntu-latest From e5748b9909f23a68bc2ca1e16692e598e160d670 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sat, 4 Nov 2023 21:09:22 +0900 Subject: [PATCH 03/38] Update: docker.yml add docker build push nginx --- .github/workflows/docker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6cef02e..14d86a6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,8 +33,7 @@ jobs: docker build -t ${{ secrets.DOCKER_REPO }}/mappin-server . docker push ${{ secrets.DOCKER_REPO }}/mappin-server - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f Dockerfile-nginx . + docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f dockerfile-nginx . docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx From 6a5bf6468f55ee75c47cc0249e54fd2ca7e172f4 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sat, 4 Nov 2023 21:13:59 +0900 Subject: [PATCH 04/38] Update: docker.yml add docker build push nginx --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 14d86a6..6eb3632 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -69,10 +69,10 @@ jobs: script: | if [ "$(sudo docker ps -aq)" ]; then sudo docker stop $(sudo docker ps -aq) - sudo docker rm $(sudo docker ps -aq) + sudo docker rm -f $(sudo docker ps -aq) fi if [ "$(sudo docker images -aq)" ]; then - sudo docker rmi $(sudo docker images -aq) + sudo docker rmi -f $(sudo docker images -aq) fi - name: Copy file to EC2 From a2e7c3c098efb7f03a06f78bf7499b200ab9ee6b Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sun, 5 Nov 2023 14:35:15 +0900 Subject: [PATCH 05/38] Update: docker.yml add docker build push nginx --- .github/workflows/docker.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6eb3632..0dcf6b0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -31,11 +31,7 @@ jobs: run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build -t ${{ secrets.DOCKER_REPO }}/mappin-server . - docker push ${{ secrets.DOCKER_REPO }}/mappin-server - - docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f dockerfile-nginx . - docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx - + docker push ${{ secrets.DOCKER_REPO }}/mappin-server - name: Install Docker on EC2 uses: appleboy/ssh-action@v0.1.6 From 092fef573dc52b3388229784a1be12e42439a3f9 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sun, 5 Nov 2023 14:52:50 +0900 Subject: [PATCH 06/38] Update: Add nginx.conf upstream + dockerfile-nginx CMD --- .github/workflows/docker.yml | 5 ++++- dockerfile-nginx | 1 + nginx/conf.d/nginx.conf | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0dcf6b0..6226ff9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -31,7 +31,10 @@ jobs: run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build -t ${{ secrets.DOCKER_REPO }}/mappin-server . - docker push ${{ secrets.DOCKER_REPO }}/mappin-server + docker push ${{ secrets.DOCKER_REPO }}/mappin-server + + docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f dockerfile-nginx . + docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx - name: Install Docker on EC2 uses: appleboy/ssh-action@v0.1.6 diff --git a/dockerfile-nginx b/dockerfile-nginx index e6888c3..6ec8e80 100644 --- a/dockerfile-nginx +++ b/dockerfile-nginx @@ -1,2 +1,3 @@ FROM nginx COPY ./nginx/conf.d/nginx.conf /etc/nginx/conf.d +CMD ["nginx" ,"-g", "daemon off;"] diff --git a/nginx/conf.d/nginx.conf b/nginx/conf.d/nginx.conf index ab6d967..e186d00 100644 --- a/nginx/conf.d/nginx.conf +++ b/nginx/conf.d/nginx.conf @@ -1,7 +1,10 @@ +upstream server { + server web:8080; +} + server { listen 80; server_name hohoseung.shop; - access_log logs/host.access.log; location / { proxy_pass http://web:8080; From 693e12a2adf6db67542a791342baf4deab00c3b2 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Sun, 5 Nov 2023 15:06:09 +0900 Subject: [PATCH 07/38] [#31] Update: docker.yml dev -> main --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6226ff9..27023d6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,7 @@ name: Issue 18 Workflow on: push: branches: - - dev + - main jobs: build: runs-on: ubuntu-latest From 329240b8350162486f4c89bba8d07f2292f7c0ee Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:46:23 +0900 Subject: [PATCH 08/38] =?UTF-8?q?Update:=20dd-auto=20update=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4a59e95..cfb5ab3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,10 +19,9 @@ spring: url: ${DB_URL} username: ${DB_USERNAME} password: ${DB_PASS} - jpa : #jpa ?? hibernate: - ddl-auto : create + ddl-auto : update properties: hibernate : #show_sql : true #??? ??? ?? @@ -53,6 +52,10 @@ spring: user-info-uri: https://kapi.kakao.com/v2/user/me user-name-attribute: id + kakao: + api: + key: ${KAKAO_REST_API_KEY} + # mvc: # pathmatch: # matching-strategy: ant_path_matcher From 08e45aebea0356491c69487f56ac1cd8605a1438 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:47:18 +0900 Subject: [PATCH 09/38] =?UTF-8?q?Update:=20=EC=9D=BC=EB=B0=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=99=80=20=EA=B0=80=EA=B2=8C=20=EC=A3=BC?= =?UTF-8?q?=EC=9D=B8=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/mappin/controller/MemberController.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/server/mappin/controller/MemberController.java b/src/main/java/com/server/mappin/controller/MemberController.java index 923f8ef..a651a3a 100644 --- a/src/main/java/com/server/mappin/controller/MemberController.java +++ b/src/main/java/com/server/mappin/controller/MemberController.java @@ -1,6 +1,8 @@ package com.server.mappin.controller; +import com.server.mappin.dto.AdminLoginResponseDto; import com.server.mappin.dto.LoginResponseDto; +import com.server.mappin.dto.UserLoginResponseDto; import com.server.mappin.dto.MemberLoginDto; import com.server.mappin.service.MemberService; import io.swagger.v3.oas.annotations.Operation; @@ -25,14 +27,15 @@ public class MemberController { private final MemberService memberService; @Operation(summary = "로그인", description = "새로운 회원은 회원가입, 기존 회원은 로그인") - @ApiResponses({ - @ApiResponse(content = @Content(schema = @Schema(implementation = LoginResponseDto.class))) + @ApiResponses(value = { + @ApiResponse(responseCode ="200",description ="일반 사용자 로그인", content = @Content(schema = @Schema(implementation = UserLoginResponseDto.class))), + @ApiResponse(responseCode = "201",description = "가게 주인 로그인", content = @Content(schema = @Schema(implementation = AdminLoginResponseDto.class))) }) @PostMapping("/login") - public ResponseEntity create(@RequestBody MemberLoginDto memberCreateDto){ + public ResponseEntity login(@RequestBody MemberLoginDto memberCreateDto){ try{ - LoginResponseDto loginResponseDto = memberService.create(memberCreateDto); - return new ResponseEntity<>(loginResponseDto,HttpStatus.OK); + LoginResponseDto responseDto = memberService.login(memberCreateDto); + return new ResponseEntity<>(responseDto,HttpStatus.OK); }catch (IllegalStateException e){ return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT); } From e97a626ee5046b4786930ca76c82ec4dd3a57e75 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:47:38 +0900 Subject: [PATCH 10/38] =?UTF-8?q?Update:=20=EC=9D=BC=EB=B0=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=99=80=20=EA=B0=80=EA=B2=8C=20=EC=A3=BC?= =?UTF-8?q?=EC=9D=B8=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/mappin/service/MemberService.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/server/mappin/service/MemberService.java b/src/main/java/com/server/mappin/service/MemberService.java index ef64af8..d9bf98d 100644 --- a/src/main/java/com/server/mappin/service/MemberService.java +++ b/src/main/java/com/server/mappin/service/MemberService.java @@ -2,18 +2,24 @@ import com.server.mappin.auth.token.TokenProvider; import com.server.mappin.domain.Member; +import com.server.mappin.domain.Shop; import com.server.mappin.domain.enums.ProviderType; +import com.server.mappin.domain.enums.Role; +import com.server.mappin.dto.AdminLoginResponseDto; import com.server.mappin.dto.LoginResponseDto; +import com.server.mappin.dto.UserLoginResponseDto; import com.server.mappin.dto.MemberLoginDto; import com.server.mappin.repository.MemberRepository; -import io.swagger.v3.oas.annotations.Parameters; +import com.server.mappin.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.geo.Point; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.time.LocalDateTime; +import java.util.Map; import java.util.Optional; @Service @@ -22,16 +28,14 @@ public class MemberService { private final MemberRepository memberRepository; private final TokenProvider tokenProvider; + private final ShopRepository shopRepository; + private final MapService mapService; @Value("${spring.jwt.access-token-validity-in-seconds}") long accessTokenValidityInMilliseconds; - @Transactional - public Optional findByEmail(String email) { - return memberRepository.findByEmail(email); - } @Transactional - public LoginResponseDto create(MemberLoginDto memberCreateDto) { + public LoginResponseDto login(MemberLoginDto memberCreateDto) { Member save; - + String jwt; Optional existingMember = memberRepository.findByEmail(memberCreateDto.getEmail()); if (existingMember.isPresent()) { @@ -43,18 +47,35 @@ public LoginResponseDto create(MemberLoginDto memberCreateDto) { member.setName(memberCreateDto.getName()); member.setCreatedAt(LocalDate.now()); member.setProviderType(ProviderType.KAKAO); - save = memberRepository.save(member); } - - String jwt = tokenProvider.generateToken(save.getEmail(), save.getRole().toString()); - - return LoginResponseDto.builder() + jwt = tokenProvider.generateToken(save.getEmail(), save.getRole().toString()); + if(save.getRole() == Role.OWNER){ + Optional byMember = shopRepository.findByMember(save); + if(byMember.isPresent()){ + Shop shop = byMember.get(); + Point point = mapService.GetLocalInfo(shop.getAddress()); + return AdminLoginResponseDto.builder() + .statusCode(201) + .isSuccess("true") + .id(save.getId()) + .jwt(jwt) + .token_type("Bearer") + .expires_in(accessTokenValidityInMilliseconds) + .role(save.getRole().name()) + .geo(point) + .build(); + } + } + return UserLoginResponseDto.builder() + .statusCode(200) .isSuccess("true") .id(save.getId()) + .role(save.getRole().name()) .jwt(jwt) .token_type("Bearer") .expires_in(accessTokenValidityInMilliseconds) .build(); + } } From 8108beceacf38bde8ed6c3de5af5bc53c75aca7c Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:48:04 +0900 Subject: [PATCH 11/38] =?UTF-8?q?Update:=20Address=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/server/mappin/domain/Shop.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/server/mappin/domain/Shop.java b/src/main/java/com/server/mappin/domain/Shop.java index 536a0ba..543aee1 100644 --- a/src/main/java/com/server/mappin/domain/Shop.java +++ b/src/main/java/com/server/mappin/domain/Shop.java @@ -1,13 +1,16 @@ package com.server.mappin.domain; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import javax.persistence.*; @Entity @Table(name = "shop") @NoArgsConstructor +@Getter @Setter public class Shop { @Id From 5c27cd772d3af3cb9d57a0b07b1b5043b7899c08 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:48:32 +0900 Subject: [PATCH 12/38] =?UTF-8?q?Update:=20=EC=9D=BC=EB=B0=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20Response=20Dto=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/mappin/dto/LoginResponseDto.java | 14 ----- .../mappin/dto/UserLoginResponseDto.java | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/com/server/mappin/dto/LoginResponseDto.java create mode 100644 src/main/java/com/server/mappin/dto/UserLoginResponseDto.java diff --git a/src/main/java/com/server/mappin/dto/LoginResponseDto.java b/src/main/java/com/server/mappin/dto/LoginResponseDto.java deleted file mode 100644 index ecf78f6..0000000 --- a/src/main/java/com/server/mappin/dto/LoginResponseDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.server.mappin.dto; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class LoginResponseDto { - private String isSuccess; - private Long id; - private String jwt; - private String token_type; - private long expires_in; -} diff --git a/src/main/java/com/server/mappin/dto/UserLoginResponseDto.java b/src/main/java/com/server/mappin/dto/UserLoginResponseDto.java new file mode 100644 index 0000000..3c32213 --- /dev/null +++ b/src/main/java/com/server/mappin/dto/UserLoginResponseDto.java @@ -0,0 +1,51 @@ +package com.server.mappin.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.Getter; + +@Data +@Builder +public class UserLoginResponseDto implements LoginResponseDto { + private int statusCode; + private String isSuccess; + private Long id; + private String role; + private String jwt; + private String token_type; + private long expires_in; + + @Override + public int getStatusCode(){ + return statusCode; + } + @Override + public String getIsSuccess() { + return isSuccess; + } + @Override + public Long getId() { + return id; + } + @Override + public String getRole() { + return role; + } + + @Override + public String getJwt() { + return jwt; + } + + @Override + public String getToken_Type() { + return token_type; + } + + @Override + public long getExpires_In() { + return expires_in; + } + + +} From 8c653b2a1a9708ab8a45304ba08c77f4373d105c Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:49:08 +0900 Subject: [PATCH 13/38] =?UTF-8?q?Update:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EA=B2=8C=20=EA=B2=80=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/server/mappin/repository/ShopRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/server/mappin/repository/ShopRepository.java b/src/main/java/com/server/mappin/repository/ShopRepository.java index 3a964cb..98be2c0 100644 --- a/src/main/java/com/server/mappin/repository/ShopRepository.java +++ b/src/main/java/com/server/mappin/repository/ShopRepository.java @@ -1,10 +1,16 @@ package com.server.mappin.repository; import com.server.mappin.domain.Lost; +import com.server.mappin.domain.Member; import com.server.mappin.domain.Shop; +import org.springframework.data.domain.Example; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface ShopRepository extends JpaRepository { + Optional findByMember(Member member); } From a3ab76b89b131a1fab998e03d910d040531fd5b6 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:49:33 +0900 Subject: [PATCH 14/38] =?UTF-8?q?Add:=20=EA=B0=80=EA=B2=8C=20=EC=A3=BC?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20Response=20Dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappin/dto/AdminLoginResponseDto.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/com/server/mappin/dto/AdminLoginResponseDto.java diff --git a/src/main/java/com/server/mappin/dto/AdminLoginResponseDto.java b/src/main/java/com/server/mappin/dto/AdminLoginResponseDto.java new file mode 100644 index 0000000..cf71d7a --- /dev/null +++ b/src/main/java/com/server/mappin/dto/AdminLoginResponseDto.java @@ -0,0 +1,55 @@ +package com.server.mappin.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.springframework.data.geo.Point; + +@Data +@Builder +@Getter +public class AdminLoginResponseDto implements LoginResponseDto { + private int statusCode; + private String isSuccess; + private Long id; + private String role; + private String jwt; + private String token_type; + private long expires_in; + private Point geo; + + @Override + public int getStatusCode(){ + return statusCode; + } + @Override + public String getIsSuccess() { + return isSuccess; + } + + @Override + public Long getId() { + return id; + } + + @Override + public String getRole() { + return role; + } + + @Override + public String getJwt() { + return jwt; + } + + @Override + public String getToken_Type() { + return token_type; + } + + @Override + public long getExpires_In() { + return expires_in; + } + +} From 8b2c4a955a66055dcb2719b013edccf532be3f74 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:49:50 +0900 Subject: [PATCH 15/38] =?UTF-8?q?Add:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20Resp?= =?UTF-8?q?onse=20Dto=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/server/mappin/dto/LoginResponseDto.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/server/mappin/dto/LoginResponseDto.java diff --git a/src/main/java/com/server/mappin/dto/LoginResponseDto.java b/src/main/java/com/server/mappin/dto/LoginResponseDto.java new file mode 100644 index 0000000..ff06ea3 --- /dev/null +++ b/src/main/java/com/server/mappin/dto/LoginResponseDto.java @@ -0,0 +1,11 @@ +package com.server.mappin.dto; + +public interface LoginResponseDto { + int getStatusCode(); + String getIsSuccess(); + Long getId(); + String getRole(); + String getJwt(); + String getToken_Type(); + long getExpires_In(); +} From e20dad203ba26a6c0013c6329aa7290d2daa8c6a Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Sun, 5 Nov 2023 19:50:09 +0900 Subject: [PATCH 16/38] =?UTF-8?q?Add:=20=EA=B0=80=EA=B2=8C=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=EB=A5=BC=20x,y=20=EC=A2=8C=ED=91=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/server/mappin/service/MapService.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/server/mappin/service/MapService.java diff --git a/src/main/java/com/server/mappin/service/MapService.java b/src/main/java/com/server/mappin/service/MapService.java new file mode 100644 index 0000000..cb57967 --- /dev/null +++ b/src/main/java/com/server/mappin/service/MapService.java @@ -0,0 +1,59 @@ +package com.server.mappin.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.data.geo.Point; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class MapService { + + @Value("${spring.kakao.api.key}") + private String apiKey; + + public Point GetLocalInfo(String address){ + String apiUrl = "https://dapi.kakao.com/v2/local/search/address.json"; + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization","KakaoAK "+apiKey); + HttpEntity httpEntity = new HttpEntity<>(headers); + URI builder = UriComponentsBuilder + .fromUriString(apiUrl) + .queryParam("query",address) + .build() + .encode(StandardCharsets.UTF_8) + .toUri(); + ResponseEntity> response = new RestTemplate().exchange(builder, HttpMethod.GET, httpEntity, new ParameterizedTypeReference>() {}); + Map responseBody = response.getBody(); + List> documents = (List>)responseBody.get("documents"); + if(!documents.isEmpty()){ + Map firstDocument = documents.get(0); + Object xObject = firstDocument.get("x"); + Object yObject = firstDocument.get("y"); + if(xObject instanceof Double && yObject instanceof Double){ + Double xCoordinate = (Double) xObject; + Double yCoordinate = (Double) yObject; + Point point = new Point(xCoordinate,yCoordinate); + return new Point(xCoordinate,yCoordinate); + }else if(xObject instanceof String && yObject instanceof String){ + try{ + Double xCoordinate = Double.parseDouble((String) xObject); + Double yCoordinate = Double.parseDouble((String) yObject); + return new Point(xCoordinate,yCoordinate); + }catch (NumberFormatException e){ + log.error(e.getMessage()); + } + } + } + return null; + } +} From fb6f6409cfcb4f788f97ffadab9a04004b000273 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 10:35:35 +0900 Subject: [PATCH 17/38] =?UTF-8?q?Update:=20ResponseDto=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/server/mappin/dto/FindByCategoryResponseDto.java | 2 ++ .../java/com/server/mappin/dto/LostRegisterResponseDto.java | 1 + src/main/java/com/server/mappin/dto/PostCreateRequestDto.java | 4 ++-- .../java/com/server/mappin/dto/PostCreateResponseDto.java | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/server/mappin/dto/FindByCategoryResponseDto.java b/src/main/java/com/server/mappin/dto/FindByCategoryResponseDto.java index ee87155..31c1881 100644 --- a/src/main/java/com/server/mappin/dto/FindByCategoryResponseDto.java +++ b/src/main/java/com/server/mappin/dto/FindByCategoryResponseDto.java @@ -3,6 +3,8 @@ import lombok.Builder; import lombok.Data; +import java.util.List; + @Data @Builder public class FindByCategoryResponseDto { diff --git a/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java b/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java index 75a1474..5128bfe 100644 --- a/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java +++ b/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java @@ -6,6 +6,7 @@ @Data @Builder public class LostRegisterResponseDto { + private int statusCode; private String isSuccess; private Long lostId; } diff --git a/src/main/java/com/server/mappin/dto/PostCreateRequestDto.java b/src/main/java/com/server/mappin/dto/PostCreateRequestDto.java index aaba98e..075924e 100644 --- a/src/main/java/com/server/mappin/dto/PostCreateRequestDto.java +++ b/src/main/java/com/server/mappin/dto/PostCreateRequestDto.java @@ -13,7 +13,7 @@ public class PostCreateRequestDto { private LocalDate date; private String dong; private String category; - private int x; - private int y; + private Double x; + private Double y; } diff --git a/src/main/java/com/server/mappin/dto/PostCreateResponseDto.java b/src/main/java/com/server/mappin/dto/PostCreateResponseDto.java index b2a40b0..f18e4c0 100644 --- a/src/main/java/com/server/mappin/dto/PostCreateResponseDto.java +++ b/src/main/java/com/server/mappin/dto/PostCreateResponseDto.java @@ -6,6 +6,7 @@ @Data @Builder public class PostCreateResponseDto { + private int statusCode; private String isSuccess; private Long postId; From 8a2041167828cbf60d1e0d4e4b14525de641a0ae Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 10:36:00 +0900 Subject: [PATCH 18/38] =?UTF-8?q?Update:=20ResponseDto=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/mappin/controller/LostController.java | 13 ++++++------- .../server/mappin/controller/PostController.java | 3 ++- src/main/java/com/server/mappin/domain/Post.java | 6 +++--- .../com/server/mappin/service/LostService.java | 14 +++++++++++--- .../com/server/mappin/service/PostService.java | 3 +++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/server/mappin/controller/LostController.java b/src/main/java/com/server/mappin/controller/LostController.java index 644fbcf..34d8fed 100644 --- a/src/main/java/com/server/mappin/controller/LostController.java +++ b/src/main/java/com/server/mappin/controller/LostController.java @@ -1,8 +1,6 @@ package com.server.mappin.controller; -import com.server.mappin.dto.FindByCategoryResponseDto; -import com.server.mappin.dto.LostRegisterRequestDto; -import com.server.mappin.dto.LostRegisterResponseDto; +import com.server.mappin.dto.*; import com.server.mappin.service.LostService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -27,7 +25,8 @@ public class LostController { private final LostService lostService; @Operation(summary = "분실물 등록") - @ApiResponse(content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) + @ApiResponse(responseCode ="200",description ="분실물 등록 성공",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) + @ApiResponse(responseCode ="400",description ="분실물 등록 실패",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) @PutMapping("/lost/register") public ResponseEntity registerLost(@RequestBody LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication){ try{ @@ -39,12 +38,12 @@ public ResponseEntity registerLost(@RequestBody LostRegisterRequestDto lostRe } @Operation(summary = "카테고리 검색",description = "분실물을 카테고리 별로 검색") - @ApiResponse(content = @Content(schema = @Schema(implementation = FindByCategoryResponseDto.class))) + @ApiResponse(responseCode = "200",description ="카테고리 별로 검색 성공", content = @Content(schema = @Schema(implementation = FindByCategoryListResponseDto.class))) @GetMapping("/search/category/{category_name}") public ResponseEntity searchByCategory(@RequestParam(value = "category_name") String name){ try{ - List byCategory = lostService.findByCategory(name); - return new ResponseEntity<>(byCategory,HttpStatus.OK); + FindByCategoryListResponseDto findByCategoryListResponseDto = lostService.findByCategory(name); + return new ResponseEntity<>(findByCategoryListResponseDto,HttpStatus.OK); }catch (IllegalStateException e){ return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT); } diff --git a/src/main/java/com/server/mappin/controller/PostController.java b/src/main/java/com/server/mappin/controller/PostController.java index 0b633cb..7ee2297 100644 --- a/src/main/java/com/server/mappin/controller/PostController.java +++ b/src/main/java/com/server/mappin/controller/PostController.java @@ -28,7 +28,8 @@ public class PostController { @Operation(summary = "게시물 작성",description = "게시물을 작성합니다") @ApiResponses({ - @ApiResponse(content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class))) + @ApiResponse(responseCode ="200",description ="게시물 작성 성공",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class))), + @ApiResponse(responseCode ="400",description ="게시물 작성 실패",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class))) }) @PutMapping("/post") public ResponseEntity create(@RequestBody PostCreateRequestDto postCreateDto, Authentication authentication){ diff --git a/src/main/java/com/server/mappin/domain/Post.java b/src/main/java/com/server/mappin/domain/Post.java index fb05866..8e37535 100644 --- a/src/main/java/com/server/mappin/domain/Post.java +++ b/src/main/java/com/server/mappin/domain/Post.java @@ -37,9 +37,9 @@ public class Post { private String imageUrl; - private Integer x; + private Double x; - private Integer y; + private Double y; @ManyToOne @JoinColumn(name = "location_id") @@ -50,7 +50,7 @@ public class Post { private Category category; @Builder - public Post(Member member, String title, String content, LocalDate createdAt, LocalDate lostDate, String imageUrl, Integer x, Integer y, Location location, Category category) { + public Post(Member member, String title, String content, LocalDate createdAt, LocalDate lostDate, String imageUrl, Double x, Double y, Location location, Category category) { this.member = member; this.title = title; this.content = content; diff --git a/src/main/java/com/server/mappin/service/LostService.java b/src/main/java/com/server/mappin/service/LostService.java index 1d2635d..4d44c70 100644 --- a/src/main/java/com/server/mappin/service/LostService.java +++ b/src/main/java/com/server/mappin/service/LostService.java @@ -4,6 +4,7 @@ import com.server.mappin.domain.Location; import com.server.mappin.domain.Lost; import com.server.mappin.domain.Member; +import com.server.mappin.dto.FindByCategoryListResponseDto; import com.server.mappin.dto.FindByCategoryResponseDto; import com.server.mappin.dto.LostRegisterRequestDto; import com.server.mappin.dto.LostRegisterResponseDto; @@ -30,15 +31,19 @@ public class LostService { private final MemberRepository memberRepository; private final CategoryRepository categoryRepository; private final LocationRepository locationRepository; - public List findByCategory(String categoryName){ + public FindByCategoryListResponseDto findByCategory(String categoryName){ List losts = lostRepository.findByCategory(categoryName); - List result = losts.stream() + List list = losts.stream() .map(lost -> FindByCategoryResponseDto.builder() .id(lost.getId()) .title(lost.getTitle()) .build()) .collect(Collectors.toList()); - return result; + return FindByCategoryListResponseDto.builder() + .statusCode(200) + .isSuccess("true") + .losts(list) + .build(); } @Transactional @@ -63,12 +68,15 @@ public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterR .build(); Lost save = lostRepository.save(lost); return LostRegisterResponseDto.builder() + .statusCode(200) .isSuccess("true") .lostId(save.getId()) .build(); } return LostRegisterResponseDto.builder() + .statusCode(400) .isSuccess("false") + .lostId(null) .build(); } diff --git a/src/main/java/com/server/mappin/service/PostService.java b/src/main/java/com/server/mappin/service/PostService.java index 74b7528..83e3d9a 100644 --- a/src/main/java/com/server/mappin/service/PostService.java +++ b/src/main/java/com/server/mappin/service/PostService.java @@ -56,13 +56,16 @@ public PostCreateResponseDto create(PostCreateRequestDto postCreateRequestDto, S Post save = postRepository.save(post); log.info(save.getTitle()); return PostCreateResponseDto.builder() + .statusCode(200) .isSuccess("true") .postId(save.getId()) .build(); } return PostCreateResponseDto.builder() + .statusCode(400) .isSuccess("false") + .postId(null) .build(); } } From 9f3ef27c9dec5448ecfe3a6aa1fcb3805123b67b Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 10:36:18 +0900 Subject: [PATCH 19/38] =?UTF-8?q?Add:=20ResponseDto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappin/dto/FindByCategoryListResponseDto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/server/mappin/dto/FindByCategoryListResponseDto.java diff --git a/src/main/java/com/server/mappin/dto/FindByCategoryListResponseDto.java b/src/main/java/com/server/mappin/dto/FindByCategoryListResponseDto.java new file mode 100644 index 0000000..5c39582 --- /dev/null +++ b/src/main/java/com/server/mappin/dto/FindByCategoryListResponseDto.java @@ -0,0 +1,14 @@ +package com.server.mappin.dto; + +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +@Builder +@Data +public class FindByCategoryListResponseDto { + private int statusCode; + private String isSuccess; + private List losts; +} From 3b729574849cca21bd01abbe93fcd81d3542c6de Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 13:05:59 +0900 Subject: [PATCH 20/38] [#31] Update: application.yml for s3 --- src/main/resources/application.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4a59e95..e6fe833 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,6 +21,10 @@ spring: password: ${DB_PASS} jpa : #jpa ?? + http: + encoding: + charset: UTF-8 + hibernate: ddl-auto : create properties: @@ -57,6 +61,18 @@ spring: # pathmatch: # matching-strategy: ant_path_matcher +cloud: + aws: + credentials: + accessKey: ${S3Accesskey} # IAM 사용자 엑세스 키 + secretKey: ${S3SecretKey} # IAM 사용자 비밀 엑세스 키 + s3: + bucket: mappin-s3 # 버킷명 + region: + static: ap-northeast-2 # 리전 + stack: + auto: false # Spring Cloud는 환경 또는 스택을 기반으로 이를 자동으로 감지 + logging.level: org.hibernate.SQL: debug #??? ???? ??? ??? ??. org.hibernate.type : trace #???? ?????? ? ? ? From e50738c4996c0d0209c06ac5ca132116ee24a453 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 13:06:21 +0900 Subject: [PATCH 21/38] [#32] Update: build.gradle for s3 --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 783ef92..a50544a 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' implementation 'org.springdoc:springdoc-openapi-ui:1.7.0' + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.1.RELEASE' compileOnly 'org.projectlombok:lombok' From 11fed7dc0a7a2ef52c731f0cece9a8fc9ab4d63e Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 13:06:35 +0900 Subject: [PATCH 22/38] [#32] Add: S3config --- .../com/server/mappin/config/S3Config.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/server/mappin/config/S3Config.java diff --git a/src/main/java/com/server/mappin/config/S3Config.java b/src/main/java/com/server/mappin/config/S3Config.java new file mode 100644 index 0000000..0c4778f --- /dev/null +++ b/src/main/java/com/server/mappin/config/S3Config.java @@ -0,0 +1,32 @@ +package com.server.mappin.config; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class S3Config { + + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + + @Value("${cloud.aws.region.static}") + private String region; + + @Bean + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); + return (AmazonS3Client) AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) + .build(); + } + +} From d4b8029572ab48b1014402217d9030cc5283401f Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 13:06:43 +0900 Subject: [PATCH 23/38] [#32] Add: S3Service --- .../com/server/mappin/service/S3Service.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/java/com/server/mappin/service/S3Service.java diff --git a/src/main/java/com/server/mappin/service/S3Service.java b/src/main/java/com/server/mappin/service/S3Service.java new file mode 100644 index 0000000..fd3ff01 --- /dev/null +++ b/src/main/java/com/server/mappin/service/S3Service.java @@ -0,0 +1,62 @@ +package com.server.mappin.service; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; + +@Component +@RequiredArgsConstructor +public class S3Service { + + private final AmazonS3Client amazonS3Client; + + @Value("${cloud.aws.s3.bucket}") + public String bucket; // S3 버킷 + + // S3 파일 업로드 + public String upload(MultipartFile multipartFile, String dirName) throws IOException { + // MultipartFile -> File + File convertFile = convert(multipartFile) + .orElseThrow(() -> new IllegalArgumentException("file convert error")); // 파일을 변환할 수 없으면 에러 + + // S3에 저장할 파일명 + String fileName = dirName + "/" + UUID.randomUUID() + "_" + convertFile.getName(); + + // S3에 파일 업로드 + amazonS3Client.putObject(new PutObjectRequest(bucket, fileName, convertFile).withCannedAcl(CannedAccessControlList.PublicRead)); + String uploadImageUrl = amazonS3Client.getUrl(bucket, fileName).toString(); + + // 로컬 파일 삭제 + convertFile.delete(); + + return uploadImageUrl; + } + + // S3 파일 삭제 + public void delete(String path) { + amazonS3Client.deleteObject(bucket, path); + } + + // 파일 convert 후 로컬에 업로드 + private Optional convert(MultipartFile file) throws IOException { + File convertFile = new File(System.getProperty("user.dir") + "/" + file.getOriginalFilename()); + if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) + try (FileOutputStream fos = new FileOutputStream(convertFile)) { // FileOutputStream 데이터를 파일에 바이트 스트림으로 저장하기 위함 + fos.write(file.getBytes()); + } + return Optional.of(convertFile); + } + return Optional.empty(); + } + +} From 2c34abae036c9189322316c30c27eb6cd33ff7a9 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 13:06:52 +0900 Subject: [PATCH 24/38] [#32] Add: S3Controller --- .../mappin/controller/S3Controller.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/server/mappin/controller/S3Controller.java diff --git a/src/main/java/com/server/mappin/controller/S3Controller.java b/src/main/java/com/server/mappin/controller/S3Controller.java new file mode 100644 index 0000000..ecd32a3 --- /dev/null +++ b/src/main/java/com/server/mappin/controller/S3Controller.java @@ -0,0 +1,29 @@ +package com.server.mappin.controller; + +import com.server.mappin.service.S3Service; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@RequiredArgsConstructor +@RequestMapping(value = "aws-s3") +@RestController +public class S3Controller { + + private final S3Service s3UploadUtil; + + @PostMapping(name = "S3 파일 업로드", value = "/file") + public String fileUpload(@RequestParam("files") MultipartFile multipartFile) throws IOException { + s3UploadUtil.upload(multipartFile, "test"); // test 폴더에 파일 생성 + return "success"; + } + + @DeleteMapping(name = "S3 파일 삭제", value = "/file") + public String fileDelete(@RequestParam("path") String path) { + s3UploadUtil.delete(path); + return "success"; + } + +} From 3697562bcd12830db6d8dd272e8aa9b16c193d5a Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 16:30:09 +0900 Subject: [PATCH 25/38] [#38] Add: FindByDongResponseDto --- .../com/server/mappin/dto/FindByDongResponseDto.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/server/mappin/dto/FindByDongResponseDto.java diff --git a/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java b/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java new file mode 100644 index 0000000..a0a07d2 --- /dev/null +++ b/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java @@ -0,0 +1,12 @@ +package com.server.mappin.dto; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class FindByDongResponseDto { + private Long id; + private String title; + private String dong; +} From 890020e73ebdd4fb4457cd69e2623a1f79c4a11c Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 16:30:28 +0900 Subject: [PATCH 26/38] [#38] Update: Location getter add --- src/main/java/com/server/mappin/domain/Location.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/server/mappin/domain/Location.java b/src/main/java/com/server/mappin/domain/Location.java index 0b3454a..ba4105e 100644 --- a/src/main/java/com/server/mappin/domain/Location.java +++ b/src/main/java/com/server/mappin/domain/Location.java @@ -10,6 +10,7 @@ @Entity @Table(name = "location") @NoArgsConstructor +@Getter public class Location { @Id From 39abe891b6fdfa9f025de219bd43f1fb5932bbba Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 16:30:46 +0900 Subject: [PATCH 27/38] [#38] Add: Lost Controller --- .../mappin/controller/LostController.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/server/mappin/controller/LostController.java b/src/main/java/com/server/mappin/controller/LostController.java index 34d8fed..d30cfc5 100644 --- a/src/main/java/com/server/mappin/controller/LostController.java +++ b/src/main/java/com/server/mappin/controller/LostController.java @@ -1,6 +1,9 @@ package com.server.mappin.controller; -import com.server.mappin.dto.*; +import com.server.mappin.dto.FindByCategoryResponseDto; +import com.server.mappin.dto.FindByDongResponseDto; +import com.server.mappin.dto.LostRegisterRequestDto; +import com.server.mappin.dto.LostRegisterResponseDto; import com.server.mappin.service.LostService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -25,8 +28,7 @@ public class LostController { private final LostService lostService; @Operation(summary = "분실물 등록") - @ApiResponse(responseCode ="200",description ="분실물 등록 성공",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) - @ApiResponse(responseCode ="400",description ="분실물 등록 실패",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) + @ApiResponse(content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) @PutMapping("/lost/register") public ResponseEntity registerLost(@RequestBody LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication){ try{ @@ -38,12 +40,24 @@ public ResponseEntity registerLost(@RequestBody LostRegisterRequestDto lostRe } @Operation(summary = "카테고리 검색",description = "분실물을 카테고리 별로 검색") - @ApiResponse(responseCode = "200",description ="카테고리 별로 검색 성공", content = @Content(schema = @Schema(implementation = FindByCategoryListResponseDto.class))) + @ApiResponse(content = @Content(schema = @Schema(implementation = FindByCategoryResponseDto.class))) @GetMapping("/search/category/{category_name}") public ResponseEntity searchByCategory(@RequestParam(value = "category_name") String name){ try{ - FindByCategoryListResponseDto findByCategoryListResponseDto = lostService.findByCategory(name); - return new ResponseEntity<>(findByCategoryListResponseDto,HttpStatus.OK); + List byCategory = lostService.findByCategory(name); + return new ResponseEntity<>(byCategory,HttpStatus.OK); + }catch (IllegalStateException e){ + return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT); + } + } + + @Operation(summary = "동 검색",description = "분실물을 동 별로 검색") + @ApiResponse(content = @Content(schema = @Schema(implementation = FindByDongResponseDto.class))) + @GetMapping("/search/dong/{dong_name}") + public ResponseEntity searchByDong(@RequestParam(value = "dong_name") String dongName){ + try{ + List byDong = lostService.findByDong(dongName); + return new ResponseEntity<>(byDong,HttpStatus.OK); }catch (IllegalStateException e){ return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT); } From 24b2d3e5014eb27049274e6d9e9a083dd50becfc Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 16:30:55 +0900 Subject: [PATCH 28/38] [#38] Add: Lost Repository --- .../java/com/server/mappin/repository/LostRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/server/mappin/repository/LostRepository.java b/src/main/java/com/server/mappin/repository/LostRepository.java index aa43c12..af9f8f2 100644 --- a/src/main/java/com/server/mappin/repository/LostRepository.java +++ b/src/main/java/com/server/mappin/repository/LostRepository.java @@ -15,7 +15,10 @@ public interface LostRepository extends JpaRepository { @Query(value = "select l from Lost l left join fetch l.category c where c.name = :category") List findByCategory(@Param("category") String category); - + @Query(value = "select l from Lost l left join fetch l.location c where c.dong = :dong") + List findLocationByDong(@Param("dong") String dong); @Override S save(S entity); } + + From 678cdac6102765518348155aaec1978ec9cc3c55 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 16:31:10 +0900 Subject: [PATCH 29/38] [#38] Add: Lost Service --- .../server/mappin/service/LostService.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/server/mappin/service/LostService.java b/src/main/java/com/server/mappin/service/LostService.java index 4d44c70..5a34945 100644 --- a/src/main/java/com/server/mappin/service/LostService.java +++ b/src/main/java/com/server/mappin/service/LostService.java @@ -4,8 +4,8 @@ import com.server.mappin.domain.Location; import com.server.mappin.domain.Lost; import com.server.mappin.domain.Member; -import com.server.mappin.dto.FindByCategoryListResponseDto; import com.server.mappin.dto.FindByCategoryResponseDto; +import com.server.mappin.dto.FindByDongResponseDto; import com.server.mappin.dto.LostRegisterRequestDto; import com.server.mappin.dto.LostRegisterResponseDto; import com.server.mappin.repository.CategoryRepository; @@ -31,19 +31,27 @@ public class LostService { private final MemberRepository memberRepository; private final CategoryRepository categoryRepository; private final LocationRepository locationRepository; - public FindByCategoryListResponseDto findByCategory(String categoryName){ + public List findByCategory(String categoryName){ List losts = lostRepository.findByCategory(categoryName); - List list = losts.stream() + List result = losts.stream() .map(lost -> FindByCategoryResponseDto.builder() .id(lost.getId()) .title(lost.getTitle()) .build()) .collect(Collectors.toList()); - return FindByCategoryListResponseDto.builder() - .statusCode(200) - .isSuccess("true") - .losts(list) - .build(); + return result; + } + + public List findByDong(String dongName){ + List dongs = lostRepository.findLocationByDong(dongName); + List result = dongs.stream() + .map(dong -> FindByDongResponseDto.builder() + .id(dong.getId()) + .title(dong.getTitle()) + .dong(dong.getLocation().getDong()) + .build()) + .collect(Collectors.toList()); + return result; } @Transactional @@ -68,16 +76,25 @@ public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterR .build(); Lost save = lostRepository.save(lost); return LostRegisterResponseDto.builder() - .statusCode(200) .isSuccess("true") .lostId(save.getId()) .build(); } return LostRegisterResponseDto.builder() - .statusCode(400) .isSuccess("false") - .lostId(null) .build(); } } + + + + + + + + + + + + From ff0df393e82d0c04573641fa0292bc64a5fcf721 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:23:27 +0900 Subject: [PATCH 30/38] =?UTF-8?q?Add:=20x,y=20=EC=A2=8C=ED=91=9C=EB=A1=9C?= =?UTF-8?q?=20=EB=8F=99=20=EA=B2=80=EC=83=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/server/mappin/service/MapService.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/com/server/mappin/service/MapService.java b/src/main/java/com/server/mappin/service/MapService.java index cb57967..43257ef 100644 --- a/src/main/java/com/server/mappin/service/MapService.java +++ b/src/main/java/com/server/mappin/service/MapService.java @@ -56,4 +56,28 @@ public Point GetLocalInfo(String address){ } return null; } + + public String getDong(Double xCoordinate, Double yCoordinate){ + String apiUrl = "https://dapi.kakao.com/v2/local/geo/coord2regioncode.json"; + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization","KakaoAK "+apiKey); + HttpEntity httpEntity = new HttpEntity<>(headers); + System.out.println("xCoordinate = " + xCoordinate); + URI builder = UriComponentsBuilder + .fromUriString(apiUrl) + .queryParam("x",xCoordinate) + .queryParam("y",yCoordinate) + .build() + .encode(StandardCharsets.UTF_8) + .toUri(); + ResponseEntity> response = new RestTemplate().exchange(builder, HttpMethod.GET, httpEntity, new ParameterizedTypeReference>() {}); + Map responseBody = response.getBody(); + List> documents = (List>)responseBody.get("documents"); + if(!documents.isEmpty()){ + Map firstDocument = documents.get(0); + Object dong = firstDocument.get("region_3depth_name"); + return (String)dong; + } + return null; + } } From 6765fcabc15a6dcc5ca07d8a9a45a9921b05d838 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:23:40 +0900 Subject: [PATCH 31/38] =?UTF-8?q?Update:=20@Getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/server/mappin/domain/Location.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/server/mappin/domain/Location.java b/src/main/java/com/server/mappin/domain/Location.java index 0b3454a..ba4105e 100644 --- a/src/main/java/com/server/mappin/domain/Location.java +++ b/src/main/java/com/server/mappin/domain/Location.java @@ -10,6 +10,7 @@ @Entity @Table(name = "location") @NoArgsConstructor +@Getter public class Location { @Id From 5b7d7f7aebbb8f6e27d0a92cf2228d63b9e0a3d8 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:23:58 +0900 Subject: [PATCH 32/38] =?UTF-8?q?Update:=20RequestDto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/server/mappin/dto/LostRegisterRequestDto.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/server/mappin/dto/LostRegisterRequestDto.java b/src/main/java/com/server/mappin/dto/LostRegisterRequestDto.java index 5002717..b19f2ec 100644 --- a/src/main/java/com/server/mappin/dto/LostRegisterRequestDto.java +++ b/src/main/java/com/server/mappin/dto/LostRegisterRequestDto.java @@ -1,10 +1,12 @@ package com.server.mappin.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import com.server.mappin.domain.Category; import com.server.mappin.domain.Location; import lombok.Builder; import lombok.Data; import org.springframework.data.geo.Point; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; @@ -12,7 +14,8 @@ public class LostRegisterRequestDto { private String title; private String content; - private LocalDate foundDate; + private String foundDate; + private MultipartFile image; private Double x; private Double y; private String dong; From 3aacb841d69d1be160ecddd3f478522a619b65d6 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:24:08 +0900 Subject: [PATCH 33/38] =?UTF-8?q?Update:=20Response=20Dto=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappin/dto/LostRegisterResponseDto.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java b/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java index 5128bfe..6d8dab7 100644 --- a/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java +++ b/src/main/java/com/server/mappin/dto/LostRegisterResponseDto.java @@ -1,12 +1,27 @@ package com.server.mappin.dto; +import com.server.mappin.domain.Lost; import lombok.Builder; import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +import java.time.LocalDate; +import java.time.LocalDateTime; @Data @Builder public class LostRegisterResponseDto { private int statusCode; private String isSuccess; + private Long memberId; private Long lostId; + private String title; + private String content; + private LocalDate foundDate; + private LocalDateTime createdAt; + private String image; + private Double x; + private Double y; + private String dong; + private String category; } From bda0f7ec542b46f6d2e3177857f2533da69531d3 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:24:30 +0900 Subject: [PATCH 34/38] =?UTF-8?q?Update:=20=EB=B6=84=EC=8B=A4=EB=AC=BC=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/server/mappin/controller/LostController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/server/mappin/controller/LostController.java b/src/main/java/com/server/mappin/controller/LostController.java index 34d8fed..14b9104 100644 --- a/src/main/java/com/server/mappin/controller/LostController.java +++ b/src/main/java/com/server/mappin/controller/LostController.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*; import javax.persistence.Column; +import java.io.IOException; import java.util.List; @Tag(name = "Lost API", description = "분실물 관련 API 명세서") @RestController @@ -28,7 +29,7 @@ public class LostController { @ApiResponse(responseCode ="200",description ="분실물 등록 성공",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) @ApiResponse(responseCode ="400",description ="분실물 등록 실패",content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class))) @PutMapping("/lost/register") - public ResponseEntity registerLost(@RequestBody LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication){ + public ResponseEntity registerLost(@ModelAttribute LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication) throws IOException { try{ LostRegisterResponseDto lostRegisterResponseDto = lostService.registerLost(lostRegisterRequestDto, authentication.getName()); return new ResponseEntity<>(lostRegisterResponseDto,HttpStatus.OK); From e5162df0305f1fdf27c2f7c2af062af186372737 Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 19:24:38 +0900 Subject: [PATCH 35/38] =?UTF-8?q?Update:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/mappin/service/LostService.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/server/mappin/service/LostService.java b/src/main/java/com/server/mappin/service/LostService.java index 4d44c70..4a70b32 100644 --- a/src/main/java/com/server/mappin/service/LostService.java +++ b/src/main/java/com/server/mappin/service/LostService.java @@ -17,8 +17,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -31,6 +33,8 @@ public class LostService { private final MemberRepository memberRepository; private final CategoryRepository categoryRepository; private final LocationRepository locationRepository; + private final MapService mapService; + private final S3Service s3Service; public FindByCategoryListResponseDto findByCategory(String categoryName){ List losts = lostRepository.findByCategory(categoryName); List list = losts.stream() @@ -47,10 +51,18 @@ public FindByCategoryListResponseDto findByCategory(String categoryName){ } @Transactional - public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterRequestDto, String email){ + public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterRequestDto, String email) throws IOException { + //String으로 받아온 yyyy-MM-dd를 LocalDate 형식으로 변환 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate localDate = LocalDate.parse(lostRegisterRequestDto.getFoundDate(),formatter); + //회원, 카테고리 찾기 Optional memberRepositoryByEmail = memberRepository.findByEmail(email); Optional categoryByName = categoryRepository.findCategoryByName(lostRegisterRequestDto.getCategory()); - Optional locationByDong = locationRepository.findLocationByDong(lostRegisterRequestDto.getDong()); + //x,y좌표로 동네 찾고 동네가 DB에 존재하는지 확인 + String dong = mapService.getDong(lostRegisterRequestDto.getX(), lostRegisterRequestDto.getY()); + Optional locationByDong = locationRepository.findLocationByDong(dong); + //이미지 S3에 업로드 + String imageUrl = s3Service.upload(lostRegisterRequestDto.getImage(), "images"); if(memberRepositoryByEmail.isPresent() && categoryByName.isPresent() && locationByDong.isPresent()){ Member member = memberRepositoryByEmail.get(); Location location = locationByDong.get(); @@ -60,7 +72,8 @@ public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterR .content(lostRegisterRequestDto.getContent()) .x(lostRegisterRequestDto.getX()) .y(lostRegisterRequestDto.getY()) - .foundDate(lostRegisterRequestDto.getFoundDate()) + .foundDate(localDate) + .imageUrl(imageUrl) .createdAt(LocalDateTime.now()) .category(category) .location(location) @@ -70,13 +83,23 @@ public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterR return LostRegisterResponseDto.builder() .statusCode(200) .isSuccess("true") - .lostId(save.getId()) + .title(lost.getTitle()) + .content(lost.getContent()) + .x(lost.getX()) + .y(lost.getY()) + .foundDate(lost.getFoundDate()) + .createdAt(lost.getCreatedAt()) + .image(lost.getImageUrl()) + .category(lost.getCategory().getName()) + .memberId(lost.getMember().getId()) + .dong(location.getDong()) + .lostId(lost.getId()) .build(); + } return LostRegisterResponseDto.builder() .statusCode(400) .isSuccess("false") - .lostId(null) .build(); } From 7a0a463e6918f2151e4a574bda36d99ed0e46ae9 Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 21:51:17 +0900 Subject: [PATCH 36/38] [#38] Updaate: FindByDongResponseDto add createdAt and imageUrl --- src/main/java/com/server/mappin/dto/FindByDongResponseDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java b/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java index a0a07d2..2dc4349 100644 --- a/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java +++ b/src/main/java/com/server/mappin/dto/FindByDongResponseDto.java @@ -2,11 +2,14 @@ import lombok.Builder; import lombok.Data; +import java.time.LocalDateTime; @Data @Builder public class FindByDongResponseDto { private Long id; private String title; + private LocalDateTime createdAt; + private String imageUrl; private String dong; } From ad681324fdfa5ea236a6c29ae4dfe1e9e6af693a Mon Sep 17 00:00:00 2001 From: SunwuPark Date: Mon, 6 Nov 2023 21:51:31 +0900 Subject: [PATCH 37/38] [#38] Update: LostService add createdAt and imageUrl --- src/main/java/com/server/mappin/service/LostService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/server/mappin/service/LostService.java b/src/main/java/com/server/mappin/service/LostService.java index 5a34945..338a6dc 100644 --- a/src/main/java/com/server/mappin/service/LostService.java +++ b/src/main/java/com/server/mappin/service/LostService.java @@ -49,6 +49,8 @@ public List findByDong(String dongName){ .id(dong.getId()) .title(dong.getTitle()) .dong(dong.getLocation().getDong()) + .imageUrl(dong.getImageUrl()) + .createdAt(dong.getCreatedAt()) .build()) .collect(Collectors.toList()); return result; From d554a266655e0e7cea2f0f48f3aa30160fe3148e Mon Sep 17 00:00:00 2001 From: seungheon123 Date: Mon, 6 Nov 2023 22:23:06 +0900 Subject: [PATCH 38/38] =?UTF-8?q?Update:=20=ED=99=98=EA=B2=BD=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 27023d6..a4ef525 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -97,6 +97,9 @@ jobs: echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> ~/.env echo "KAKAO_CLIENT=${{ secrets.KAKAO_CLIENT }}" >> ~/.env echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> ~/.env + echo "KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }}" >> ~/.env + echo "S3accessKey=${{ secrets.S3ACCESSKEY }}" >> ~/.env + echo "S3SecretKey=${{ secrets.S3SECRETKEY }}" >> ~/.env # Copy .env file to the project directory #cp ~/.env /home/ubuntu/.env