Skip to content

Commit

Permalink
Merge pull request #52 from HyeJiJUN11/feature/47-Diary
Browse files Browse the repository at this point in the history
feat: 일기 API 추가 구현
  • Loading branch information
peeerr authored Oct 16, 2024
2 parents 040a0d5 + f4babd5 commit 1418219
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 152 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
implementation 'org.hibernate:hibernate-spatial:6.6.1.Final'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.potatocake.everymoment.config;

import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.PrecisionModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GeometryConfig {
@Bean
public GeometryFactory geometryFactory() {
return new GeometryFactory(new PrecisionModel(), 4326);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.LocationPoint;
import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.CommentRequest;
import com.potatocake.everymoment.dto.request.DiaryAutoCreateRequest;
Expand Down Expand Up @@ -87,8 +88,8 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(required = false) String keyword,
@Parameter(description = "이모지 필터")
@RequestParam(required = false) String emoji,
@Parameter(description = "카테고리 ID")
@RequestParam(required = false) Long category,
@Parameter(description = "카테고리")
@RequestParam(required = false) String category,
@Parameter(description = "특정 날짜")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@Parameter(description = "시작 날짜")
Expand All @@ -103,14 +104,15 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(defaultValue = "10") int size
) {
Long memberId = memberDetails.getId();

DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
.category(category)
.date(date)
.from(from)
.until(until)
.bookmark(bookmark)
.isBookmark(bookmark)
.key(key)
.size(size)
.build();
Expand All @@ -137,6 +139,22 @@ public ResponseEntity<SuccessResponse<MyDiaryResponse>> getMyDiary(
.body(SuccessResponse.ok(response));
}

@Operation(summary = "특정 일기 위경도 조회", description = "특정 일기에 있는 위경도를 조회합니다.")
@ApiResponse(responseCode = "200", description = "위경도 조회 성공")
@GetMapping("/{diaryId}/location")
public ResponseEntity<SuccessResponse<LocationPoint>> getLocation(
@Parameter(description = "인증된 사용자 정보", hidden = true)
@AuthenticationPrincipal MemberDetails memberDetails,
@Parameter(description = "조회할 일기 ID", required = true)
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

LocationPoint response = diaryService.getDiaryLocation(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

@Operation(summary = "일기 수정", description = "기존 일기를 수정합니다.")
@ApiResponse(responseCode = "200", description = "일기 수정 성공")
@PatchMapping("/{diaryId}")
Expand Down Expand Up @@ -213,8 +231,8 @@ public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
@RequestParam(required = false) String keyword,
@Parameter(description = "이모지 필터")
@RequestParam(required = false) String emoji,
@Parameter(description = "카테고리 ID")
@RequestParam(required = false) Long category,
@Parameter(description = "카테고리")
@RequestParam(required = false) String category,
@Parameter(description = "특정 날짜")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@Parameter(description = "시작 날짜")
Expand All @@ -229,14 +247,15 @@ public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
@RequestParam(defaultValue = "10") int size
) {
Long memberId = memberDetails.getId();

DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
.category(category)
.date(date)
.from(from)
.until(until)
.bookmark(bookmark)
.isBookmark(bookmark)
.key(key)
.size(size)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.potatocake.everymoment.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@AllArgsConstructor
@Getter
@Builder
public class LocationPoint {
private double latitude;
private double longitude;

@Override
public String toString() {
return latitude + "/" + longitude;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.potatocake.everymoment.dto.request;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -9,11 +13,26 @@
public class DiaryFilterRequest {
private String keyword;
private String emoji;
private Long category;
private String category;
private LocalDate date;
private LocalDate from;
private LocalDate until;
private Boolean bookmark;
private Boolean isBookmark;
private int key;
private int size;

public List<String> getEmojis() {
return (emoji != null && !emoji.isEmpty())
? Arrays.asList(emoji.split(","))
: Collections.emptyList();
}

public List<Long> getCategories() {
return (category != null && !category.isEmpty())
? Arrays.stream(category.split(","))
.map(Long::parseLong)
.collect(Collectors.toList())
: Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class FriendDiaryResponse {
private List<CategoryResponse> categories;
private String locationName;
private String emoji;
private List<FileResponse> file;
private String content;
private Integer likeCount;
private LikeCountResponse likeCount;
private LocalDateTime createAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class MyDiaryResponse {
private String locationName;
private boolean isBookmark;
private String emoji;
private List<FileResponse> file;
private String content;
private LocalDateTime createAt;
}
8 changes: 4 additions & 4 deletions src/main/java/com/potatocake/everymoment/entity/Diary.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.Point;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -32,9 +33,8 @@ public class Diary extends BaseTimeEntity {
@Lob
private String content;

//point는 mysql연결 뒤에
@Column(length = 250, nullable = false)
private String locationPoint; // Java에서는 문자열로 처리
@Column(nullable = false)
private Point locationPoint;

@Column(length = 50, nullable = false)
private String locationName;
Expand All @@ -59,7 +59,7 @@ public void updateContent(String content) {
}
}

public void updateLocationPoint(String locationPoint) {
public void updateLocationPoint(Point locationPoint) {
if (locationPoint != null) {
this.locationPoint = locationPoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@JsonInclude(Include.NON_NULL)
public class ErrorResponse {

private int code;
private String message;
private Map<String, String> validation;
private final int code;
private final String message;
private final Map<String, String> validation;

@Builder
public ErrorResponse(int code, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.potatocake.everymoment.repository;

import com.potatocake.everymoment.entity.Diary;
import com.potatocake.everymoment.entity.DiaryCategory;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface DiaryCategoryRepository extends JpaRepository<DiaryCategory, Long> {
List<DiaryCategory> findByCategoryId(Long categoryId);

List<DiaryCategory> findByDiary(Diary diary);

void deleteByDiary(Diary diary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public interface FileRepository extends JpaRepository<File, Long> {

List<File> findByDiaryId(Long diaryId);

List<File> findByDiary(Diary diary);

File findByDiaryAndOrder(Diary diary, int order);

void deleteByDiary(Diary diary);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class MemberDetails implements UserDetails {

private final Member member;
private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LoginFilter extends UsernamePasswordAuthenticationFilter {
private final AuthenticationManager authenticationManager;
private final MemberRepository memberRepository;

private boolean postOnly = true;
private final boolean postOnly = true;

public LoginFilter(String filterProcessesUrl, ObjectMapper objectMapper, JwtUtil jwtUtil,
MemberRepository memberRepository, AuthenticationManager authenticationManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
import com.potatocake.everymoment.repository.CommentRepository;
import com.potatocake.everymoment.repository.DiaryRepository;
import com.potatocake.everymoment.repository.MemberRepository;
import com.potatocake.everymoment.security.MemberDetails;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down
Loading

0 comments on commit 1418219

Please sign in to comment.