Skip to content

Commit e04a437

Browse files
authored
Merge pull request #25 from SOPT-all/feat/#20
[feat/#20] 구현완료
2 parents 6dce6dd + 69535af commit e04a437

File tree

14 files changed

+249
-3
lines changed

14 files changed

+249
-3
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.sopkathon.domain.apply.controller;
2+
3+
import java.util.List;
4+
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestParam;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
import com.sopkathon.domain.apply.dto.GetApplyListResponse;
14+
import com.sopkathon.domain.apply.dto.GetApplyResponse;
15+
import com.sopkathon.domain.apply.entity.ApplyEntity;
16+
import com.sopkathon.domain.apply.service.ApplyService;
17+
import com.sopkathon.domain.place.dto.GetPlaceListResponse;
18+
import com.sopkathon.domain.place.dto.GetPlaceResponse;
19+
import com.sopkathon.global.error.code.SuccessCode;
20+
import com.sopkathon.global.error.dto.SuccessResponse;
21+
22+
import lombok.RequiredArgsConstructor;
23+
24+
@RestController
25+
@RequiredArgsConstructor
26+
@RequestMapping("/api/v1/apply")
27+
public class ApplyController {
28+
private final ApplyService applyService;
29+
30+
@PostMapping("/{place-id}")
31+
public ResponseEntity<SuccessResponse<?>> apply(@PathVariable("place-id") Long placeId) {
32+
applyService.addApply(placeId);
33+
return ResponseEntity.ok(SuccessResponse.of(SuccessCode.SUCCESS_CREATE));
34+
}
35+
36+
@GetMapping("/list")
37+
public ResponseEntity<SuccessResponse<?>> getApplies(@RequestParam(defaultValue = "PENDING") String status) {
38+
GetPlaceListResponse getPlaceListResponse = GetPlaceListResponse.of(applyService.getApplyList(status));
39+
40+
return ResponseEntity.ok(SuccessResponse.of(SuccessCode.SUCCESS_FETCH, getPlaceListResponse));
41+
}
42+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.sopkathon.domain.apply.dto;
2+
3+
public record GetApplyListResponse() {
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sopkathon.domain.apply.dto;
2+
3+
public record GetApplyResponse(
4+
Long placeId,
5+
String name,
6+
String description,
7+
int price,
8+
String farmer,
9+
String photoUrl
10+
) {
11+
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.sopkathon.domain.apply.entity;
2+
3+
import com.sopkathon.domain.place.entity.PlaceEntity;
4+
import com.sopkathon.domain.user.UserEntity;
5+
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.EnumType;
8+
import jakarta.persistence.Enumerated;
9+
import jakarta.persistence.FetchType;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.JoinColumn;
13+
import jakarta.persistence.ManyToOne;
14+
import lombok.Builder;
15+
import lombok.Getter;
16+
import lombok.NoArgsConstructor;
17+
18+
@Entity
19+
@Getter
20+
@NoArgsConstructor
21+
public class ApplyEntity {
22+
@Id
23+
@GeneratedValue
24+
private Long id;
25+
26+
@Enumerated(EnumType.STRING)
27+
private ApplyStatus status;
28+
29+
@ManyToOne(fetch = FetchType.LAZY)
30+
@JoinColumn(name = "place_id", nullable = false)
31+
private PlaceEntity place;
32+
33+
@Builder
34+
public ApplyEntity(ApplyStatus status, PlaceEntity place) {
35+
this.status = status;
36+
this.place = place;
37+
}
38+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sopkathon.domain.apply.entity;
2+
3+
import lombok.AccessLevel;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
@Getter
8+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
9+
public enum ApplyStatus {
10+
PENDING,
11+
APPROVED
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.sopkathon.domain.apply.repository;
2+
3+
import java.util.List;
4+
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
import com.sopkathon.domain.apply.entity.ApplyEntity;
9+
import com.sopkathon.domain.apply.entity.ApplyStatus;
10+
11+
@Repository
12+
public interface ApplyRepository extends JpaRepository<ApplyEntity, Long> {
13+
List<ApplyEntity> findByStatus(ApplyStatus applyStatus);
14+
15+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.sopkathon.domain.apply.service;
2+
3+
import java.util.List;
4+
5+
import org.springframework.stereotype.Service;
6+
7+
import com.sopkathon.domain.apply.dto.GetApplyListResponse;
8+
import com.sopkathon.domain.apply.dto.GetApplyResponse;
9+
import com.sopkathon.domain.apply.entity.ApplyEntity;
10+
import com.sopkathon.domain.apply.entity.ApplyStatus;
11+
import com.sopkathon.domain.apply.repository.ApplyRepository;
12+
import com.sopkathon.domain.place.dto.GetPlaceResponse;
13+
import com.sopkathon.domain.place.entity.PlaceEntity;
14+
import com.sopkathon.domain.place.repository.PlaceRepository;
15+
import com.sopkathon.domain.user.UserEntity;
16+
import com.sopkathon.domain.user.UserRepository;
17+
18+
import lombok.RequiredArgsConstructor;
19+
20+
@Service
21+
@RequiredArgsConstructor
22+
public class ApplyService {
23+
24+
private final ApplyRepository applyRepository;
25+
private final PlaceRepository placeRepository;
26+
private final UserRepository userRepository;
27+
28+
// 신청 생성
29+
public void addApply(Long placeId) {
30+
// 임시: 로그인된 유저 ID 하드코딩 (나중에 인증 붙이면 수정)
31+
Long userId = 1L;
32+
33+
PlaceEntity place = placeRepository.findById(placeId)
34+
.orElseThrow(() -> new IllegalArgumentException("장소를 찾을 수 없습니다."));
35+
36+
ApplyEntity apply = ApplyEntity.builder()
37+
.status(ApplyStatus.PENDING)
38+
.place(place)
39+
.build();
40+
41+
applyRepository.save(apply);
42+
}
43+
44+
// 신청 목록 조회
45+
public List<GetPlaceResponse> getApplyList(String status) {
46+
ApplyStatus applyStatus = ApplyStatus.valueOf(status.toUpperCase());
47+
List<ApplyEntity> applies = applyRepository.findByStatus(applyStatus);
48+
49+
return applies.stream()
50+
.map(apply -> {
51+
PlaceEntity place = apply.getPlace();
52+
return GetPlaceResponse.of(place);
53+
})
54+
.toList();
55+
56+
}
57+
}

src/main/java/com/sopkathon/domain/place/controller/PlaceController.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import com.sopkathon.domain.place.dto.GetPlaceDetailRes;
44
import org.springframework.http.ResponseEntity;
55
import org.springframework.web.bind.annotation.*;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestHeader;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
import org.springframework.web.bind.annotation.RestController;
613

714
import com.sopkathon.domain.place.dto.GetPlaceListResponse;
815
import com.sopkathon.domain.place.service.PlaceService;
@@ -19,11 +26,18 @@ public class PlaceController {
1926

2027
@GetMapping
2128
public ResponseEntity<SuccessResponse<?>> getPlaceList(@RequestParam(name = "category", defaultValue = "ALL") String category,
22-
@RequestParam(name = "subway") String subway) {
29+
@RequestParam(name = "subway", defaultValue = "교대역") String subway){
2330
GetPlaceListResponse getPlaceListResponse = placeService.getPlaceList(category, subway);
2431
return ResponseEntity.ok(SuccessResponse.of(SuccessCode.SUCCESS_FETCH, getPlaceListResponse));
2532
}
2633

34+
@PostMapping
35+
public ResponseEntity<SuccessResponse<?>> addPlace(@PathVariable("place-id")Long placeId, @RequestHeader Long userId){
36+
placeService.addPlace(placeId);
37+
return ResponseEntity.ok(SuccessResponse.of(SuccessCode.SUCCESS_CREATE));
38+
}
39+
40+
2741
@GetMapping("/{place-id}")
2842
public ResponseEntity<SuccessResponse<?>> getPlaceDetailById(@PathVariable("place-id") Long placeId) {
2943
GetPlaceDetailRes getPlaceDetailRes = placeService.getPlaceDetailById(placeId);

src/main/java/com/sopkathon/domain/place/dto/GetPlaceResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public record GetPlaceResponse(
1010
Long placeId,
1111
String name,
1212
String description,
13-
String mapLink,
1413
int price,
1514
String farmer,
1615
String photoUrl
@@ -21,7 +20,6 @@ public static GetPlaceResponse of(PlaceEntity placeEntity) {
2120
.placeId(placeEntity.getId())
2221
.name(placeEntity.getName())
2322
.description(placeEntity.getDescription())
24-
.mapLink(placeEntity.getMapLink())
2523
.photoUrl(placeEntity.getPhotoUrl())
2624
.price(placeEntity.getPrice())
2725
.farmer(placeEntity.getFarmer())

src/main/java/com/sopkathon/domain/place/entity/PlaceEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.sopkathon.domain.place.entity;
22

3+
import com.sopkathon.domain.apply.entity.ApplyEntity;
4+
import com.sopkathon.domain.apply.entity.ApplyStatus;
35
import com.sopkathon.domain.review.entity.ReviewEntity;
46
import com.sopkathon.domain.subway.entity.SubwayEntity;
57

0 commit comments

Comments
 (0)