-
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
54a1ff1
commit 354a32f
Showing
8 changed files
with
135 additions
and
3 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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/goorm/jejuPowerTest/app/view/controller/ViewController.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,23 @@ | ||
package com.goorm.jejuPowerTest.app.view.controller; | ||
|
||
import com.goorm.jejuPowerTest.app.view.dto.ResponseViewDTO; | ||
import com.goorm.jejuPowerTest.app.view.service.ViewService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class ViewController { | ||
|
||
private final ViewService viewService; | ||
|
||
@PostMapping("/view") | ||
public ResponseEntity<ResponseViewDTO> getView(){ | ||
|
||
return new ResponseEntity<>(viewService.getView(), HttpStatus.OK); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/goorm/jejuPowerTest/app/view/dto/ResponseViewDTO.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,12 @@ | ||
package com.goorm.jejuPowerTest.app.view.dto; | ||
|
||
import lombok.*; | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
public class ResponseViewDTO { | ||
Long view; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/goorm/jejuPowerTest/app/view/entity/View.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,22 @@ | ||
package com.goorm.jejuPowerTest.app.view.entity; | ||
|
||
import com.goorm.jejuPowerTest.app.base.entity.BaseEntity; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@SuperBuilder | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class View extends BaseEntity { | ||
@Column() | ||
Long count; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/goorm/jejuPowerTest/app/view/repository/ViewRepository.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,13 @@ | ||
package com.goorm.jejuPowerTest.app.view.repository; | ||
|
||
import com.goorm.jejuPowerTest.app.place.entity.Place; | ||
import com.goorm.jejuPowerTest.app.view.entity.View; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ViewRepository extends JpaRepository<View, Long> { | ||
@Query("update View v set v.count = v.count + 1 where v.id = :id") | ||
int updateView(@Param("id") Long id); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/goorm/jejuPowerTest/app/view/service/ViewService.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,34 @@ | ||
package com.goorm.jejuPowerTest.app.view.service; | ||
|
||
import com.goorm.jejuPowerTest.app.view.dto.ResponseViewDTO; | ||
import com.goorm.jejuPowerTest.app.view.entity.View; | ||
import com.goorm.jejuPowerTest.app.view.repository.ViewRepository; | ||
import com.goorm.jejuPowerTest.global.mapper.ViewMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ViewService { | ||
|
||
private final ViewRepository viewRepository; | ||
|
||
private final ViewMapper viewMapper; | ||
|
||
@Transactional | ||
public void create(View view){ | ||
viewRepository.save(view); | ||
} | ||
|
||
public ResponseViewDTO getView(){ | ||
View view = viewRepository.findById(1L).get(); | ||
return viewMapper.entityToDto(view); | ||
} | ||
|
||
@Transactional | ||
public void increaseView(){ | ||
viewRepository.updateView(1L); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/goorm/jejuPowerTest/global/mapper/ViewMapper.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.goorm.jejuPowerTest.global.mapper; | ||
|
||
import com.goorm.jejuPowerTest.app.view.dto.ResponseViewDTO; | ||
import com.goorm.jejuPowerTest.app.view.entity.View; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ViewMapper { | ||
public ResponseViewDTO entityToDto(View view){ | ||
return ResponseViewDTO.builder() | ||
.view(view.getCount()) | ||
.build(); | ||
} | ||
} |