Skip to content

Commit

Permalink
Merge pull request #44 from Map-Pin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
seungheon123 authored Nov 6, 2023
2 parents 8889d84 + d554a26 commit 8cafe8d
Show file tree
Hide file tree
Showing 30 changed files with 542 additions and 61 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +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 build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx .
docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx
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/[email protected]
Expand Down Expand Up @@ -67,10 +68,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
Expand All @@ -96,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
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FROM nginx
COPY ./nginx/conf.d/nginx.conf /etc/nginx/conf.d
CMD ["nginx" ,"-g", "daemon off;"]
5 changes: 4 additions & 1 deletion nginx/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/server/mappin/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
25 changes: 18 additions & 7 deletions src/main/java/com/server/mappin/controller/LostController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,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
Expand All @@ -29,7 +28,7 @@ public class LostController {
@Operation(summary = "분실물 등록")
@ApiResponse(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);
Expand All @@ -39,12 +38,24 @@ public ResponseEntity<?> registerLost(@RequestBody LostRegisterRequestDto lostRe
}

@Operation(summary = "카테고리 검색",description = "분실물을 카테고리 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByCategoryResponseDto.class)))
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByCategoryListResponseDto.class)))
@GetMapping("/search/category/{category_name}")
public ResponseEntity<?> searchByCategory(@RequestParam(value = "category_name") String name){
try{
List<FindByCategoryResponseDto> 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);
}
}

@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<FindByDongResponseDto> byDong = lostService.findByDong(dongName);
return new ResponseEntity<>(byDong,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/server/mappin/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/server/mappin/controller/S3Controller.java
Original file line number Diff line number Diff line change
@@ -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";
}

}
1 change: 1 addition & 0 deletions src/main/java/com/server/mappin/domain/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Entity
@Table(name = "location")
@NoArgsConstructor
@Getter
public class Location {

@Id
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/server/mappin/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/server/mappin/domain/Shop.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/server/mappin/dto/AdminLoginResponseDto.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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<FindByCategoryResponseDto> losts;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class FindByCategoryResponseDto {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/server/mappin/dto/FindByDongResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.server.mappin.dto;

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;
}
19 changes: 8 additions & 11 deletions src/main/java/com/server/mappin/dto/LoginResponseDto.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
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;
public interface LoginResponseDto {
int getStatusCode();
String getIsSuccess();
Long getId();
String getRole();
String getJwt();
String getToken_Type();
long getExpires_In();
}
Loading

0 comments on commit 8cafe8d

Please sign in to comment.