Skip to content

Commit

Permalink
[feat] : 행정구 북마크 저장 api 및 전체 조회 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chahyunsoo committed May 9, 2024
1 parent 0aec2cd commit ced517b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/main/java/seoul/gonggong/domain/data/api/DataApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import seoul.gonggong.domain.data.dto.request.AreaStandardRequest;
import seoul.gonggong.domain.data.dto.response.AreaBoardListResponse;
import seoul.gonggong.domain.data.dto.response.AreaScoreListResponse;
import seoul.gonggong.domain.data.dto.response.DataBoardResponse;
import seoul.gonggong.global.ApiResponse;
import seoul.gonggong.global.utils.SecurityUtil;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/data")
Expand All @@ -32,9 +35,10 @@ public ApiResponse<?> saveBoardOfArea(@PathVariable Long areaId) {
return ApiResponse.onSuccess("성공적으로 저장되었습니다.");
}

// @GetMapping("/areas/boards")
// public ApiResponse<AreaLikeResponse> getAreaLikeList() {
// return ApiResponse.onSuccess(dataService.getLikeAreaList());
// }

@GetMapping("/boards")
public ApiResponse<List<DataBoardResponse>> getAreaLikeList() {
return ApiResponse.onSuccess(dataService.getLikeAreaList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import seoul.gonggong.domain.data.dto.request.AreaStandardRequest;
import seoul.gonggong.domain.data.dto.response.AreaBoardListResponse;
import seoul.gonggong.domain.data.dto.response.AreaScoreListResponse;
import seoul.gonggong.domain.data.dto.response.DataBoardResponse;

import java.util.List;

public interface DataService {
AreaScoreListResponse getAreaListByInputScore(AreaStandardRequest areaStandardRequest);

AreaBoardListResponse getBoardOfArea(Long areaId);

void saveBoardOfArea(Long memberId, Long areaId);

List<DataBoardResponse> getLikeAreaList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ public class DataServiceImpl implements DataService {
private final ScoreUtils scoreUtils;
private final MeanUtils meanUtils;

@Override
public List<DataBoardResponse> getLikeAreaList() {
List<DataBoardResponse> dataBoardResponses = new ArrayList<>();
List<MemberAreaEntity> memberAreaEntityList = memberAreaJpaRepository.findAll();

for (MemberAreaEntity memberArea : memberAreaEntityList) {
Area area = areaJpaRepository.findById(memberArea.getArea().getId())
.orElseThrow(() -> new DataException(AREA_NOT_FOUND));

Map<String, Integer> scoreList = new HashMap<>();

scoreList.put("education", Integer.valueOf(scoreUtils.getTotalEducationScore(area).intValue()));
scoreList.put("life",Integer.valueOf(scoreUtils.getTotalLifeScore(area).intValue()));
scoreList.put("nature",Integer.valueOf(scoreUtils.getTotalNatureScore(area).intValue()));
scoreList.put("residence",Integer.valueOf(scoreUtils.getTotalResidenceScore(area).intValue()));
scoreList.put("security",Integer.valueOf(scoreUtils.getTotalSecurityScore(area).intValue()));
scoreList.put("welfare", Integer.valueOf(scoreUtils.getTotalWelfareScore(area).intValue()));

List<AreaBoardScoreResponse> areaBoardScoreResponses = AreaBoardScoreResponse.of(scoreList);

dataBoardResponses.add(DataBoardResponse.of(area.getRegion().getArea(), areaBoardScoreResponses));
}

return dataBoardResponses;
}

@Override
public AreaScoreListResponse getAreaListByInputScore(AreaStandardRequest areaStandardRequest) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//package seoul.gonggong.domain.data.dto.response;
//
//import java.util.List;
//
//public record AreaLikeResponse(
// List<AreaBoardScoreResponse> areaBoardScoreResponseList
//){
// public static AreaLikeResponse of(List<AreaBoardScoreResponse> areaBoardScoreResponses) {
//
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package seoul.gonggong.domain.data.dto.response;

import java.util.List;

public record DataBoardResponse(
String area,
List<AreaBoardScoreResponse> areaBoardScoreResponseList
) {
public static DataBoardResponse of(String area, List<AreaBoardScoreResponse> areaBoardScoreResponseList) {
return new DataBoardResponse(area, areaBoardScoreResponseList);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seoul.gonggong.domain.member.application;

import seoul.gonggong.domain.agent.domain.AgentEntity;
import seoul.gonggong.domain.member.domain.Authority;
import seoul.gonggong.domain.member.domain.MemberEntity;
import seoul.gonggong.domain.member.domain.Role;
Expand Down Expand Up @@ -33,4 +34,13 @@ public static MemberEntity memberRequestToMemberEntity(Long id, String email,Str
Authority.ROLE_USER
);
}

public static AgentEntity memberRequestToAgentEntity(Long id, String email,String nickname, String password) {
return AgentEntity.of(id,
email,
nickname,
password,
Authority.ROLE_AGENT
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seoul.gonggong.domain.member.dto.request;

import seoul.gonggong.domain.agent.domain.AgentEntity;
import seoul.gonggong.domain.member.application.MemberMapper;
import seoul.gonggong.domain.member.domain.MemberEntity;

Expand All @@ -13,4 +14,10 @@ public static MemberEntity toEntity(MemberRequest memberRequest, Long id, String
id, email, memberRequest.username, memberRequest.password()
);
}

public static AgentEntity toAgentEntity(MemberRequest memberRequest, Long id, String email) {
return MemberMapper.memberRequestToAgentEntity(
id, email, memberRequest.username, memberRequest.password()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
public record MemberResponse(
Long id,
String email,
String nickname
String username
) {
public static MemberResponse of(Long id,String email,String nickname) {
return new MemberResponse(id, email,nickname);
public static MemberResponse of(Long id,String email,String username) {
return new MemberResponse(id, email,username);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ErrorStatus implements BaseErrorCode {
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER_001", "사용자를 찾을 수 없습니다."),
MEMBER_IS_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "MEMBER_002", "동일한 이메일을 가지고 있는 사용자가 존재합니다."),
PASSWORD_IS_INVALID(HttpStatus.BAD_REQUEST,"MEMBER_003","비밀번호가 일치하지 않습니다."),
AGENT_NOT_FOUND(HttpStatus.NOT_FOUND, "AGENT_001", "공인중개사를 찾을 수 없습니다."),
INVALID_REGION(HttpStatus.FORBIDDEN,"ENUM_001","유효하지 않은 Region입니다."),

//JWT 관련 에러
Expand Down

0 comments on commit ced517b

Please sign in to comment.