mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
flag resolving
Signed-off-by: MiniDigger <admin@minidigger.me>
This commit is contained in:
parent
68b1949019
commit
59ddb5eb6e
@ -45,8 +45,8 @@ export default class ProjectFlagsPage extends Vue {
|
||||
];
|
||||
}
|
||||
|
||||
async asyncData({ $api, $util }: Context) {
|
||||
const flags = await $api.requestInternal<Flag[]>(`flags/`, false).catch<any>($util.handlePageRequestError);
|
||||
async asyncData({ $api, $util, params }: Context) {
|
||||
const flags = await $api.requestInternal<Flag[]>(`flags/${params.author}/${params.slug}`, false).catch<any>($util.handlePageRequestError);
|
||||
return { flags };
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,12 @@ export default class AdminFlagsPage extends Vue {
|
||||
}
|
||||
|
||||
resolve(flag: Flag) {
|
||||
console.log('resolve ', flag);
|
||||
this.$api
|
||||
.requestInternal<Flag[]>(`flags/${flag.id}/resolve/true`, false, 'POST')
|
||||
.catch<any>(this.$util.handlePageRequestError)
|
||||
.then(() => {
|
||||
this.flags = this.flags.filter((f) => f.id !== flag.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -30,11 +30,16 @@ public class FlagController extends HangarController {
|
||||
this.flagService = flagService;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void flag(@RequestBody FlagForm form) {
|
||||
flagService.createFlag(form.getProjectId(), getHangarUserId(), form.getReason(), form.getComment());
|
||||
flagService.createFlag(form.getProjectId(), form.getReason(), form.getComment());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/resolve/{resolve}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void resolve(@PathVariable("id") long id, @PathVariable("resolve") boolean resolve) {
|
||||
flagService.markAsResolved(id, resolve);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
|
@ -8,6 +8,7 @@ import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.hangar.model.db.projects.ProjectFlagTable;
|
||||
@ -41,4 +42,9 @@ public interface HangarFlagsDAO {
|
||||
"WHERE NOT pf.resolved " +
|
||||
"GROUP BY pf.id, fu.id, ru.id, p.id")
|
||||
List<HangarProjectFlag> getFlags();
|
||||
|
||||
@SqlUpdate("UPDATE project_flags SET resolved = :resolved, resolved_by = :resolvedBy, resolved_at = :resolvedAt WHERE id = :flagId")
|
||||
@GetGeneratedKeys
|
||||
@RegisterConstructorMapper(ProjectFlagTable.class)
|
||||
ProjectFlagTable markAsResolved(long flagId, boolean resolved, Long resolvedBy, OffsetDateTime resolvedAt);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.papermc.hangar.service.internal.admin;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.hangar.db.dao.HangarDao;
|
||||
@ -20,9 +21,14 @@ public class FlagService extends HangarService {
|
||||
this.flagsDAO = flagsDAO.get();
|
||||
}
|
||||
|
||||
public void createFlag(long projectId, long userId, FlagReason reason, String comment) {
|
||||
public void createFlag(long projectId, FlagReason reason, String comment) {
|
||||
// TODO idk, we prolly need more checking here, plus notification? logs?
|
||||
flagsDAO.insert(new ProjectFlagTable( projectId, userId, reason, comment));
|
||||
flagsDAO.insert(new ProjectFlagTable( projectId, getHangarUserId(), reason, comment));
|
||||
}
|
||||
|
||||
public ProjectFlagTable markAsResolved(long flagId, boolean resolved) {
|
||||
OffsetDateTime resolvedAt = resolved ? OffsetDateTime.now() : null;
|
||||
return flagsDAO.markAsResolved(flagId, resolved, getHangarUserId(), resolvedAt);
|
||||
}
|
||||
|
||||
public List<HangarProjectFlag> getFlags(String author, String slug) {
|
||||
|
Loading…
Reference in New Issue
Block a user