Skip to content

Commit

Permalink
Merge pull request #21 from HyeJiJUN11/feature/18-friendAPI
Browse files Browse the repository at this point in the history
feat: 친구 관련 API 구현
  • Loading branch information
peeerr authored Sep 27, 2024
2 parents b7841f0 + ab55440 commit 7c69c7e
Show file tree
Hide file tree
Showing 26 changed files with 862 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
Expand All @@ -39,6 +40,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.formLogin(auth -> auth.disable())
.httpBasic(auth -> auth.disable());

http
.headers(header -> header.frameOptions(FrameOptionsConfig::sameOrigin));

http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/members/login", "/h2-console/**", "/error").permitAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.DiaryAutoRequest;
import com.potatocake.everymoment.dto.request.DiaryManualRequest;
import com.potatocake.everymoment.dto.request.DiaryAutoCreateRequest;
import com.potatocake.everymoment.dto.request.DiaryFilterRequest;
import com.potatocake.everymoment.dto.request.DiaryManualCreateRequest;
import com.potatocake.everymoment.dto.response.FriendDiariesResponse;
import com.potatocake.everymoment.dto.response.FriendDiaryResponse;
import com.potatocake.everymoment.dto.response.MyDiariesResponse;
import com.potatocake.everymoment.dto.response.MyDiaryResponse;
import com.potatocake.everymoment.dto.response.NotificationResponse;
import com.potatocake.everymoment.service.DiaryService;
import com.potatocake.everymoment.service.FriendDiaryService;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,46 +26,42 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("api/diaries")
@RequestMapping("/api/diaries")
public class DiaryController {

private final DiaryService diaryService;

public DiaryController(DiaryService diaryService) {
this.diaryService = diaryService;
}
private final FriendDiaryService friendDiaryService;

//자동 일기 작성
@PostMapping("/auto")
public ResponseEntity<SuccessResponse<NotificationResponse>> createDiaryAuto(
@RequestBody DiaryAutoRequest diaryAutoRequest) {
NotificationResponse notificationResponse = diaryService.createDiaryAuto(diaryAutoRequest);
@RequestBody DiaryAutoCreateRequest diaryAutoCreateRequest) {
NotificationResponse notificationResponse = diaryService.createDiaryAuto(diaryAutoCreateRequest);
SuccessResponse<NotificationResponse> response = SuccessResponse.<NotificationResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(notificationResponse)
.build();

return ResponseEntity.ok(response);
}

//수기 일기 작성
@PostMapping("/manual")
public ResponseEntity<SuccessResponse<Void>> createDiaryManual(
@RequestBody DiaryManualRequest diaryManualRequest) {
diaryService.createDiaryManual(diaryManualRequest);
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
diaryService.createDiaryManual(diaryManualCreateRequest);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();

return ResponseEntity.ok(response);
}

//내 일기 전체 조회(타임라인)
@GetMapping("my")
@GetMapping("/my")
public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String emoji,
Expand All @@ -72,14 +73,24 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size
) {
MyDiariesResponse myDiariesResponse = diaryService.getMyDiaries(keyword, emoji, category, date, from, until,
bookmark, key, size);
DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
.category(category)
.date(date)
.from(from)
.until(until)
.bookmark(bookmark)
.key(key)
.size(size)
.build();

MyDiariesResponse myDiariesResponse = diaryService.getMyDiaries(diaryFilterRequest);
SuccessResponse<MyDiariesResponse> response = SuccessResponse.<MyDiariesResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(myDiariesResponse)
.build();

return ResponseEntity.ok(response);
}

Expand All @@ -92,15 +103,14 @@ public ResponseEntity<SuccessResponse<MyDiaryResponse>> getMyDiary(@PathVariable
.message("success")
.info(myDiaryResponse)
.build();

return ResponseEntity.ok(response);
}

//일기 수정
@PatchMapping("/{id}")
public ResponseEntity<SuccessResponse<Void>> updateDiary(@PathVariable Long id,
@RequestBody DiaryManualRequest diaryManualRequest) {
diaryService.updateDiary(id, diaryManualRequest);
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
diaryService.updateDiary(id, diaryManualCreateRequest);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
Expand Down Expand Up @@ -144,4 +154,50 @@ public ResponseEntity<SuccessResponse<Void>> togglePrivacy(@PathVariable Long id
.build();
return ResponseEntity.ok(response);
}

//전체 친구 일기 조회
@GetMapping("/friend")
public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String emoji,
@RequestParam(required = false) Long category,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate until,
@RequestParam(required = false) Boolean bookmark,
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size
) {
DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
.category(category)
.date(date)
.from(from)
.until(until)
.bookmark(bookmark)
.key(key)
.size(size)
.build();

FriendDiariesResponse diaries = friendDiaryService.getFriendDiaries(diaryFilterRequest);
SuccessResponse<FriendDiariesResponse> response = SuccessResponse.<FriendDiariesResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(diaries)
.build();
return ResponseEntity.ok(response);
}

//친구 일기 상제 조회
@GetMapping("/friend/{id}")
public ResponseEntity<SuccessResponse<FriendDiaryResponse>> getFriendDiary(@PathVariable Long id) {
FriendDiaryResponse diary = friendDiaryService.getFriendDiary(id);
SuccessResponse<FriendDiaryResponse> response = SuccessResponse.<FriendDiaryResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(diary)
.build();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.response.FriendListResponse;
import com.potatocake.everymoment.dto.response.OneFriendDiariesResponse;
import com.potatocake.everymoment.service.FriendService;
import java.time.LocalDate;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/friends")
public class FriendController {
private final FriendService friendService;

public FriendController(FriendService friendService) {
this.friendService = friendService;
}

//특정 친구 일기 전체 조회
@GetMapping("/{id}/diaries")
public ResponseEntity<SuccessResponse<OneFriendDiariesResponse>> getOneFriendDiaries(
@PathVariable Long id,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size) {
OneFriendDiariesResponse diaries = friendService.OneFriendDiariesResponse(id, date, key, size);
SuccessResponse<OneFriendDiariesResponse> response = SuccessResponse.<OneFriendDiariesResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(diaries)
.build();
return ResponseEntity.ok(response);
}

//내 친구 목록 조회
@GetMapping("/friends")
public ResponseEntity<SuccessResponse<FriendListResponse>> getFriendList(
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String email,
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size) {
FriendListResponse friendList = friendService.getFriendList(nickname, email, key, size);
SuccessResponse<FriendListResponse> response = SuccessResponse.<FriendListResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(friendList)
.build();
return ResponseEntity.ok(response);
}

//내 친구 삭제
@DeleteMapping("/{id}")
public ResponseEntity<SuccessResponse<Void>> deleteFriend(@PathVariable Long id) {
friendService.deleteFriend(id);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
}

//친한 친구 설정
@PatchMapping("/{id}/bookmark")
public ResponseEntity<SuccessResponse<Void>> toggleCloseFriend(@PathVariable Long id) {
friendService.toggleCloseFriend(id);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Getter;

@Getter
public class DiaryAutoRequest {
public class DiaryAutoCreateRequest {
private LocationPoint locationPoint;
private String locationName;
private String address;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.potatocake.everymoment.dto.request;

import java.time.LocalDate;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class DiaryFilterRequest {
private String keyword;
private String emoji;
private Long category;
private LocalDate date;
private LocalDate from;
private LocalDate until;
private Boolean bookmark;
private int key;
private int size;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;

@Getter
public class DiaryManualRequest {
public class DiaryManualCreateRequest {
private List<CategoryRequest> categories;
private LocationPoint locationPoint;
private String locationName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.potatocake.everymoment.dto.response;

import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class FriendDiariesResponse {
private List<FriendDiarySimpleResponse> diaries;
private Integer next;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.potatocake.everymoment.dto.response;

import java.time.LocalDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FriendDiaryResponse {
private Long id;
private List<CategoryResponse> categories;
private String locationName;
private String emoji;
private List<FileResponse> file;
private String content;
private Integer likeCount;
private LocalDateTime createAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.potatocake.everymoment.dto.response;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FriendDiarySimpleResponse {
private Long id;
private String locationName;
private String address;
private boolean isBookmark;
private boolean isPublic;
private String emoji;
private ThumbnailResponse thumbnailResponse;
private String content;
private LocalDateTime createAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.potatocake.everymoment.dto.response;

import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class FriendListResponse {
private List<FriendProfileResponse> friends;
private Integer next;
}
Loading

0 comments on commit 7c69c7e

Please sign in to comment.