Skip to content

Commit

Permalink
🚀 [Deploy] - API 반영 (#28)
Browse files Browse the repository at this point in the history
* Feat: customException 구현

* Feat: responseDto 구현

* Feat: 내 근처 킥보드 주차장 찾기 API 구현

* Fix: BoardingRecord 도메인 수정

* Feat: Spring Security, JWT Cookie, 소셜 로그인 기능 구현

* Feat: Spring Security, JWT Cookie, 소셜 로그인 기능 구현

* Fix: 코드 에러 수정

* Refactor: 아직 사용하지 않는 코드 삭제

* Feat: oauth2 의존성 추가

* Chore: Credentials 추가

* ✨ [Feature] - 서버 날짜 설정 및 유저 닉네임 설정 (#15)

* Feat: 스프링 서버 시간 한국으로 설정

* Feat: 사용자 닉네임 지정 로직 추가

* Fix: 초기 포인트 설정

* Fix: nickname 에러 수정 (#18)

* Fix: BoardingRecord 도메인 수정

* Feat: 디펜던시 추가

* Feat: ErrorCode 추가

* Feat: Image API 구현

* Feat: WebClientConfig 구현

* Feat: S3ClientConfig 구현

* Feat: BoardingRecord API 구현

* Feat: 주차장 예측 결과 관련 기능 추가

* Feat: 탑승 기록 저장 API 구현

* Fix: 디렉토리 경로 수정

* Feat: 코드 리팩터링 진행

---------

Co-authored-by: Jang99u <[email protected]>
Co-authored-by: 민장규 <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent 829de04 commit d626bdc
Show file tree
Hide file tree
Showing 41 changed files with 633 additions and 55 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {
}

dependencies {
//database
// database
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand All @@ -46,8 +46,14 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

//json
// json
implementation 'net.minidev:json-smart:2.4.7'

// s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// WebClient
implementation 'org.springframework.boot:spring-boot-starter-webflux'
}

task copyGitSubmodule(type: Copy) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/ice/spot/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ice.spot.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 credentials = new BasicAWSCredentials(accessKey, secretKey);

return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
}
}
22 changes: 22 additions & 0 deletions src/main/java/ice/spot/config/WebClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ice.spot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class WebClientConfig {

@Bean
public WebClient webClient(WebClient.Builder builder) {
return builder
.baseUrl("https://detectingkickboard11-prediction.cognitiveservices.azure.com")
.defaultHeaders(httpHeaders -> {
httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
httpHeaders.add("Prediction-Key", "17482dedf9834e0c958d0e88a3bf940d");
})
.build();
}
}
40 changes: 40 additions & 0 deletions src/main/java/ice/spot/controller/BoardingRecordController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ice.spot.controller;

import ice.spot.annotation.UserId;
import ice.spot.dto.boardingrecord.request.BoardingRecordRequest;
import ice.spot.dto.global.ResponseDto;
import ice.spot.service.BoardingRecordService;
import ice.spot.service.ImageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class BoardingRecordController {

private final ImageService imageService;
private final BoardingRecordService boardingRecordService;

@PostMapping("/boarding-record")
public ResponseDto<?> saveBoardingRecord (
@UserId Long userId,
@RequestPart(value = "image", required = false) MultipartFile multipartFile,
@RequestPart(value = "dto") BoardingRecordRequest boardingRecordRequest
) throws IOException {
Long imageId = imageService.saveImage(multipartFile);

return ResponseDto.created(boardingRecordService
.saveBoardingRecord(userId, imageId, boardingRecordRequest));
}

@GetMapping("/boarding-record")
public ResponseDto<?> getBoardingRecord (@UserId Long userId) {
return ResponseDto.ok(boardingRecordService.boardingRecordList(userId));
}
}
21 changes: 21 additions & 0 deletions src/main/java/ice/spot/controller/ParkingLotController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ice.spot.controller;

import ice.spot.dto.global.ResponseDto;
import ice.spot.service.ParkingLotService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class ParkingLotController {
private final ParkingLotService parkingLotService;

@GetMapping("/kickboard")
public ResponseDto<?> parkingLotList(@RequestParam Double lat, @RequestParam Double lon) {
return ResponseDto.ok(parkingLotService.parkingLotList(lat, lon));
}
}
51 changes: 23 additions & 28 deletions src/main/java/ice/spot/domain/BoardingRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Getter
Expand All @@ -17,44 +18,38 @@ public class BoardingRecord {
@Column(name = "id")
private Long id;

@Column(name = "image_url")
private String imageUrl;
@Column(name = "distance")
private Double distance;

@Column(name = "depart_at")
private LocalDate departAt;
@Column(name = "time")
private Integer time;

@Column(name = "arrive_at")
private LocalDate arriveAt;
@Column(name = "point")
private Integer point;

@Column(name = "depart_lat")
private Double departLat;

@Column(name = "depart_lon")
private Double departLon;

@Column(name = "arrive_lat")
private Double arriveLat;

@Column(name = "arrive_lon")
private Double arriveLon;
@Column(name = "createdAt")
private LocalDateTime createdAt;

@ManyToOne
@JoinColumn(name = "user_id")
private User user;

@OneToOne
@JoinColumn(name = "parking_lot_id", referencedColumnName = "id")
@ManyToOne
@JoinColumn(name = "parking_lot_id")
private ParkingLot parkingLot;

public BoardingRecord(String imageUrl, LocalDate departAt, LocalDate arriveAt, Double departLat, Double departLon, Double arriveLat, Double arriveLon, User user, ParkingLot parkingLot) {
this.imageUrl = imageUrl;
this.departAt = departAt;
this.arriveAt = arriveAt;
this.departLat = departLat;
this.departLon = departLon;
this.arriveLat = arriveLat;
this.arriveLon = arriveLon;
@OneToOne
@JoinColumn(name = "image_id")
private Image image;

@Builder
public BoardingRecord(Double distance, Integer time, Integer point, User user, ParkingLot parkingLot, Image image) {
this.distance = distance;
this.time = time;
this.point = point;
this.createdAt = LocalDateTime.now();
this.user = user;
this.parkingLot = parkingLot;
this.image = image;
}
}
52 changes: 52 additions & 0 deletions src/main/java/ice/spot/domain/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ice.spot.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "image")
public class Image {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "origin_name")
private String originName;

@Column(name = "stored_name")
private String storedName;

@Column(name = "image_url")
private String imageUrl;

@OneToOne(mappedBy = "image")
private BoardingRecord boardingRecord;

public Image(String originName) {
this.originName = originName;
this.storedName = getFileName(originName);
this.imageUrl = "";
}

public void setAccessUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String extractExtension(String originName) {
int index = originName.lastIndexOf('.');

return originName.substring(index, originName.length());
}

public String getFileName(String originName) {
return UUID.randomUUID() + "." + extractExtension(originName);
}

}
7 changes: 5 additions & 2 deletions src/main/java/ice/spot/domain/ParkingLot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -27,6 +30,6 @@ public class ParkingLot {
@Column(name = "detail_address")
private String detailAddress;

@OneToOne(mappedBy = "parkingLot")
private BoardingRecord boardingRecord;
@OneToMany(mappedBy = "parkingLot")
private List<BoardingRecord> boardingRecords = new ArrayList<>();
}
4 changes: 4 additions & 0 deletions src/main/java/ice/spot/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ public void register(String nickname) {
public void updateRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}

