-
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.
Browse files
Browse the repository at this point in the history
[FEAT] #4 - 유저 찌르기 조회 API 구현
- Loading branch information
Showing
8 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Server/src/main/java/sopt/sopkathon13/Server/controller/UserController.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,23 @@ | ||
package sopt.sopkathon13.Server.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
import sopt.sopkathon13.Server.common.dto.ApiResponse; | ||
import sopt.sopkathon13.Server.controller.dto.response.TodayComplainResponseDto; | ||
import sopt.sopkathon13.Server.exception.Success; | ||
import sopt.sopkathon13.Server.service.UserService; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/user") | ||
@RestController | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@GetMapping("/{fromHomeNumber}/complain") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<TodayComplainResponseDto> readTodayComplain(@PathVariable("fromHomeNumber") int fromHomeNumber){ | ||
return ApiResponse.success(Success.COMPLAIN_FIND_SUCCESS, userService.findTodayComplain(fromHomeNumber)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...c/main/java/sopt/sopkathon13/Server/controller/dto/response/TodayComplainResponseDto.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,25 @@ | ||
package sopt.sopkathon13.Server.controller.dto.response; | ||
|
||
import lombok.*; | ||
|
||
import javax.validation.constraints.Size; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class TodayComplainResponseDto { | ||
@Size(max = 2) | ||
private List<Long> up; | ||
|
||
@Size(max = 2) | ||
private List<Long> right; | ||
|
||
@Size(max = 2) | ||
private List<Long> left; | ||
|
||
@Size(max = 2) | ||
private List<Long> down; | ||
private Long receiveCount; | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
Server/src/main/java/sopt/sopkathon13/Server/service/UserService.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,55 @@ | ||
package sopt.sopkathon13.Server.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.sopkathon13.Server.controller.dto.response.TodayComplainResponseDto; | ||
import sopt.sopkathon13.Server.domain.Complain; | ||
import sopt.sopkathon13.Server.domain.User; | ||
import sopt.sopkathon13.Server.infrastructure.ComplainRepository; | ||
import sopt.sopkathon13.Server.infrastructure.UserRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
private final ComplainRepository complainRepository; | ||
|
||
@Transactional | ||
public TodayComplainResponseDto findTodayComplain(int fromHomeNumber){ | ||
User upUser = userRepository.findByHomeNumber(fromHomeNumber + 100); | ||
User rightUser = userRepository.findByHomeNumber(fromHomeNumber + 1); | ||
User downUser = userRepository.findByHomeNumber(fromHomeNumber - 100); | ||
User leftUser = userRepository.findByHomeNumber(fromHomeNumber - 1); | ||
|
||
List<Long> up = new ArrayList<>(); | ||
up.add((long)(fromHomeNumber + 100)); | ||
up.add(upUser.getTodayGetComplain()); | ||
|
||
List<Long> right = new ArrayList<>(); | ||
right.add((long)(fromHomeNumber + 1)); | ||
right.add(rightUser.getTodayGetComplain()); | ||
|
||
List<Long> down = new ArrayList<>(); | ||
down.add((long)(fromHomeNumber - 100)); | ||
down.add(downUser.getTodayGetComplain()); | ||
|
||
List<Long> left = new ArrayList<>(); | ||
left.add((long)(fromHomeNumber - 1)); | ||
left.add(leftUser.getTodayGetComplain()); | ||
|
||
User fromUser = userRepository.findByHomeNumber(fromHomeNumber); | ||
|
||
return TodayComplainResponseDto.builder() | ||
.up(up) | ||
.right(right) | ||
.down(down) | ||
.left(left) | ||
.receiveCount(fromUser.getTodayGetComplain()) | ||
.build(); | ||
} | ||
} |