-
Notifications
You must be signed in to change notification settings - Fork 7
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
7ef61a6
commit 746a185
Showing
8 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/aiassistant/controller/AttachmentController.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,28 @@ | ||
package com.aiassistant.controller; | ||
|
||
import com.aiassistant.model.Attachment; | ||
import com.aiassistant.service.AttachmentService; | ||
import com.aiassistant.utils.ResultModel; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/attachment") | ||
public class AttachmentController { | ||
private final AttachmentService attachmentService; | ||
|
||
@Autowired | ||
public AttachmentController(AttachmentService attachmentService) { | ||
this.attachmentService = attachmentService; | ||
} | ||
|
||
@PostMapping("/add") | ||
public ResultModel addAttachment(@RequestBody Attachment attachment) { | ||
return attachmentService.addAttachment(attachment); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResultModel getAttachmentById(@PathVariable Integer id) { | ||
return attachmentService.getAttachmentById(id); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/aiassistant/mapper/AttachmentMapper.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,17 @@ | ||
package com.aiassistant.mapper; | ||
|
||
import com.aiassistant.model.Attachment; | ||
import org.apache.ibatis.annotations.Insert; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Options; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
@Mapper | ||
public interface AttachmentMapper { | ||
@Insert("INSERT INTO attachment(name, type, url) VALUES(#{name}, #{type}, #{url})") | ||
@Options(useGeneratedKeys = true, keyProperty = "id") | ||
void insertAttachment(Attachment attachment); | ||
|
||
@Select("SELECT * FROM attachment WHERE id = #{id}") | ||
Attachment selectById(Integer id); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.aiassistant.model; | ||
|
||
public class Attachment { | ||
private String name; | ||
private String type; | ||
private String url; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/aiassistant/service/AttachmentService.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,10 @@ | ||
package com.aiassistant.service; | ||
|
||
import com.aiassistant.model.Attachment; | ||
import com.aiassistant.utils.ResultModel; | ||
|
||
public interface AttachmentService { | ||
ResultModel<Attachment> addAttachment(Attachment attachment); | ||
|
||
ResultModel<Attachment> getAttachmentById(Integer id); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/aiassistant/service/impl/AttachmentServiceImpl.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,35 @@ | ||
package com.aiassistant.service.impl; | ||
|
||
import com.aiassistant.mapper.AttachmentMapper; | ||
import com.aiassistant.model.Attachment; | ||
import com.aiassistant.service.AttachmentService; | ||
import com.aiassistant.utils.ResultModel; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AttachmentServiceImpl implements AttachmentService { | ||
|
||
private final AttachmentMapper attachmentMapper; | ||
|
||
@Autowired | ||
public AttachmentServiceImpl(AttachmentMapper attachmentMapper) { | ||
this.attachmentMapper = attachmentMapper; | ||
} | ||
|
||
@Override | ||
public ResultModel<Attachment> addAttachment(Attachment attachment) { | ||
attachmentMapper.insertAttachment(attachment); | ||
return new ResultModel<>(attachment); | ||
} | ||
|
||
@Override | ||
public ResultModel<Attachment> getAttachmentById(Integer id) { | ||
Attachment attachment = attachmentMapper.selectById(id); | ||
if (attachment != null) { | ||
return new ResultModel<>(attachment); | ||
} else { | ||
return new ResultModel<>(ResultModel.FAIL, "Attachment not found"); | ||
} | ||
} | ||
} |