public void plusPoint() {
this.point += 100L;
}
}
17 changes: 17 additions & 0 deletions src/main/java/ice/spot/domain/type/ParkingLotResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ice.spot.domain.type;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ParkingLotResult {

CORRECT_PARKING_LOT(0, "올바른 주차구역에 주차되었습니다."),
WRONG_PARKING_LOT(1, "올바르지 않은 주차구역입니다."),
NOT_FOUND_KICKBOARD(2, "킥보드가 인식되지 않습니다."),
;

private final Integer code;
private final String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ice.spot.dto.boardingrecord.request;

import lombok.Builder;

@Builder
public record BoardingRecordRequest(
Double distance,
Integer time
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ice.spot.dto.boardingrecord.response;

import ice.spot.dto.user.response.PersonResponse;
import lombok.Builder;

import java.util.List;

@Builder
public record BoardingRecordListResponse(
PersonResponse personResponse,

List<BoardingRecordResponse> boardingRecordResponseList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ice.spot.dto.boardingrecord.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;

@Builder
public record BoardingRecordResponse(
@JsonProperty("created_at")
String createdAt,

@JsonProperty("image")
String image,

@JsonProperty("distance")
Double distance,

@JsonProperty("time")
Integer time,

@JsonProperty("point")
Integer point
) {
public static BoardingRecordResponse of(String createdAt, String image, Double distance, Integer time, Integer point) {
return new BoardingRecordResponse(createdAt, image, distance, time, point);
}
}
2 changes: 1 addition & 1 deletion src/main/java/ice/spot/dto/global/ExceptionDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ice.spot.dto.global;

import ice.spot.exeption.ErrorCode;
import ice.spot.exception.ErrorCode;

public record ExceptionDto(
Integer code,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ice/spot/dto/global/ResponseDto.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ice.spot.dto.global;

import ice.spot.exeption.CommonException;
import ice.spot.exeption.ErrorCode;
import ice.spot.exception.CommonException;
import ice.spot.exception.ErrorCode;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import net.minidev.json.annotate.JsonIgnore;
Expand Down
Loading

0 comments on commit d626bdc

Please sign in to comment.