Skip to content

Commit

Permalink
Merge pull request #77 from Alpha-Damyo/develop
Browse files Browse the repository at this point in the history
Main merge
  • Loading branch information
wjdwlghks authored Jun 5, 2024
2 parents 0f483c7 + 31388ff commit 04421d9
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ public class AuthController {
})
public ResponseEntity<TokenResponse> signUp(
@Parameter(description = "프로필 사진", in = ParameterIn.DEFAULT)
@RequestPart(value = "image") MultipartFile image,
@Parameter(description = "회원가입 요청사항", in = ParameterIn.DEFAULT)
@RequestPart(value = "image", required = false) MultipartFile image,
@Parameter(description = "회원가입 요청사항", in = ParameterIn.DEFAULT, required = true)
@RequestPart SignUpRequest signUpRequest) {
String profileUrl = s3ImageService.upload(image);
authService.signUp(signUpRequest, profileUrl);

if(image != null) {
String profileUrl = s3ImageService.upload(image);
authService.signUp(signUpRequest, profileUrl);
}
else {
authService.signUp(signUpRequest, null);
}

User user = authService.login(signUpRequest);
String token = authService.generateToken(user);
return ResponseEntity.ok().body(new TokenResponse(token));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ public class ContestController {
private final PictureService pictureService;
private final ContestService contestService;

// TODO 페이지네이션에 좋아요 여부 적용
@GetMapping("/page")
@Operation(summary="사진 콘테스트의 사진 반환", description = "페이지네이션을 적용한 사진 URL 리스트가 반환됩니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "사진 URL 리스트 반환에 성공하였습니다.", content = @Content(mediaType = "application/json")),
})
public ResponseEntity<PictureSliceResponse> getPageContestPicture(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@Parameter(description = "페이지네이션 위치를 위한 커서", in = ParameterIn.DEFAULT, required = true)
@RequestParam Long cursorId,
@Parameter(description = "정렬 기준", in = ParameterIn.DEFAULT)
@RequestParam(required = false) String sortBy,
@Parameter(description = "검색 지역", in = ParameterIn.DEFAULT)
@RequestParam(required = false) String region) {
PictureSliceResponse contestResponse = pictureService.getPageContestPicture(cursorId, sortBy, region);
UUID userId = userDetails.getId();
PictureSliceResponse contestResponse = pictureService.getPageContestPicture(cursorId, sortBy, region, userId);
return ResponseEntity
.ok(contestResponse);
}
Expand Down Expand Up @@ -76,4 +77,18 @@ public ResponseEntity<?> unlikeContestPicture(@AuthenticationPrincipal UserDetai
return ResponseEntity
.ok(200);
}
}

