Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions goorm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies {
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'

implementation 'com.amazonaws:aws-java-sdk-s3:1.12.753'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public class Cloth extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

public void increaseWearCount() {
this.wearNum++;
}

public void decreaseWearCount() {
if (this.wearNum > 0) {
this.wearNum--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import study.goorm.domain.cloth.domain.entity.Cloth;
import study.goorm.domain.member.domain.entity.Member;

import java.util.List;

public interface ClothRepository extends JpaRepository<Cloth, Long> {

// 1. wearNum ์˜ค๋ฆ„์ฐจ์ˆœ
Expand All @@ -19,4 +24,12 @@ public interface ClothRepository extends JpaRepository<Cloth, Long> {

// 4. createdAt ๋‚ด๋ฆผ์ฐจ์ˆœ
Page<Cloth> findByMemberOrderByCreatedAtDesc(Member member, Pageable pageable);

// ํŠน์ • ID ๋ชฉ๋ก์— ํ•ด๋‹นํ•˜๋Š” ์˜ท๋“ค์„ ์กฐํšŒ
List<Cloth> findAllByIdIn(List<Long> ids);

// ์˜ท ์ฐฉ์šฉ ํšŸ์ˆ˜ ์ฆ๊ฐ€ (์ƒ์„ฑ ๋ฐ ์ˆ˜์ • ์‹œ ์‚ฌ์šฉ)
@Modifying
@Query("UPDATE Cloth c SET c.wearNum = c.wearNum + 1 WHERE c.id = :clothId")
void incrementWearNum(@Param("clothId") Long clothId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package study.goorm.domain.history.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import study.goorm.domain.history.application.HistoryService;
import study.goorm.domain.history.dto.HistoryRequestDTO;
import study.goorm.domain.history.dto.HistoryResponseDTO;
import study.goorm.global.common.response.BaseResponse;
import study.goorm.global.error.code.status.SuccessStatus;

@RestController
@RequiredArgsConstructor
@RequestMapping("/histories")
public class HistoryRestController {

private final HistoryService historyService;

@GetMapping("/monthly/")
@Operation(summary = "ํŠน์ • ์›”์˜ ๊ธฐ๋ก์„ ์ „๋ถ€ ์กฐํšŒํ•˜๋Š” API", description = "query string์œผ๋กœ clokeyId, month๋ฅผ ๋„˜๊ฒจ์ฃผ์„ธ์š”.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse( responseCode = "HISTORY_200", description = "OK, ์„ฑ๊ณต์ ์œผ๋กœ ์กฐํšŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
})
@Parameters({
@Parameter(name = "clokey-id", description = "ํด๋กœํ‚ค ์œ ์ €์˜ clokey id, query string ์ž…๋‹ˆ๋‹ค."),
@Parameter(name = "month", description = "YYYY-MM ํ˜•ํƒœ๋กœ ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๋Š” query string ์ž…๋‹ˆ๋‹ค.")
})
public BaseResponse<HistoryResponseDTO.HistoryMonthResult> getMonthlyHistories(
@RequestParam(value = "clokey-id") String clokeyId,
@RequestParam(value = "month") String month
) {

HistoryResponseDTO.HistoryMonthResult result = historyService.getMonthlyHistories(clokeyId,month);

return BaseResponse.onSuccess(SuccessStatus.HISTORY_MONTH, result);
}

@GetMapping("/{historyId}")
@Operation(summary = "ํŠน์ • History์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๋Š” API", description = "Path Variable๋กœ historyId๋ฅผ ๋˜์ ธ์ฃผ์„ธ์š”.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "HISTORY_201", description = "OK, ์„ฑ๊ณต์ ์œผ๋กœ ์กฐํšŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
})
public BaseResponse<HistoryResponseDTO.HistoryDayResult> getDailyHistory(
@Parameter(name = "historyId") Long historyId
) {
HistoryResponseDTO.HistoryDayResult result = historyService.getDailyHistory(historyId);

return BaseResponse.onSuccess(SuccessStatus.HISTORY_DAY, result);
}


@PostMapping(value = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "์ƒˆ๋กœ์šด ๊ธฐ๋ก ์ƒ์„ฑ API", description = "๋ฉ”ํƒ€๋ฐ์ดํ„ฐ(JSON)์™€ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ฐ›์•„ ๊ธฐ๋ก์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "HISTORY_202", description = "OK, ์„ฑ๊ณต์ ์œผ๋กœ ์กฐํšŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
})
public BaseResponse<Long> createHistory(
@RequestPart("metadata") HistoryRequestDTO.HistoryCreateDTO request,
@RequestPart(value = "image", required = false) MultipartFile imageFile,
@RequestHeader(name = "clokey-id") String clokeyId // ์‚ฌ์šฉ์ž ์ธ์ฆ์šฉ
) {
Long historyId = historyService.createHistory(clokeyId, request, imageFile);
return BaseResponse.onSuccess(SuccessStatus.HISTORY_CREATED, historyId);
}

@PatchMapping(value = "/{historyId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "ํŠน์ • History์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜๋Š” API", description = "Path Variable๋กœ historyId๋ฅผ ๋˜์ ธ์ฃผ์„ธ์š”.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "HISTORY_203", description = "OK, ์„ฑ๊ณต์ ์œผ๋กœ ์กฐํšŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
})
public BaseResponse<Void> updateHistory(
@PathVariable(name = "historyId") Long historyId,
@RequestPart("metadata") HistoryRequestDTO.HistoryUpdateDTO request,
@RequestPart(value = "image", required = false) MultipartFile imageFile,
@RequestHeader(name = "clokey-id") String clokeyId
) {
historyService.updateHistory(historyId, clokeyId, request, imageFile);

return BaseResponse.onSuccess(SuccessStatus.CLOTH_DELETED, null);
}

@DeleteMapping("/{historyId}")
@Operation(summary = "ํŠน์ • History ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜๋Š” API", description = "Path Variable๋กœ historyId๋ฅผ ๋˜์ ธ์ฃผ์„ธ์š”. " +
"๊ด€๋ จ๋œ ๋Œ“๊ธ€, ์˜ท ์ฐฉ์šฉ ํšŸ์ˆ˜, ํ•ด์‹œํƒœ๊ทธ ๊ธฐ๋ก, ์‚ฌ์ง„, ์ข‹์•„์š”, ๊ธฐ๋ก-์˜ท ์—ฐ๊ฒฐ์ด ๋ชจ๋‘ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "204", description = "NO_CONTENT, ์„ฑ๊ณต์ ์œผ๋กœ ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
})
public BaseResponse<Void> deleteHistory(
@PathVariable Long historyId,
@RequestHeader(name = "clokey-id") String clokeyId
) {
historyService.deleteHistory(historyId, clokeyId);

return BaseResponse.onSuccess(SuccessStatus.CLOTH_DELETED, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package study.goorm.domain.history.application;

import org.springframework.web.multipart.MultipartFile;
import study.goorm.domain.history.dto.HistoryRequestDTO;
import study.goorm.domain.history.dto.HistoryResponseDTO;

public interface HistoryService {

HistoryResponseDTO.HistoryMonthResult getMonthlyHistories(String clokeyId, String month);

HistoryResponseDTO.HistoryDayResult getDailyHistory(Long historyId);

Long createHistory(String clokeyId, HistoryRequestDTO.HistoryCreateDTO request, MultipartFile imageFile);

void updateHistory(Long historyId, String clokeyId, HistoryRequestDTO.HistoryUpdateDTO request, MultipartFile imageFile);

void deleteHistory(Long historyId, String clokeyId);

}
Loading