Skip to content

Commit

Permalink
[feat] : 지역 저장 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chahyunsoo committed May 8, 2024
1 parent deaf7d8 commit 4c0833d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main/java/seoul/gonggong/HealthCheckApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

public class HealthCheckApi {
@GetMapping("/")
public String hello() {
return "Hello!";
public ResponseEntity<HttpStatus> hello() {
return ResponseEntity.ok(HttpStatus.OK);
}

}
16 changes: 15 additions & 1 deletion src/main/java/seoul/gonggong/domain/data/api/DataApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import seoul.gonggong.domain.data.application.DataService;
import seoul.gonggong.domain.data.application.DataServiceImpl;
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.global.ApiResponse;
import seoul.gonggong.global.utils.SecurityUtil;

@RestController
@RequiredArgsConstructor
@RequestMapping("/data")
public class DataApi {
private final DataServiceImpl dataService;
private final DataService dataService;

@PostMapping("/areas")
public ApiResponse<AreaScoreListResponse> getAreaListPriority(@RequestBody AreaStandardRequest areaStandardRequest) {
Expand All @@ -23,4 +25,16 @@ public ApiResponse<AreaScoreListResponse> getAreaListPriority(@RequestBody AreaS
public ApiResponse<AreaBoardListResponse> getBoardOfArea(@PathVariable Long areaId) {
return ApiResponse.onSuccess(dataService.getBoardOfArea(areaId));
}

@PostMapping("/{areaId}/board")
public ApiResponse<?> saveBoardOfArea(@PathVariable Long areaId) {
dataService.saveBoardOfArea(SecurityUtil.getCurrentMemberId(), areaId);
return ApiResponse.onSuccess("성공적으로 저장되었습니다.");
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface DataService {
AreaScoreListResponse getAreaListByInputScore(AreaStandardRequest areaStandardRequest);

AreaBoardListResponse getBoardOfArea(Long areaId);

void saveBoardOfArea(Long memberId, Long areaId);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package seoul.gonggong.domain.data.application;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import seoul.gonggong.domain.data.domain.Area;
import seoul.gonggong.domain.data.domain.Education;
import seoul.gonggong.domain.data.domain.MemberAreaEntity;
import seoul.gonggong.domain.data.dto.request.AreaStandardRequest;
import seoul.gonggong.domain.data.dto.response.*;
import seoul.gonggong.domain.data.repository.*;
import seoul.gonggong.domain.data.utils.CalculateUtils;
import seoul.gonggong.domain.data.utils.MeanUtils;
import seoul.gonggong.domain.data.utils.ScoreUtils;
import seoul.gonggong.domain.exception.DataException;
import seoul.gonggong.domain.member.domain.MemberEntity;
import seoul.gonggong.domain.member.exception.MemberNotFoundException;
import seoul.gonggong.domain.member.repository.MemberJpaRepository;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -21,12 +22,13 @@

@Service
@RequiredArgsConstructor
@Slf4j
@Transactional
public class DataServiceImpl implements DataService {
private final AreaJpaRepository areaJpaRepository;
private final MemberAreaJpaRepository memberAreaJpaRepository;
private final MemberJpaRepository memberJpaRepository;

private final ScoreUtils scoreUtils;
private final CalculateUtils calculateUtils;
private final MeanUtils meanUtils;


Expand Down Expand Up @@ -71,5 +73,16 @@ public AreaBoardListResponse getBoardOfArea(Long areaId) {
);
}

@Override
public void saveBoardOfArea(Long memberId, Long areaId) {
MemberEntity memberEntity = memberJpaRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND));

Area area = areaJpaRepository.findById(areaId)
.orElseThrow(() -> new DataException(DATA_NOT_FOUND));

MemberAreaEntity memberArea = MemberAreaEntity.of(null, memberEntity, area);
memberAreaJpaRepository.save(memberArea);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seoul.gonggong.domain.data.domain;

import jakarta.persistence.*;
import lombok.*;
import seoul.gonggong.domain.member.domain.MemberEntity;

@Entity
@Table(name = "member_area")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class MemberAreaEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private MemberEntity member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "area_id")
private Area area;

public static MemberAreaEntity of(Long id, MemberEntity member, Area area) {
return new MemberAreaEntity(id, member, area);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package seoul.gonggong.domain.data.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import seoul.gonggong.domain.data.domain.MemberAreaEntity;

@Repository
public interface MemberAreaJpaRepository extends JpaRepository<MemberAreaEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ApiResponse<MemberResponse> getMyPage() {
return ApiResponse.onSuccess(memberService.findMemberWithId(SecurityUtil.getCurrentMemberId()));
}

@PatchMapping
@PatchMapping("/my-page")
public ApiResponse<MemberResponse> updateMyPage(@RequestBody MemberRequest memberRequest) {
return ApiResponse.onSuccess(memberService.updateMember(memberRequest, SecurityUtil.getCurrentMemberId()));
}
Expand Down

0 comments on commit 4c0833d

Please sign in to comment.