//TODO 챌린지 랭킹 기능
@PutMapping("/ranking")
@Operation()
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "사진 URL 리스트 반환에 성공하였습니다.", content = @Content(mediaType = "application/json")),
})
public ResponseEntity<?> unlikeContestPicture(@AuthenticationPrincipal UserDetailsImpl userDetails) {
UUID userId = userDetails.getId();
pictureService.getContestRanking(userId);

return ResponseEntity
.ok(200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;

import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -22,6 +24,8 @@
@Tag(name = "InfoController")
public class InfoController {
private final InfoService infoService;

//TODO 리뷰 작성시 사진 저장
@PostMapping("/postInfo")
@Operation(summary="리뷰 작성하기", description = "리뷰를 작성한다.")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
public record InfoResponse(
Integer size,
Float score,
Integer opened,
Integer closed,
Integer notExist,
Integer airOut,
Integer hygiene,
Integer dirty,
Integer indoor,
Integer outdoor,
Integer big,
Integer small,
Integer crowded,
Integer quite,
Integer chair
Long opened,
Long closed,
Long notExist,
Long airOut,
Long hygiene,
Long dirty,
Long indoor,
Long outdoor,
Long big,
Long small,
Long crowded,
Long quite,
Long chair
) {
}
26 changes: 13 additions & 13 deletions src/main/java/com/damyo/alpha/api/info/service/InfoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public void updateInfo(UpdateInfoRequest updateInfoRequest, UserDetailsImpl deta
public InfoResponse getInfo(String smokingAreaId) {
List<Info> infos = infoRepository.findInfosBySmokingAreaId(smokingAreaId);
Float scoreSum = 0F;
Integer openedSum = 0;
Integer closedSum = 0;
Integer notExistSum = 0;
Integer airOutSum = 0;
Integer hygieneSum = 0;
Integer dirtySum = 0;
Integer indoorSum = 0;
Integer outdoorSum = 0;
Integer bigSum = 0;
Integer smallSum = 0;
Integer crowdedSum = 0;
Integer quiteSum = 0;
Integer chairSum = 0;
Long openedSum = 0L;
Long closedSum = 0L;
Long notExistSum = 0L;
Long airOutSum = 0L;
Long hygieneSum = 0L;
Long dirtySum = 0L;
Long indoorSum = 0L;
Long outdoorSum = 0L;
Long bigSum = 0L;
Long smallSum = 0L;
Long crowdedSum = 0L;
Long quiteSum = 0L;
Long chairSum = 0L;
for (Info info : infos){
scoreSum += info.getScore();
openedSum += info.getOpened()? 1 : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.damyo.alpha.api.picture.controller.dto.PictureSliceResponse;

import java.util.List;
import java.util.UUID;

public interface PictureCustomRepository {
PictureSliceResponse getPictureListByPaging(Long cursorId, Long pageSize, String sortBy, String region);
PictureSliceResponse getPictureListByPaging(Long cursorId, Long pageSize, String sortBy, String region, UUID userId);
List<Picture> findPicturesBySmokingArea_Id(String areaId, Long count);
Long getLikeCountById(Long id);

void getTopRanking();
void getNearRanking(UUID userID);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.damyo.alpha.api.picture.domain;

import com.damyo.alpha.api.contest.domain.QContestLike;
import com.damyo.alpha.api.picture.controller.dto.PictureResponse;
import com.damyo.alpha.api.picture.controller.dto.PictureSliceResponse;
import com.damyo.alpha.api.smokingarea.domain.QSmokingArea;
Expand All @@ -13,15 +14,17 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RequiredArgsConstructor
public class PictureRepositoryImpl implements PictureCustomRepository {
private final JPAQueryFactory jpaQueryFactory;
private QPicture picture = QPicture.picture;
private QSmokingArea smokingArea = QSmokingArea.smokingArea;
private QContestLike contestLike = QContestLike.contestLike;

@Override
public PictureSliceResponse getPictureListByPaging(Long cursorId, Long pageSize, String sortBy, String region) {
public PictureSliceResponse getPictureListByPaging(Long cursorId, Long pageSize, String sortBy, String region, UUID userId) {
OrderSpecifier[] orderSpecifiers = createOrderSpecifier(sortBy);

List<PictureResponse> pictureList = jpaQueryFactory
Expand All @@ -32,10 +35,14 @@ public PictureSliceResponse getPictureListByPaging(Long cursorId, Long pageSize,
)
.from(picture)
.innerJoin(picture.smokingArea, smokingArea)
.leftJoin(contestLike)
.on(picture.id.eq(contestLike.pictureId),
contestLike.userId.eq(userId))
.where(cursorId(cursorId),
regionEq(region))
.orderBy(orderSpecifiers)
.limit(pageSize + 1)
.distinct()
.fetch();

boolean hasNext = false;
Expand Down Expand Up @@ -78,6 +85,22 @@ public Long getLikeCountById(Long id) {
return count;
}

@Override
public void getTopRanking() {
jpaQueryFactory
.select(picture.user.id, picture.likes.sum())
.from(picture)
.fetch();
}

@Override
public void getNearRanking(UUID userId) {
jpaQueryFactory
.select(picture.user.id, picture.likes.sum())
.from(picture)
.fetch();
}

private BooleanExpression cursorId(Long cursorId) {
return cursorId == null ? null : picture.id.gt(cursorId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ public void uploadPicture(UUID userId, String areaId, String url) {
build());
}

public PictureSliceResponse getPageContestPicture(Long cursorId, String sortBy, String region) {
public PictureSliceResponse getPageContestPicture(Long cursorId, String sortBy, String region, UUID userId) {
Long pageSize = 24L;
if(cursorId == 0) cursorId = null;
PictureSliceResponse pictureSliceResponse = pictureRepository.getPictureListByPaging(cursorId, pageSize, sortBy, region);
PictureSliceResponse pictureSliceResponse = pictureRepository.getPictureListByPaging(cursorId, pageSize, sortBy, region, userId);

return pictureSliceResponse;
}

public void getContestRanking(UUID userId) {
pictureRepository.getTopRanking();
pictureRepository.getNearRanking(userId);
}

@Transactional
public void increaseLikeCount(Long pictureId) {
HashOperations<String, String, Object> hashOperations = countTemplate.opsForHash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.damyo.alpha.api.auth.domain.UserDetailsImpl;
import com.damyo.alpha.api.info.controller.dto.InfoResponse;
import com.damyo.alpha.api.info.service.InfoService;
import com.damyo.alpha.api.picture.controller.dto.PictureResponse;
import com.damyo.alpha.api.picture.service.PictureService;
import com.damyo.alpha.api.smokingarea.controller.dto.*;
import com.damyo.alpha.api.smokingarea.domain.SmokingArea;
Expand All @@ -26,6 +27,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
Expand Down Expand Up @@ -80,23 +82,27 @@ public ResponseEntity<SmokingAreaDetailResponse> postSmokingArea(
.ok(area.toDTO());
}

// 아이디로 구역정보 불러오기
// TODO 상세정보 -> 태그 총합 반환
// TODO 사진 URL 전송
@GetMapping("/details/{smokingAreaId}")
@Operation(summary="흡연구역 상세정보", description = "흡연구역 ID의 상세정보를 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "흡연구역 정보 반환에 성공하였습니다.", content = @Content(mediaType = "application/json")),
})
public ResponseEntity<SmokingAreaDetailResponse> getSmokingAreaDetailsById(
public ResponseEntity<SmokingAreaAllResponse> getSmokingAreaDetailsById(
@Parameter(description = "흡연구역 ID", in = ParameterIn.PATH)
@PathVariable String smokingAreaId){
SmokingArea areaResponse = smokingAreaService.findAreaById(smokingAreaId);
InfoResponse infoResponse = infoService.getInfo(smokingAreaId);
return ResponseEntity.ok(areaResponse.toDTO());
SmokingAreaDetailResponse area = smokingAreaService.findAreaById(smokingAreaId).toDTO();
InfoResponse info = infoService.getInfo(smokingAreaId);
List<PictureResponse> picList = pictureService.getPicturesBySmokingArea(smokingAreaId, 10L);

SmokingAreaAllResponse response = new SmokingAreaAllResponse(area.areaId(), area.name(), area.latitude(), area.longitude(), area.address(),
area.createdAt(), area.description(), area.score(), area.status(), Map.of(area.opened(), info.opened()), Map.of(area.closed(), info.closed()),
Map.of(area.hygiene(), info.hygiene()), Map.of(area.dirty(), info.dirty()), Map.of(area.airOut(), info.airOut()), Map.of(area.noExist(), info.notExist()),
Map.of(area.indoor(), info.indoor()), Map.of(area.outdoor(), info.outdoor()), Map.of(area.big(), info.big()), Map.of(area.small(), info.small()),
Map.of(area.crowded(), info.crowded()), Map.of(area.quite(), info.quite()), Map.of(area.chair(), info.chair()), picList);

return ResponseEntity.ok(response);
}

//TODO 사진 URL 전송
@GetMapping("/summary/{smokingAreaId}")
@Operation(summary="흡연구역 요약정보", description = "흡연구역 ID의 요약정보를 반환합니다.")
@ApiResponses(value = {
Expand All @@ -106,6 +112,7 @@ public ResponseEntity<SmokingAreaSummaryResponse> getSmokingAreaSummaryById(
@Parameter(description = "흡연구역 ID", in = ParameterIn.PATH)
@PathVariable String smokingAreaId){
SmokingArea areaResponse = smokingAreaService.findAreaById(smokingAreaId);

return ResponseEntity.ok(areaResponse.toSUM());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.damyo.alpha.api.smokingarea.controller.dto;

import com.damyo.alpha.api.picture.controller.dto.PictureResponse;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public record SmokingAreaAllResponse(
String areaId,
String name,
BigDecimal latitude,
BigDecimal longitude,
String address,
LocalDateTime createdAt,
String description,
Float score,
Boolean status,
Map<Boolean, Long> opened,
Map<Boolean, Long> closed,
Map<Boolean, Long> hygiene,
Map<Boolean, Long> dirty,
Map<Boolean, Long> air_out,
Map<Boolean, Long> no_exist,
Map<Boolean, Long> indoor,
Map<Boolean, Long> outdoor,
Map<Boolean, Long> big,
Map<Boolean, Long> small,
Map<Boolean, Long> crowded,
Map<Boolean, Long> quite,
Map<Boolean, Long> chair,
List<PictureResponse> pictureList
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public record SmokingAreaDetailResponse(
Boolean closed,
Boolean hygiene,
Boolean dirty,
Boolean air_out,
Boolean no_exist,
Boolean airOut,
Boolean noExist,
Boolean indoor,
Boolean outdoor,
Boolean big,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private BooleanExpression longitudeBt(BigDecimal min, BigDecimal max) {

private BooleanExpression wordEq(String word) {
if(StringUtils.hasText(word)) {
return smokingArea.name.like(word);
return smokingArea.name.like(word+"%");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public interface SmokingDataRepository extends JpaRepository<SmokingData, Long>

@Query("SELECT sd FROM SmokingData sd " +
"WHERE sd.createdAt >= :startTime " +
"AND sd.createdAt <= :endTime")
"AND sd.createdAt <= :endTime " +
"ORDER BY sd.createdAt")
List<SmokingData> findSmokingDataByCreateAt(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

@Query("SELECT COUNT(DISTINCT sd.user.id) FROM SmokingData sd JOIN sd.user " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private AreaTopResponse getAreaTop(List<Object[]> list) {
public StatisticsDateResponse getStatisticsByDate() {
List<SmokingData> dataList = smokingDataRepository.findSmokingDataByCreateAt(LocalDateTime.now().minusYears(1), LocalDateTime.now());
Integer peopleSum = smokingDataRepository.findUserNumberByCreateAt(LocalDateTime.now().minusYears(1), LocalDateTime.now());
return new StatisticsDateResponse(getHourlyStatistics(dataList, peopleSum), getDailyStatistics(dataList, peopleSum), getWeeklyStatistics(dataList, peopleSum), getMonthlyStatistics(dataList, peopleSum), getDayWeekStatistics(dataList, peopleSum));

List<SmokingData> dataMonthList = smokingDataRepository.findSmokingDataByCreateAt(LocalDateTime.now().minusMonths(1), LocalDateTime.now());
Integer peopleMonth = smokingDataRepository.findUserNumberByCreateAt(LocalDateTime.now().minusMonths(1), LocalDateTime.now());

return new StatisticsDateResponse(getHourlyStatistics(dataList, peopleSum), getDailyStatistics(dataList, peopleSum), getWeeklyStatistics(dataMonthList, peopleMonth), getMonthlyStatistics(dataList, peopleSum), getDayWeekStatistics(dataList, peopleSum));
}

private HourlyStatisticsResponse getHourlyStatistics(List<SmokingData> dataList, Integer peopleSum) {
Expand Down
Loading

0 comments on commit 04421d9

Please sign in to comment.