-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] TIL(Today I Learned) API 구현
- Loading branch information
Showing
14 changed files
with
416 additions
and
5 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...va/com/umc/networkingService/domain/todayILearned/controller/TodayILearnedController.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,86 @@ | ||
package com.umc.networkingService.domain.todayILearned.controller; | ||
|
||
import com.umc.networkingService.config.security.auth.CurrentMember; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedCreate; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedUpdate; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedId; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfo; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfos; | ||
import com.umc.networkingService.domain.todayILearned.service.TodayILearnedService; | ||
import com.umc.networkingService.global.common.base.BaseResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Tag(name = "Today I Learned API", description = "Today I Learned 관련 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/today-i-learned") | ||
public class TodayILearnedController { | ||
|
||
private final TodayILearnedService todayILearnedService; | ||
|
||
// POST | ||
@Operation(summary = "Today I Learned 추가", description = "TIL을 추가하는 API입니다.") | ||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공") | ||
}) | ||
public BaseResponse<TodayILearnedId> createTodayILearned(@CurrentMember Member member, | ||
@RequestPart(value = "files", required = false) List<MultipartFile> files, | ||
@RequestPart("request") TodayILearnedCreate request) { | ||
|
||
return BaseResponse.onSuccess(todayILearnedService.createTodayILearned(member, files, request)); | ||
} | ||
|
||
@Operation(summary = "Today I Learned 수정", description = "TIL를 수정하는 API입니다.") | ||
@PostMapping(value = {"update/{todayILearnedId}"}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공") | ||
}) | ||
public BaseResponse<TodayILearnedId> updateTodayILearned(@CurrentMember Member member, | ||
@PathVariable("todayILearnedId") UUID todayILearnedId, | ||
@RequestPart(value = "files", required = false) List<MultipartFile> files, | ||
@RequestPart("request") TodayILearnedUpdate request) { | ||
|
||
return BaseResponse.onSuccess(todayILearnedService.updateTodayILearned(member, todayILearnedId, files, request)); | ||
} | ||
|
||
//GET | ||
@Operation(summary = "Today I Learned 조회(일별)", description = "TIL(일별)을 조회하는 API입니다.") | ||
@GetMapping | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공") | ||
}) | ||
public BaseResponse<TodayILearnedInfos> getTodayILearnedInfos(@CurrentMember Member member) { | ||
|
||
return BaseResponse.onSuccess(todayILearnedService.getTodayILearnedInfos(member)); | ||
} | ||
|
||
// DELETE | ||
@Operation(summary = "Today I Learned 삭제", description = "TIL을 삭제하는 API입니다.") | ||
@DeleteMapping("/{todayILearnedId}") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공") | ||
}) | ||
public BaseResponse<TodayILearnedId> deleteTodayILearned(@CurrentMember Member member, | ||
@PathVariable("todayILearnedId") UUID todayILearnedId) { | ||
return BaseResponse.onSuccess(todayILearnedService.deleteTodayILearned(member, todayILearnedId)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ava/com/umc/networkingService/domain/todayILearned/dto/requeest/TodayILearnedRequest.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,33 @@ | ||
package com.umc.networkingService.domain.todayILearned.dto.requeest; | ||
|
||
import com.umc.networkingService.global.common.enums.Part; | ||
import java.util.UUID; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
public class TodayILearnedRequest { | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public static class TodayILearnedCreate { | ||
private Part part; | ||
private String title; | ||
private String subTitle; | ||
private String content; | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public static class TodayILearnedUpdate { | ||
private String title; | ||
private String subTitle; | ||
private String content; | ||
private Part part; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...va/com/umc/networkingService/domain/todayILearned/dto/response/TodayILearnedResponse.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,40 @@ | ||
package com.umc.networkingService.domain.todayILearned.dto.response; | ||
|
||
import com.umc.networkingService.global.common.enums.Part; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
public class TodayILearnedResponse { | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public static class TodayILearnedId { | ||
private UUID todayILearnedId; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class TodayILearnedInfo { | ||
private UUID todayILearnedId; | ||
private String title; | ||
private String subTitle; | ||
private Part part; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class TodayILearnedInfos { | ||
private List<TodayILearnedInfo> todayILearnedInfos; | ||
} | ||
|
||
} |
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
15 changes: 15 additions & 0 deletions
15
...n/java/com/umc/networkingService/domain/todayILearned/mapper/TodayILearnedFileMapper.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,15 @@ | ||
package com.umc.networkingService.domain.todayILearned.mapper; | ||
|
||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearned; | ||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearnedFile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class TodayILearnedFileMapper { | ||
public TodayILearnedFile toTodayILearnedFile(TodayILearned todayILearned, String url) { | ||
return TodayILearnedFile.builder() | ||
.todayILearned(todayILearned) | ||
.url(url) | ||
.build(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/umc/networkingService/domain/todayILearned/mapper/TodayILearnedMapper.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,50 @@ | ||
package com.umc.networkingService.domain.todayILearned.mapper; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedCreate; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedUpdate; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedId; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfo; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfos; | ||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearned; | ||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearnedFile; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class TodayILearnedMapper { | ||
|
||
public TodayILearned toTodayILearned(Member member, TodayILearnedCreate request) { | ||
return TodayILearned.builder() | ||
.writer(member) | ||
.title(request.getTitle()) | ||
.subtitle(request.getSubTitle()) | ||
.content(request.getContent()) | ||
.part(request.getPart()) | ||
.build(); | ||
} | ||
|
||
public TodayILearnedId toTodayILearnedId(UUID todayILearnedId) { | ||
return TodayILearnedId.builder() | ||
.todayILearnedId(todayILearnedId) | ||
.build(); | ||
} | ||
|
||
public TodayILearnedInfo toTodayILearnedInfo(TodayILearned todayILearned) { | ||
return TodayILearnedInfo.builder() | ||
.todayILearnedId(todayILearned.getId()) | ||
.title(todayILearned.getTitle()) | ||
.subTitle(todayILearned.getSubtitle()) | ||
.part(todayILearned.getPart()) | ||
.build(); | ||
} | ||
|
||
public TodayILearnedInfos toTodayILearnedInfos(List<TodayILearnedInfo> todayILearnedInfos) { | ||
return TodayILearnedInfos.builder() | ||
.todayILearnedInfos(todayILearnedInfos) | ||
.build(); | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...om/umc/networkingService/domain/todayILearned/repository/TodayILearnedFileRepository.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,8 @@ | ||
package com.umc.networkingService.domain.todayILearned.repository; | ||
|
||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearnedFile; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TodayILearnedFileRepository extends JpaRepository<TodayILearnedFile, UUID> { | ||
} |
18 changes: 18 additions & 0 deletions
18
...va/com/umc/networkingService/domain/todayILearned/repository/TodayILearnedRepository.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,18 @@ | ||
package com.umc.networkingService.domain.todayILearned.repository; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearned; | ||
import io.lettuce.core.dynamic.annotation.Param; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface TodayILearnedRepository extends JpaRepository<TodayILearned, UUID> { | ||
|
||
@Query(value = "SELECT t FROM TodayILearned t WHERE (t.writer = :writer AND DATE(t.createdAt) = :date)") | ||
List<TodayILearned> findTodayILearnedByWriterAndCreateDate(@Param("writer") Member writer, | ||
@Param("date") LocalDate date); | ||
} |
9 changes: 9 additions & 0 deletions
9
...java/com/umc/networkingService/domain/todayILearned/service/TodayILearnedFileService.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,9 @@ | ||
package com.umc.networkingService.domain.todayILearned.service; | ||
|
||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearned; | ||
import java.util.List; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public interface TodayILearnedFileService { | ||
void uploadTodayILearnedFiles(TodayILearned todayILearned, List<MultipartFile> files); | ||
} |
33 changes: 33 additions & 0 deletions
33
.../com/umc/networkingService/domain/todayILearned/service/TodayILearnedFileServiceImpl.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,33 @@ | ||
package com.umc.networkingService.domain.todayILearned.service; | ||
|
||
import com.umc.networkingService.domain.todayILearned.entity.TodayILearned; | ||
import com.umc.networkingService.domain.todayILearned.mapper.TodayILearnedFileMapper; | ||
import com.umc.networkingService.domain.todayILearned.repository.TodayILearnedFileRepository; | ||
import com.umc.networkingService.domain.todayILearned.repository.TodayILearnedRepository; | ||
import com.umc.networkingService.global.utils.S3FileComponent; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class TodayILearnedFileServiceImpl implements TodayILearnedFileService { | ||
|
||
private final TodayILearnedFileRepository todayILearnedFileRepository; | ||
private final TodayILearnedFileMapper todayILearnedFileMapper; | ||
private final S3FileComponent s3FileComponent; | ||
|
||
// TodayILearned 파일 업로드 | ||
@Override | ||
@Transactional | ||
public void uploadTodayILearnedFiles(TodayILearned todayILearned, List<MultipartFile> files) { | ||
files.forEach(file -> { | ||
todayILearnedFileRepository.save(todayILearnedFileMapper.toTodayILearnedFile(todayILearned, | ||
s3FileComponent.uploadFile("TodayILearned", file))); | ||
}); | ||
|
||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ain/java/com/umc/networkingService/domain/todayILearned/service/TodayILearnedService.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,20 @@ | ||
package com.umc.networkingService.domain.todayILearned.service; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedCreate; | ||
import com.umc.networkingService.domain.todayILearned.dto.requeest.TodayILearnedRequest.TodayILearnedUpdate; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedId; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfo; | ||
import com.umc.networkingService.domain.todayILearned.dto.response.TodayILearnedResponse.TodayILearnedInfos; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public interface TodayILearnedService { | ||
TodayILearnedId createTodayILearned(Member member, List<MultipartFile> files, TodayILearnedCreate request); | ||
TodayILearnedInfos getTodayILearnedInfos(Member member); | ||
|
||
TodayILearnedId updateTodayILearned(Member member, UUID todayILearnedId, List<MultipartFile> files, TodayILearnedUpdate request); | ||
|
||
TodayILearnedId deleteTodayILearned(Member member, UUID todayILearnedId); | ||
} |
Oops, something went wrong.