-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from PetQ-A/feature/mypage
Feature/mypage
- Loading branch information
Showing
20 changed files
with
689 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.petqa.api; | ||
|
||
import com.petqa.apiPayload.apiPayload.ApiResponse; | ||
import com.petqa.dto.diary.DiaryRequestDTO; | ||
import com.petqa.dto.diary.DiaryResponseDTO; | ||
import com.petqa.service.diary.DiaryService; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hibernate.engine.spi.Resolution; | ||
import java.time.LocalDate; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.WebDataBinder; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.security.Principal; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/diary") | ||
@RequiredArgsConstructor | ||
public class DiaryAPIController { | ||
private final DiaryService diaryService; | ||
|
||
|
||
@PostMapping("/{diaryDate}") | ||
public ResponseEntity<ApiResponse<DiaryResponseDTO>> writeDiary(Principal principal, | ||
@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate diaryDate, | ||
@RequestPart("request") DiaryRequestDTO.AllDto request, | ||
@RequestPart(value = "petProfileImage", required = false) MultipartFile diaryImage) { | ||
|
||
request.setImg(diaryImage); | ||
String username = principal.getName(); | ||
DiaryResponseDTO written = diaryService.writeMyDiary(username, diaryDate, request); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(written)); | ||
} | ||
|
||
@PatchMapping("/memo/{diaryDate}") | ||
public ResponseEntity<ApiResponse<DiaryResponseDTO>> modifyMemo(Principal principal, | ||
@PathVariable LocalDate diaryDate, | ||
@RequestBody DiaryRequestDTO.MemoDto request){ | ||
String username = principal.getName(); | ||
DiaryResponseDTO modified = diaryService.modifyMyMemo(username, diaryDate, request); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(modified)); | ||
} | ||
|
||
@PatchMapping("/picture/{diaryDate}") | ||
public ResponseEntity<ApiResponse<DiaryResponseDTO>> modifyImage(Principal principal, | ||
@PathVariable LocalDate diaryDate, | ||
@RequestPart(value = "petProfileImage", required = false) MultipartFile diaryImage){ | ||
String username = principal.getName(); | ||
DiaryResponseDTO modified = diaryService.modifyMyImage(username, diaryDate, diaryImage); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(modified)); | ||
} | ||
|
||
@DeleteMapping("/picture/{diaryDate}") | ||
public ResponseEntity<ApiResponse<DiaryResponseDTO>> eraseImage(Principal principal, | ||
@PathVariable LocalDate diaryDate){ | ||
String username = principal.getName(); | ||
DiaryResponseDTO modified = diaryService.eraseMyImage(username, diaryDate); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(modified)); | ||
} | ||
|
||
@GetMapping("/{diaryDate}") | ||
public ResponseEntity<ApiResponse<DiaryResponseDTO>> showDiary(Principal principal, | ||
@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") | ||
LocalDate diaryDate){ | ||
String username = principal.getName(); | ||
DiaryResponseDTO eachDiary = diaryService.showMyDiary(username, diaryDate); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(eachDiary)); | ||
} | ||
|
||
@GetMapping("/all") | ||
public ResponseEntity<ApiResponse<List<DiaryResponseDTO>>> showAllDiary(Principal principal){ | ||
String username = principal.getName(); | ||
List<DiaryResponseDTO> allDiary = diaryService.showMyAllDiary(username); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(allDiary)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.petqa.api; | ||
|
||
import com.petqa.apiPayload.apiPayload.ApiResponse; | ||
import com.petqa.base.Util; | ||
import com.petqa.domain.User; | ||
import com.petqa.dto.diary.DiaryRequestDTO; | ||
import com.petqa.dto.diary.DiaryResponseDTO; | ||
import com.petqa.dto.mypage.MypageRequestDTO; | ||
import com.petqa.dto.user.UserResponseDTO; | ||
import com.petqa.service.mypage.MypageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.security.Principal; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import static com.petqa.base.Util.getCurrentUser; | ||
|
||
@RestController | ||
@RequestMapping("/mypage") | ||
@RequiredArgsConstructor | ||
public class MypageAPIController { | ||
|
||
private final MypageService mypageService; | ||
|
||
@GetMapping("/profile") | ||
public ResponseEntity<ApiResponse<UserResponseDTO.UserDetail>> showMyPage(){ | ||
|
||
User user = getCurrentUser(); | ||
UserResponseDTO.UserDetail info = mypageService.showMyInfo(user); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(info)); | ||
} | ||
|
||
@PatchMapping("/profile") | ||
public ResponseEntity<ApiResponse<UserResponseDTO.MypageDetail>> modifyMyPage(@RequestPart("request") MypageRequestDTO request, | ||
@RequestPart(value = "petProfileImage", required = false) MultipartFile profileImage){ | ||
User user = getCurrentUser(); | ||
UserResponseDTO.MypageDetail info = mypageService.modifyMyInfo(user, request, profileImage); | ||
|
||
return ResponseEntity.ok(ApiResponse.onSuccess(info)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.petqa.converter; | ||
|
||
import com.petqa.domain.Diary; | ||
import com.petqa.dto.diary.DiaryResponseDTO; | ||
|
||
public class DiaryConverter { | ||
public static DiaryResponseDTO responseDTO(Diary diary){ | ||
return DiaryResponseDTO.builder() | ||
.img(diary.getImg()) | ||
.memo(diary.getMemo()) | ||
.createdAt(diary.getCreatedAt()) | ||
.modifiedAt(diary.getModifiedAt()) | ||
.date(diary.getDate()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.petqa.converter; | ||
|
||
import com.petqa.domain.Pet; | ||
import com.petqa.dto.user.UserResponseDTO; | ||
|
||
public class MypageConverter { | ||
public static UserResponseDTO.PetDetail convertToPetDetail(Pet pet) { | ||
return UserResponseDTO.PetDetail.builder() | ||
.id(pet.getId()) | ||
.name(pet.getName()) | ||
.petType(pet.getPetType()) | ||
.birth(pet.getBirth()) | ||
.profileImage(pet.getProfileImage()) | ||
.weight(pet.getWeight()) | ||
.gender(pet.getGender()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.petqa.domain; | ||
|
||
import com.petqa.domain.common.BaseEntity; | ||
import com.petqa.domain.common.MutableBaseEntity; | ||
import com.petqa.dto.diary.DiaryResponseDTO; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.joda.time.DateTime; | ||
import java.time.LocalDate; | ||
|
||
import java.util.Base64; | ||
import java.util.Date; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class Diary extends MutableBaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "diary_id") | ||
private Long id; | ||
|
||
private String img; | ||
|
||
@Column(length = 18) | ||
private String memo; | ||
|
||
private LocalDate date; // 이름 | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
// public DiaryResponseDTO toResponseDTO() { | ||
// return DiaryResponseDTO.builder() | ||
// .memo(memo) | ||
// .date(date) | ||
// .img(img) | ||
// .build(); | ||
// } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.petqa.dto.diary; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.petqa.domain.Diary; | ||
import com.petqa.domain.User; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.time.LocalDate; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
|
||
|
||
public class DiaryRequestDTO { | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public static class AllDto { | ||
private MultipartFile img; // 여기서 img 필드가 MultipartFile 타입이어야 함 | ||
private String memo; | ||
|
||
public Diary toEntity(User user, LocalDate diaryDate, String imgUrl) { | ||
return Diary.builder() | ||
.user(user) | ||
.memo(memo) | ||
.date(diaryDate) | ||
.img(imgUrl) | ||
.build(); | ||
} | ||
} | ||
|
||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public static class ImageDto { | ||
private String img; | ||
} | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public static class MemoDto { | ||
private String memo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.petqa.dto.diary; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import java.time.LocalDate; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class DiaryResponseDTO { | ||
String img; | ||
String memo; | ||
LocalDateTime createdAt; | ||
LocalDateTime modifiedAt; | ||
LocalDate date; // 이름 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.petqa.dto.mypage; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Setter | ||
public class MypageRequestDTO { | ||
private String username; | ||
private String petType; | ||
private String petName; | ||
private LocalDate petBirth; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.petqa.repository; | ||
|
||
import com.petqa.domain.Diary; | ||
import com.petqa.domain.User; | ||
import java.time.LocalDate; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface DiaryRepository extends JpaRepository<Diary, Long> { | ||
Optional<Diary> findByDate(LocalDate diaryDate); | ||
|
||
Optional<Diary> findByUserAndDate(User user, LocalDate date); | ||
|
||
Optional<List<Diary>> findByUser(User user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.petqa.repository; | ||
|
||
import com.petqa.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MypageRepository extends JpaRepository<User, Long> { | ||
boolean existsByUsername(String username); | ||
} |
Oops, something went wrong.