-
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 #17 from UMC-HKT-Team-R/feat/6
[Feat] 캘린더 등록하기
- Loading branch information
Showing
20 changed files
with
235 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file modified
BIN
+4.05 KB
(110%)
Midnight-Snacker/.gradle/8.11.1/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified
BIN
+30.7 KB
(170%)
Midnight-Snacker/.gradle/8.11.1/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified
BIN
+550 Bytes
(100%)
Midnight-Snacker/.gradle/8.11.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file not shown.
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
21 changes: 21 additions & 0 deletions
21
...cker/src/main/java/com/example/Midnight/Snacker/apiPayload/exception/CustomException.java
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.example.Midnight.Snacker.apiPayload.exception; | ||
|
||
import com.example.Midnight.Snacker.apiPayload.code.status.ErrorStatus; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class CustomException extends RuntimeException { | ||
private final ErrorStatus errorStatus; | ||
|
||
public CustomException(ErrorStatus errorStatus) { | ||
super(errorStatus.getMessage()); | ||
this.errorStatus = errorStatus; | ||
} | ||
|
||
public HttpStatus getHttpStatus() { | ||
return errorStatus.getHttpStatus(); | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorStatus.getCode(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Midnight-Snacker/src/main/java/com/example/Midnight/Snacker/converter/CalendarConverter.java
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,29 @@ | ||
package com.example.Midnight.Snacker.converter; | ||
|
||
import com.example.Midnight.Snacker.domain.Calendar; | ||
import com.example.Midnight.Snacker.domain.Member; | ||
import com.example.Midnight.Snacker.domain.enums.Category; | ||
import com.example.Midnight.Snacker.domain.enums.Color; | ||
import com.example.Midnight.Snacker.web.dto.CalendarDTO.RegisterRequestDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CalendarConverter { | ||
public Calendar toCalendar(Member member, | ||
RegisterRequestDTO request, | ||
String imageUrl, | ||
Category category, | ||
Color color) { | ||
return Calendar.builder() | ||
.date(request.getDate()) | ||
.detailFood(request.getDetailFood()) | ||
.color(color) | ||
.category(category) | ||
.imageUrl(imageUrl) | ||
.member(member) | ||
.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
5 changes: 5 additions & 0 deletions
5
Midnight-Snacker/src/main/java/com/example/Midnight/Snacker/domain/enums/Category.java
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,5 @@ | ||
package com.example.Midnight.Snacker.domain.enums; | ||
|
||
public enum Category { | ||
한식, 중식, 일식, 양식, 아시안, 패스트푸드, 카페, 고기 | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...r/src/main/java/com/example/Midnight/Snacker/service/CalendarService/CalendarService.java
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,14 @@ | ||
package com.example.Midnight.Snacker.service.CalendarService; | ||
|
||
import com.example.Midnight.Snacker.domain.Member; | ||
import com.example.Midnight.Snacker.domain.enums.Category; | ||
import com.example.Midnight.Snacker.domain.enums.Color; | ||
import com.example.Midnight.Snacker.web.dto.CalendarDTO.RegisterRequestDTO; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
public interface CalendarService { | ||
Long addRecord(Member member, Category category, Color color, MultipartFile image, RegisterRequestDTO request); | ||
} |
49 changes: 49 additions & 0 deletions
49
...c/main/java/com/example/Midnight/Snacker/service/CalendarService/CalendarServiceImpl.java
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,49 @@ | ||
package com.example.Midnight.Snacker.service.CalendarService; | ||
|
||
import com.example.Midnight.Snacker.apiPayload.exception.CustomException; | ||
import com.example.Midnight.Snacker.converter.CalendarConverter; | ||
import com.example.Midnight.Snacker.domain.Calendar; | ||
import com.example.Midnight.Snacker.domain.Member; | ||
import com.example.Midnight.Snacker.domain.enums.Category; | ||
import com.example.Midnight.Snacker.domain.enums.Color; | ||
import com.example.Midnight.Snacker.repository.CalendarRepository; | ||
import com.example.Midnight.Snacker.service.S3Service.S3ImageService; | ||
import com.example.Midnight.Snacker.web.dto.CalendarDTO.RegisterRequestDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CalendarServiceImpl implements CalendarService { | ||
private final CalendarRepository calendarRepository; | ||
private final S3ImageService s3ImageService; | ||
private final CalendarConverter calendarConverter; | ||
|
||
//야식 기록 추가 method | ||
@Override | ||
@Transactional | ||
public Long addRecord(Member member, Category category, Color color, MultipartFile image, RegisterRequestDTO request){ | ||
//upload file 하기 | ||
String imageUrl = s3ImageService.upload(image); | ||
//Calendar 엔티티 생성 | ||
|
||
Calendar calendar = | ||
calendarConverter.toCalendar(member,request, imageUrl, category, color); | ||
|
||
Calendar savedCalendar = calendarRepository.save(calendar); | ||
|
||
return savedCalendar.getId(); | ||
} | ||
//월별 기록 조회 method | ||
|
||
//일별 기록 조회 method | ||
|
||
//기록 삭제 method | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...Snacker/src/main/java/com/example/Midnight/Snacker/web/controller/CalendarController.java
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,52 @@ | ||
package com.example.Midnight.Snacker.web.controller; | ||
|
||
import com.example.Midnight.Snacker.apiPayload.ApiResponse; | ||
import com.example.Midnight.Snacker.apiPayload.code.status.SuccessStatus; | ||
import com.example.Midnight.Snacker.domain.Member; | ||
import com.example.Midnight.Snacker.domain.enums.Category; | ||
import com.example.Midnight.Snacker.domain.enums.Color; | ||
import com.example.Midnight.Snacker.security.handler.annotation.AuthUser; | ||
import com.example.Midnight.Snacker.service.CalendarService.CalendarService; | ||
import com.example.Midnight.Snacker.service.CalendarService.CalendarServiceImpl; | ||
import com.example.Midnight.Snacker.web.dto.CalendarDTO.CalendarResponseDTO; | ||
import com.example.Midnight.Snacker.web.dto.CalendarDTO.RegisterRequestDTO; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import lombok.*; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.awt.*; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/calendar") | ||
public class CalendarController { | ||
private final CalendarService calendarService; | ||
|
||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@Operation(summary = "캘린더 등록") | ||
public ApiResponse<Long> registerCalendar( | ||
@Parameter(name = "user", hidden = true) @AuthUser Member member, | ||
@RequestParam(value = "category")Category category, | ||
@RequestParam(value = "colorType")Color color, | ||
@RequestPart("request")RegisterRequestDTO request, | ||
@RequestPart(value = "image") MultipartFile image){ | ||
Long calendarId = calendarService.addRecord(member, category, | ||
color, image, request); | ||
|
||
return ApiResponse.of(SuccessStatus._OK, calendarId); | ||
} | ||
|
||
/*@GetMapping | ||
@Operation | ||
public ApiResponse<CalendarResponseDTO> showCalendar( | ||
@RequestParam(value = "date") LocalDate date){ | ||
return ApiResponse.of(SuccessStatus._OK,) | ||
}*/ | ||
} |
17 changes: 17 additions & 0 deletions
17
...r/src/main/java/com/example/Midnight/Snacker/web/dto/CalendarDTO/CalendarResponseDTO.java
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,17 @@ | ||
package com.example.Midnight.Snacker.web.dto.CalendarDTO; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CalendarResponseDTO { | ||
private LocalDate date; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...er/src/main/java/com/example/Midnight/Snacker/web/dto/CalendarDTO/RegisterRequestDTO.java
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,17 @@ | ||
package com.example.Midnight.Snacker.web.dto.CalendarDTO; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RegisterRequestDTO { | ||
private LocalDateTime date; | ||
private String detailFood; | ||
} |