-
Notifications
You must be signed in to change notification settings - Fork 0
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][스팟 생성]
- Loading branch information
Showing
9 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.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,31 @@ | ||
package com.umc.hackaton.snapspot.spot.controller; | ||
|
||
import com.umc.hackaton.snapspot.spot.dto.SpotRequestDto; | ||
import com.umc.hackaton.snapspot.spot.service.SpotService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/spots") | ||
public class SpotController { | ||
|
||
|
||
private final SpotService spotService; | ||
|
||
@PostMapping | ||
public ResponseEntity<?> upload(@RequestBody SpotRequestDto dto){ | ||
try { | ||
spotService.upload(dto); | ||
return ResponseEntity.ok().body("스팟 업로드 성공."); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 업로드에 실패하였습니다."); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotDto.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,31 @@ | ||
package com.umc.hackaton.snapspot.spot.dto; | ||
|
||
import com.umc.hackaton.snapspot.user.entity.User; | ||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class SpotDto { | ||
|
||
private User user; | ||
private Double latitude; | ||
private Double longitude; | ||
private String title; | ||
private String description; | ||
private String imgUrl; | ||
|
||
@Builder | ||
public Spot toEntity() { | ||
return Spot.builder() | ||
.user(user) | ||
.latitude(latitude) | ||
.longitude(longitude) | ||
.title(title) | ||
.description(description) | ||
.imgUrl(imgUrl) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotRequestDto.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,16 @@ | ||
package com.umc.hackaton.snapspot.spot.dto; | ||
|
||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SpotRequestDto { | ||
private Long userId; | ||
private Double latitude; | ||
private Double longitude; | ||
private String title; | ||
private String description; | ||
private String imgUrl; | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotResponseDto.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,4 @@ | ||
package com.umc.hackaton.snapspot.spot.dto; | ||
|
||
public class SpotResponseDto { | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/umc/hackaton/snapspot/spot/entity/Spot.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,49 @@ | ||
package com.umc.hackaton.snapspot.spot.entity; | ||
|
||
import com.umc.hackaton.snapspot.config.entity.BaseEntity; | ||
import com.umc.hackaton.snapspot.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Table(name = "spot") | ||
public class Spot extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
@Column(name = "latitude", nullable = false) | ||
private Double latitude; | ||
|
||
@Column(name = "longitude", nullable = false) | ||
private Double longitude; | ||
|
||
@Column(name = "img_url", nullable = false) | ||
private String imgUrl; | ||
|
||
@Column(name = "like_num") | ||
private Long likeNum = 0L; | ||
|
||
@Column(name = "visit_num") | ||
private Long visitNum =0L; | ||
|
||
@Column(name = "title", nullable = false) | ||
private String title; | ||
|
||
@Column(name = "description", nullable = false, columnDefinition = "TEXT") | ||
private String description; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.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,9 @@ | ||
package com.umc.hackaton.snapspot.spot.repository; | ||
|
||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface SpotRepository extends JpaRepository<Spot, Long> { | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.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,36 @@ | ||
package com.umc.hackaton.snapspot.spot.service; | ||
|
||
import com.umc.hackaton.snapspot.spot.dto.SpotDto; | ||
import com.umc.hackaton.snapspot.spot.dto.SpotRequestDto; | ||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import com.umc.hackaton.snapspot.user.entity.User; | ||
import com.umc.hackaton.snapspot.spot.repository.SpotRepository; | ||
import com.umc.hackaton.snapspot.user.repository.UserRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SpotService { | ||
private final SpotRepository spotRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public void upload(SpotRequestDto dto) { | ||
|
||
User user = userRepository.findUserById(dto.getUserId()); | ||
|
||
SpotDto spotDto = new SpotDto(); | ||
spotDto.setUser(user); | ||
spotDto.setLongitude(dto.getLongitude()); | ||
spotDto.setLatitude(dto.getLatitude()); | ||
spotDto.setTitle(dto.getTitle()); | ||
spotDto.setDescription(dto.getDescription()); | ||
spotDto.setImgUrl(dto.getImgUrl()); | ||
|
||
spotRepository.save(spotDto.toEntity()); | ||
|
||
} | ||
} |
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