-
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.
- Loading branch information
1 parent
cbc7a4e
commit 3c62ae3
Showing
13 changed files
with
365 additions
and
46 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/healthylife/config/S3Config.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,18 @@ | ||
package com.example.healthylife.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
@Configuration | ||
public class S3Config { | ||
@Bean | ||
public S3Client s3Client() { | ||
return S3Client.builder() | ||
.region(Region.AP_NORTHEAST_2) // 여러분의 AWS S3 리전으로 변경 | ||
.credentialsProvider(DefaultCredentialsProvider.create()) | ||
.build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/example/healthylife/controller/HeartController.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,47 @@ | ||
package com.example.healthylife.controller; | ||
|
||
import com.example.healthylife.entity.TodayEntity; | ||
import com.example.healthylife.entity.UserEntity; | ||
import com.example.healthylife.service.HeartService; | ||
import com.example.healthylife.service.TodayService; | ||
import com.example.healthylife.service.UserService; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/hearts") | ||
public class HeartController { | ||
|
||
@Autowired | ||
private HeartService heartService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private TodayService todayService; | ||
|
||
@ApiOperation("하트") | ||
@PostMapping("/heart/{todaySq}") | ||
public void like(@PathVariable("todaySq") long todaySq, @RequestParam String userId) { | ||
Optional<UserEntity> user = userService.findUserById(userId); | ||
Optional<TodayEntity> today = todayService.findbytodaysq(todaySq); | ||
|
||
if (user.isPresent() && today.isPresent()) { | ||
heartService.Like(user.get(), today.get()); | ||
} else { | ||
// Handle the case when user or today entity is not found | ||
throw new RuntimeException("User or Today entity not found"); | ||
} | ||
} | ||
|
||
@ApiOperation("하트 수") | ||
@GetMapping("/count/{todaySq}") | ||
public Long heartCount(@PathVariable("todaySq") long todaySq) { | ||
Optional<TodayEntity> today = todayService.findbytodaysq(todaySq); | ||
return heartService.HeartCount(today.orElse(null)); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/example/healthylife/entity/HeartEntity.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,44 @@ | ||
package com.example.healthylife.entity; | ||
|
||
import lombok.*; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
|
||
@ToString | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Entity | ||
@Table(name = "heart") | ||
public class HeartEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "heart_sq", unique = true, nullable = false) | ||
private Long heartSq; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_sq", nullable = false) | ||
private UserEntity user; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "today_sq", nullable = false) | ||
private TodayEntity today; | ||
|
||
@Column(name = "status", nullable = false) | ||
private Boolean status; | ||
|
||
@Column(name = "created_at", nullable = false) | ||
private LocalDateTime createdAt = LocalDateTime.now(); | ||
|
||
|
||
// 상태를 토글하는 메서드 | ||
public void toggleStatus() { | ||
this.status = !this.status; | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/healthylife/repository/HeartRepository.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,18 @@ | ||
package com.example.healthylife.repository; | ||
|
||
|
||
import com.example.healthylife.entity.HeartEntity; | ||
import com.example.healthylife.entity.TodayEntity; | ||
import com.example.healthylife.entity.UserEntity; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.Optional; | ||
|
||
public interface HeartRepository extends JpaRepository<HeartEntity, Long> { | ||
Optional<HeartEntity> findByUserAndToday(UserEntity user, TodayEntity todayentity); | ||
|
||
@Query("SELECT COUNT(h) FROM HeartEntity h WHERE h.today = :today AND h.status = true") | ||
Long HeartCount(@Param("today") TodayEntity today); | ||
} |
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
Oops, something went wrong.